Skip to content

Instantly share code, notes, and snippets.

View adfinlay's full-sized avatar

Andrew Finlay adfinlay

View GitHub Profile
@adfinlay
adfinlay / install_node_v4.sh
Created March 16, 2016 13:06
Install node.js v4
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
sudo apt-get install -y nodejs
@adfinlay
adfinlay / usbreset.md
Created November 4, 2015 10:42
Reset a USB device from the command line

Save as usbreset.c

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <linux/usbdevice_fs.h>
@adfinlay
adfinlay / git_tree_top.sh
Created October 21, 2015 10:25
Get to the top of a git tree
cdp () {
TEMP_PWD=`pwd`
while ! [ -d .git ]; do
cd ..
done
OLDPWD=$TEMP_PWD
}
@adfinlay
adfinlay / vim_gg.sh
Created October 21, 2015 10:24
Have vim inspect command history
vim () {
last_command=$(history | tail -n 2 | head -n 1)
if [[ $last_command =~ 'git grep' ]] && [[ "$*" =~ :[0-9]+:$ ]]; then
line_number=$(echo $* | awk -F: '{print $(NF-1)}')
/usr/bin/vim +${line_number} ${*%:${line_number}:}
else
/usr/bin/vim $*
fi
}
@adfinlay
adfinlay / jquery.post.js
Created October 1, 2015 10:48
Create and send a POST request with form data
postRequest = function(path, parameters) {
var form = $('<form></form>');
form.attr("method", "post");
form.attr("action", path);
var addField = function(key, value) {
var field = $('<input></input>');
field.attr("type", "hidden");
field.attr("name", key);
@adfinlay
adfinlay / uri.js
Last active August 29, 2015 14:23 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@adfinlay
adfinlay / rotate.js
Created May 28, 2015 14:47
JQuery Rotate
$.fn.rotate = function(revolutions, duration) {
var deg = 360 * revolutions;
this.each(function() {
$(this).css({
'-webkit-transform-style': 'preserve-3d',
'-o-transform-style': 'preserve-3d',
'transform-style': 'preserve-3d',
'-webkit-transition': duration + 's ease-in-out',
'-o-transition': duration + 's ease-in-out',
'transition': duration + 's ease-in-out',
@adfinlay
adfinlay / wombat256mod.vim
Created April 9, 2015 09:30
wombat256mod.vim
" Vim color file
" Original Maintainer: Lars H. Nielsen ([email protected])
" Last Change: 2010-07-23
"
" Modified version of wombat for 256-color terminals by
" David Liang ([email protected])
" based on version by
" Danila Bespalov ([email protected])
set background=dark
@adfinlay
adfinlay / php.vim
Created April 9, 2015 09:29
php.vim
" Vim syntax file
" Language: PHP 4/5
" Maintainer: Peter Hodge <[email protected]>
" Last Change: May 7, 2008
"
" URL: http://www.vim.org/scripts/script.php?script_id=1571
" Version: 0.9.7
"
" ================================================================
"
backend jsonp_varnish {
.host = "localhost";
.port = "80";
}
#------------- begin jsonp functionality -------------#
# How the jsonp_template_backend dispatches to the ESI generating code:
sub jsonp_throw_error_recv {
if (req.url == "/JSONP-ESI-TEMPLATE") {
error 760;