Skip to content

Instantly share code, notes, and snippets.

@lukemartin
lukemartin / gist:4251315
Created December 10, 2012 15:40
nginx: Set up a proxy to access ISP-blocked sites
server {
listen 80;
server_name thepiratebay.example.com;
location / {
proxy_pass http://thepiratebay.se/;
}
}
@lukemartin
lukemartin / routes.php
Created June 22, 2012 10:51
Output checkboxes with appropriate 'checked' attributes in Laravel
Route::get('edit', function() {
// fetch our post, and it's associated categories
$post = Post::with('cats')->where('id', '=', $id)->first();
// fetch all of our categories
$cats = Cat::all();
// create our empty array
$post_cats = array();
[user]
name = Name Nameson
email = name@example.com
[core]
editor = /Applications/Sublime\\ Text.app/Contents/SharedSupport/bin/subl -n -w
[push]
default = simple
[alias]
# Get the current branch name (not so useful in itself, but used in
# other aliases)
tell application "Xcode"
activate
tell application "System Events"
perform (keystroke "r" using command down)
end tell
end tell
@lukemartin
lukemartin / nvhgen
Last active December 17, 2015 05:49
Simple shell script to generate an nginx virtual host. http://luke.is/blogging/nginx-virtual-host-generator/
#!/bin/bash
if [ "$#" -le "1" ]; then
echo "Usage: nvhgen [hostname] [location]"
exit 1
fi
NGINXSA="/etc/nginx/sites-available/"
NGINXSE="/etc/nginx/sites-enabled/"
FILENAME="$1"
@lukemartin
lukemartin / parse.js
Created February 7, 2013 11:10
Parse ajax response html (jQuery)
$.ajax({
url: url,
success: function (response) {
var html = $('<div>').html(response).find('.something');
}
});
@lukemartin
lukemartin / kittify bookmarklet
Last active October 13, 2015 22:58
Need cats? Have kittify.
/* Highlight everything below, drag to bookmarks bar */
javascript:(function(b){var a=b.getElementsByTagName("img"),f=a.length,d,c,e;for(d=0;d<f;d++){a[d].src="http://placekitten.com/"+a[d].width+"/"+a[d].height;}})(document);
@lukemartin
lukemartin / gist:4121867
Created November 20, 2012 23:00
AppleScript: Smart Archive for multiple inboxes in Mail.app
tell application "Mail"
set selected_messages to selection
repeat with a_message in selected_messages
set a_message_mailbox to name of mailbox of a_message
if a_message_mailbox is "INBOX" then
tell application "Mail"
move the a_message to mailbox "INBOX/Archive" of account "FastMail"
end tell
else if a_message_mailbox is "anotherinbox" then
@lukemartin
lukemartin / gist:4071683
Created November 14, 2012 11:44
Shell: Unzip all zips in directory with containing folder
#!/bin/bash
for f in *.zip; do
dir=${f%.zip}
unzip -d "./$dir" "./$f"
done
@lukemartin
lukemartin / gist:4058590
Created November 12, 2012 10:41
Copy public key to remote authorized_files
cat ~/.ssh/id_rsa.pub | ssh user@machine "cat >> ~/.ssh/authorized_keys"