Skip to content

Instantly share code, notes, and snippets.

ALTER TABLE pgbench_accounts
ADD created_on timestamptz,
DROP CONSTRAINT pgbench_accounts_pkey;
CREATE UNIQUE INDEX ON pgbench_accounts(aid, created_on DESC);
import os, sys
import re
import json
import time
import uuid
import email
import types
import socket
import logging
import datetime
#include <stdio.h>
#include <stdlib.h>
#include "src/uthash.h"
struct my_struct {
int id; /* we'll use this field as the key */
char *name;
UT_hash_handle hh; /* makes this structure hashable */
};
@mohangk
mohangk / emoji.js
Last active August 29, 2015 14:15 — forked from thomasboyt/emoji.js
/** @jsx React.DOM */
define([
'react',
'modernizr',
'punycode'
], function(React, Modernizr, punycode) {
/**
* Replaces the emojis in a text string with <img> tags
@mohangk
mohangk / cdn_performance.js
Last active August 29, 2015 14:01
Use Google analytics to track CDN performance
function dl(url) {
var imageUrl = url + "?n=" + Math.random();
var startTime, endTime;
var download = new Image();
download.onload = function () {
endTime = (new Date()).getTime();
var duration = (endTime - startTime);
console.log(url+" >"+ duration);
_gaq.push(['_trackEvent', 'Speedtest','CDN', url, duration])
#!/bin/bash
set -e
export APP_NAME=$1
export PGHOST=$(< $HOME/predeploy.d/postgres_host)
export PGUSER=admin
if [ -f $HOME/$APP_NAME/DATABASE_URL ]; then
# Database URL is already set - DB must exist
DATABASE_URL=$(cat $HOME/$APP_NAME/DATABASE_URL)
my_chpwd()
{
if [[ -s "$PWD/set_env" ]] ; then
source "$PWD/set_env"
echo '(automatically sourced set_env)'
fi
if Rails.env.production?
PAYPAL_ACCOUNT = '[email protected]'
else
PAYPAL_ACCOUNT = '[email protected]'
ActiveMerchant::Billing::Base.mode = :test
end
class Object
# The hidden singleton lurks behind everyone
def metaclass; class << self; self; end; end
def meta_eval &blk; metaclass.instance_eval &blk; end
# Adds methods to a metaclass
def meta_def name, &blk
meta_eval { define_method name, &blk }
end
@mohangk
mohangk / post-receive
Created June 15, 2012 07:41 — forked from carlosantoniodasilva/post-receive
Basic git post-receive hook file to deploy a Rails app.
#!/bin/bash
APP_NAME="your-app-name-goes-here"
APP_PATH=/home/deploy/${APP_NAME}
# Production environment
export RAILS_ENV="production"
# This loads RVM into a shell session. Uncomment if you're using RVM system wide.
# [[ -s "/usr/local/lib/rvm" ]] && . "/usr/local/lib/rvm"