Unix: Using iptables

First create a ipfilters firewall file. Call it ipfilter.firewall.rules for example. Here's an example: http://library.linode.com/securing-your-server#sph_creating-a-firewall
You can then set it as your firewall like so:
iptables-restore < iptables.firewall.rules

Then you can list all the added rules via
iptables -L

unix-iptables unix

Java: List all the files in a directory based on a regex

If you define a regular expression with Pattern, then use the matcher() and matches() methods on that within a File's listFiles() method, you will get back a list of the files in the File's directory based on the regex.

final Pattern p = Pattern.compile(regex);
File[] pagesTemplates = file.listFiles(new FileFilter() {
    public boolean accept(File f) {
       	return p.matcher(f.getName()).matches();

java java-io java-regex

Java: Read a file as a string using Scanner

If you first open a Scanner using a file location wrapped in a FileReader, you can then issue hasNext() and nextLine() to read from that file:
Scanner in = new Scanner(new FileReader("file.txt"));
String s, str="";
while(in.hasNext() && (s=in.nextLine())!=null) str+=s+"\n";

java java-io

Java: Using JGit to clone a repository


remoteRepo will be something like "git@github.com:denevell/BlogPosts.git" and dir is a File object stating where to put the new repository.
If the directory doesn't exist, you must create it with dir.mkdirs();

java jgit

Unix: curl

To use curl to simulate a GET request with custom headers, you use this.
Note a normal header would be "One: Thing". But if you're passing no data, it's "One;"

 curl -k --header "One;" --header "Two;" --header "Three;" https://your.url

unix-curl unix

Page 1 of 3