Skip to content

Instantly share code, notes, and snippets.

@albertoperdomo
albertoperdomo / xvfb
Created December 20, 2010 16:08
xvfb init script
DISPLAY=:99
XVFB=/usr/bin/Xvfb
XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16"
PIDFILE=/var/run/xvfb.pid
case "$1" in
start)
echo -n "Starting virtual X frame buffer: Xvfb"
/sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
echo "."
;;
@gnarf
gnarf / jQuery.ajaxQueue.min.js
Created June 21, 2011 23:52
jQuery.ajaxQueue - A queue for ajax requests
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function(a){var b=a({});a.ajaxQueue=function(c){function g(b){d=a.ajax(c).done(e.resolve).fail(e.reject).then(b,b)}var d,e=a.Deferred(),f=e.promise();b.queue(g),f.abort=function(h){if(d)return d.abort(h);var i=b.queue(),j=a.inArray(g,i);j>-1&&i.splice(j,1),e.rejectWith(c.context||c,[f,h,""]);return f};return f}})(jQuery)
@rahearn
rahearn / auto_strip_text_attributes.rb
Created March 20, 2012 19:17
Adding functionality to every model in a system
# This file is in lib
module AutoStripTextAttributes
extend ActiveSupport::Concern
included do
text_columns = columns.collect do |c|
c.name.to_sym if c.type == :string || c.type == :text
end.compact
@gkop
gkop / gist:2340796
Created April 9, 2012 01:58
Regexes to upgrade to new FactoryGirl syntax
# NOTE if you want to do this outside a git repo, find . -type f can by substituted for git grep -l 'Factory'
# fix Factory.create and Factory()
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory(\.create)?\((\:)?(\w+)(, )?/FactoryGirl\.create\($2$3$4/g'
# fix Factory.build
$ git grep -l 'Factory' | xargs perl -pi -e 's/Factory\.build\((\:)?(\w+)(, )?/FactoryGirl\.build\($1$2$3/g'
# fix Factory.define
# NOTE after running this, at the very least you still have to wrap your definitions sets with a FactoryGirl.define do end block,
@iain
iain / gist:2563017
Created April 30, 2012 21:58
global variables in Ruby and the 'english' extension
>> global_variables
=> [:$;, :$-F, :$@, :$!, :$SAFE, :$~, :$&, :$`, :$', :$+, :$=, :$KCODE, :$-K, :$,, :$/, :$-0,
:$\, :$_, :$stdin, :$stdout, :$stderr, :$>, :$<, :$., :$FILENAME, :$-i, :$*, :$?, :$$, :$:,
:$-I, :$LOAD_PATH, :$", :$LOADED_FEATURES, :$VERBOSE, :$-v, :$-w, :$-W, :$DEBUG, :$-d, :$0,
:$PROGRAM_NAME, :$-p, :$-l, :$-a, :$binding, :$1, :$2, :$3, :$4, :$5, :$6, :$7, :$8, :$9]
>> require 'english'
=> true
>> global_variables
@GerHobbelt
GerHobbelt / .gitignore
Created September 9, 2012 08:04
d3.js: using tree layout for graphs which have nodes with multiple 'parents'
# Editor backup files
*.bak
*~
@gkop
gkop / gist:3921201
Created October 19, 2012 23:03
Ruby's "and" and "or" operators explained

|| and && bind with the precedence that you expect from boolean operators in programming languages (&& is very strong, || is slightly less strong).

and and or have lower precedence.

For example, unlike ||, or has lower precedence than =:

> a = false || true
 => true 
> a

=> true

@gdamjan
gdamjan / README.md
Last active June 27, 2024 20:09
Setup for an easy to use, simple reverse http tunnels with nginx and ssh. It's that simple there's no authentication at all. The end result, a single ssh command invocation gives you a public url for your web app hosted on your laptop.

What

A lot of times you are developing a web application on your own laptop or home computer and would like to demo it to the public. Most of those times you are behind a router/firewall and you don't have a public IP address. Instead of configuring routers (often not possible), this solution gives you a public URL that's reverse tunnelled via ssh to your laptop.

Because of the relaxation of the sshd setup, it's best used on a dedicated virtual machine just for this (an Amazon micro instance for example).

Requirements

@bspkrs
bspkrs / pg_change_schema_owner.sh
Last active September 18, 2023 23:26 — forked from mintsoft/change_db_owner.sh
Changes the owner on all tables, sequences, views, and functions in a PostgreSQL database with support for identifiers with whitespace and non-public schemas.
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script sets ownership for all tables, sequences, views, and functions for a given schema.
Run this script as your postgres OS user.
@mmrko
mmrko / git-zsh-checkout-autocomplete-local-only.md
Last active July 20, 2023 08:48
List only local branches when autocompleting git checkout (Zsh)
git config --global alias.checkoutr checkout
$EDITOR /usr/local/share/zsh/site-functions/git-completion.bash

...and then modify the file as follows...

-__gitcomp_nl "$(__git_refs '' $track)"
+if [ "$command" = "checkoutr" ]; then
+    __gitcomp_nl "$(__git_refs '' $track)"
+else