Skip to content

Instantly share code, notes, and snippets.

@lukemartin
lukemartin / .zshrc
Last active June 5, 2024 10:36
Automatically use the correct package manager
detect_and_run() {
if [ -f "bun.lockb" ]; then
bun "$@"
elif [ -f "pnpm-lock.yaml" ]; then
pnpm "$@"
elif [ -f "yarn.lock" ]; then
yarn "$@"
elif [ -f "package-lock.json" ]; then
npm "$@"
else
[user]
name = Name Nameson
email = [email protected]
[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)
@lukemartin
lukemartin / git-tagssorted
Created August 12, 2014 13:24
Git: Sort tags
#!/bin/sh
# put in ~/bin
# make executable
# git tagssorted
git for-each-ref --format="%(taggerdate): %(refname)" --sort=-taggerdate --count=10 refs/tags
@lukemartin
lukemartin / app.coffee
Last active August 29, 2015 14:04
Bluebird Promise Example
Promise = require 'bluebird'
getName = ->
return new Promise((resolve) -> resolve('Luke'))
getAge = (name) ->
data =
'Luke': 27
<snippet>
<content><![CDATA[{
"name": "${1:Project}",
"version": "${2:0.0.1}",
"private": ${3:true},
"dependencies": {
}
}]]></content>
<tabTrigger>bower</tabTrigger>
<scope></scope>
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: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/;
}
}