Skip to content

Instantly share code, notes, and snippets.

@wesbos
wesbos / gist:1476820
Created December 14, 2011 14:36
PhantomJS Screenshot
var page = new WebPage(),
address, output, size;
address = "http://www.metachunk.com/";
width = 1024; height = 600;
output = "./screenshots/wat-"+width+"X"+height+".png";
page.viewportSize = { width: width, height: height };
if (phantom.args.length === 3 && phantom.args[1].substr(-4) === ".pdf") {
@sontek
sontek / snowjob.sh
Last active April 5, 2024 06:51
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear
@myobie
myobie / mountain-lion-brew-setup.markdown
Created February 18, 2012 20:14
Get Mountain Lion and Homebrew to Be Happy

Get Mountain Lion and Homebrew to Be Happy

1) Install XCode 4.4 into /Applications

Get it from the App Store.

2) Install Command Line Tools

In XCode's Preferences > Downloads you can install command line tools.

@klovadis
klovadis / gist:2548942
Created April 29, 2012 09:22
Typical node.js callback pattern
// include the filesystem module
var fs = require('fs');
// fs.readFile: read a file and all its contents,
// then call a callback function
fs.readFile('/some/file', function (err, contents) {
// if any error occurred, throw it
if (err) throw err;
@klovadis
klovadis / gist:2549029
Created April 29, 2012 09:35
Short circuit function chains if an error occurs
var fs = require('fs');
// read a file
function read_the_file(filename, callback) {
// begin by reading a file
fs.readFile(filename, function (err, contents) {
// an error occurred, i.e. the file was not found.
// instead of throwing an error, skip the other
@klovadis
klovadis / gist:2549131
Created April 29, 2012 10:03
How to use optional arguments in node.js
// example function where arguments 2 and 3 are optional
function example( err, optionalA, optionalB, callback ) {
// retrieve arguments as array
var args = [];
for (var i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
// first argument is the error object
@dstroot
dstroot / install_postgresql.sh
Created June 13, 2012 00:26
Install PostgreSQL on Amazon AMI
#!/bin/bash
###############################################
# To use:
# https://raw.github.com/gist/2776351/???
# chmod 777 install_postgresql.sh
# ./install_postgresql.sh
###############################################
echo "*****************************************"
echo " Installing PostgreSQL"
echo "*****************************************"
@mystix
mystix / fix-city-country-stripAlpha-function.sql
Last active December 1, 2019 13:39
Magento - Customer address-related SQL (note: these queries only work on MySQL databases)
DROP FUNCTION IF EXISTS stripAlpha;
-- taken from http://stackoverflow.com/a/5146376
delimiter //
create function stripAlpha(str varchar(50)) returns varchar(50)
no sql
begin
declare verification varchar(50);
declare result varchar(50) default '';
@amejiarosario
amejiarosario / rails_migration_cheatsheet.md
Created June 18, 2012 21:40
Rails Migration - Cheatsheet
@ibeex
ibeex / foo.log
Created August 4, 2012 13:46
Flask logging example
A warning occurred (42 apples)
An error occurred