mirror of
https://github.com/jbranchaud/til
synced 2026-01-17 14:08:01 +00:00
Compare commits
5 Commits
016c1f84f2
...
bdb21c336e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdb21c336e | ||
|
|
fad36e0691 | ||
|
|
4d1d8e7134 | ||
|
|
567637497c | ||
|
|
295fe153ad |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
||||
|
||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||
|
||||
_1466 TILs and counting..._
|
||||
_1469 TILs and counting..._
|
||||
|
||||
---
|
||||
|
||||
@@ -276,6 +276,7 @@ _1466 TILs and counting..._
|
||||
- [Auto-Squash Those Fixup Commits](git/auto-squash-those-fixup-commits.md)
|
||||
- [Caching Credentials](git/caching-credentials.md)
|
||||
- [Change The Start Point Of A Branch](git/change-the-start-point-of-a-branch.md)
|
||||
- [Check How A File Is Being Ignored](git/check-how-a-file-is-being-ignored.md)
|
||||
- [Checking Commit Ancestry](git/checking-commit-ancestry.md)
|
||||
- [Checkout Old Version Of A File](git/checkout-old-version-of-a-file.md)
|
||||
- [Checkout Previous Branch](git/checkout-previous-branch.md)
|
||||
@@ -442,6 +443,7 @@ _1466 TILs and counting..._
|
||||
|
||||
### Java
|
||||
|
||||
- [Ensure Resources Always Get Closed](java/ensure-resources-always-get-closed.md)
|
||||
- [Install Java On Mac With Brew](java/install-java-on-mac-with-brew.md)
|
||||
- [Run A Hello World Program In Eclipse](java/run-a-hello-world-program-in-eclipse.md)
|
||||
|
||||
@@ -1655,6 +1657,7 @@ _1466 TILs and counting..._
|
||||
- [Swap Occurrences Of Two Words](vim/swap-occurrences-of-two-words.md)
|
||||
- [Swapping Split Windows](vim/swapping-split-windows.md)
|
||||
- [Swap The Position Of Two Split Windows](vim/swap-the-position-of-two-split-windows.md)
|
||||
- [Switch Moving End Of Visual Selection](vim/switch-moving-end-of-visual-selection.md)
|
||||
- [Tabs To Spaces](vim/tabs-to-spaces.md)
|
||||
- [The Vim Info File](vim/the-vim-info-file.md)
|
||||
- [Toggle Absolute And Relative Paths In BufExplorer](vim/toggle-absolute-and-relative-paths-in-bufexplorer.md)
|
||||
|
||||
28
git/check-how-a-file-is-being-ignored.md
Normal file
28
git/check-how-a-file-is-being-ignored.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Check How A File Is Being Ignored
|
||||
|
||||
There are a few places on your machine where you can specify the files that git
|
||||
should ignore. The most common is a repository's `.gitignore` file. The other
|
||||
places those excludes are specified can be more obscure. Fortunately, `git
|
||||
check-ignore` is a command that can show you specifically where.
|
||||
|
||||
For instance, let's check why my `notes.md` file is being ignored.
|
||||
|
||||
```bash
|
||||
$ git check-ignore -v .DS_Store
|
||||
.git/info/exclude:7:notes.md notes.md
|
||||
```
|
||||
|
||||
At some point I added it to my repo's `.git/info/exclude` file. The `-v` flag
|
||||
(_verbose_) when included with `check-ignore` tells me the file location.
|
||||
|
||||
How about these pesky `.DS_Store` directories? How are those being ignored?
|
||||
|
||||
```bash
|
||||
git check-ignore .DS_Store -v
|
||||
/Users/jbranchaud/.gitignore:3:.DS_Store .DS_Store
|
||||
```
|
||||
|
||||
Ah yes, I had added it to my _global exclude file_ which I've configured in
|
||||
`~/.gitconfig` to be the `~/.gitignore` file.
|
||||
|
||||
See `man git-check-ignore` for more details.
|
||||
55
java/ensure-resources-always-get-closed.md
Normal file
55
java/ensure-resources-always-get-closed.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# Ensure Resources Always Get Closed
|
||||
|
||||
Java has a construct known as _try-with-resource_ that allows us to always
|
||||
ensure opened resources get closed. This is safer than similar cleanup in the
|
||||
`finally` block which could still leave a memory leak if an error occurs in
|
||||
that block.
|
||||
|
||||
To use the _try-with-resource_ construct, instantiate your opened resource in
|
||||
parentheses with the `try`.
|
||||
|
||||
```java
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
The resource will be automatically closed when the try/catch block completes.
|
||||
|
||||
Here is a full example:
|
||||
|
||||
```java
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FileReaderExample {
|
||||
public static void main(String[] args) {
|
||||
String fileName = "example.txt";
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
|
||||
String line;
|
||||
int lineCount = 0;
|
||||
|
||||
while ((line = reader.readLine()) != null && lineCount < 5) {
|
||||
System.out.println(line);
|
||||
lineCount++;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("An error occurred while reading the file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
You can even specify multiple resources in one `try`. The above does that, but
|
||||
this will make it more obvious:
|
||||
|
||||
```java
|
||||
try (FileReader fr = new FileReader(filename);
|
||||
BufferedReader br = new BufferedReader(fr)) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
[source](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html)
|
||||
@@ -5,6 +5,8 @@ an array-like object with all of the arguments to the function. Even if not
|
||||
all of the arguments are referenced in the function signature, they can
|
||||
still be accessed via the `arguments` object.
|
||||
|
||||
> For ES6+ compatibility, the `spread` operator used via [rest parameters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) is preferred over the `arugments` object when accessing an abritrary number of function arguments.
|
||||
|
||||
```javascript
|
||||
function argTest(one) {
|
||||
console.log(one);
|
||||
|
||||
17
vim/switch-moving-end-of-visual-selection.md
Normal file
17
vim/switch-moving-end-of-visual-selection.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# Switch Moving End Of Visual Selection
|
||||
|
||||
When I go into character-wise visual selection mode, one end of the visual
|
||||
selection is fixed while I move my cursor around to define the other end of it.
|
||||
|
||||
Let's say I've arranged a visual selection that encompasses several lines of my
|
||||
file. And then I realize that the fixed front-end of my visual selection is off
|
||||
by a bit. Maybe I've selected an entire function definition and I just want to
|
||||
inner part of the function.
|
||||
|
||||
Instead of starting over with my visual selection. I can leave the right-end of
|
||||
the visual selection where it is, hit `o` which will switch the moving end to
|
||||
the other side, and then continue making adjustments from there.
|
||||
|
||||
I can always hit `o` again to switch it back to the original side.
|
||||
|
||||
See `:h v_o` for more details.
|
||||
Reference in New Issue
Block a user