Skip to content

Instantly share code, notes, and snippets.

View fairchild's full-sized avatar

Michael Fairchild fairchild

  • Procore
  • California
View GitHub Profile
@vwood
vwood / eav.sql
Created October 2, 2012 00:34
EAV in postgres
-- Entity Attribute Value Model in Postgres
CREATE TABLE public.entity (
id serial NOT NULL,
type varchar(25) NOT NULL,
PRIMARY KEY (id)
);
CREATE TABLE public.defined_attributes (
key varchar(25) NOT NULL,
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active April 19, 2025 04:39
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@max-mapper
max-mapper / cordova-loader.js
Created August 31, 2012 23:33
phonegap conditional script loader
// require this script before your document is done loading
;(function () {
var isDroid = navigator.userAgent.match(/Android/)
var isiOS = navigator.userAgent.match(/(iPhone|iPod|iPad)/)
var droidScripts = [
"script/cordova-android.js",
"script/android-utils.js",
"script/cdv-plugin-childbrowser-android.js",
"script/cdv-plugin-datepicker.js",
@fcurella
fcurella / psql.py
Created August 27, 2012 16:22
postgres PubSub vs Redis
#!/usr/bin/env python
import select
import time
import psycopg2
import psycopg2.extensions
import sys
def get_cursor():
conn = psycopg2.connect("dbname=pgpubsub")
@afair
afair / tmux.cheat
Last active June 3, 2024 23:26
Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!
========================================== ==========================================
TMUX COMMAND WINDOW (TAB)
========================================== ==========================================
List tmux ls List ^b w
New new -s <session> Create ^b c
Attach att -t <session> Rename ^b , <name>
Rename rename-session -t <old> <new> Last ^b l (lower-L)
Kill kill-session -t <session> Close ^b &
@igrigorik
igrigorik / battery.sh
Created August 6, 2012 04:29
OSX power management & information
# system wide assertions on OSX
$> pmset -g assertions
# power state log since boot
$> pmset -g log
# battery stats
$> pmset -g batt
Currently drawing from 'Battery Power'
@foca
foca / how_to_use.md
Created July 7, 2012 02:36
new_rails_app is a script to quickly create pre-configured rails applications out of a template app.

new_rails_app

This script is my way of creating rails apps without much trouble. It works better for me than Rails' templates, so this is what I use.

Basically, it clones a template app and then changes the name of the app.

It's a very simple solution that I've been using for a while now.

Installation

@giosakti
giosakti / es.sh
Created June 29, 2012 07:19
Install ElasticSearch on Ubuntu 12.04
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre -y
wget https://github.com/downloads/elasticsearch/elasticsearch/elasticsearch-0.19.7.tar.gz -O elasticsearch.tar.gz
tar -xf elasticsearch.tar.gz
rm elasticsearch.tar.gz
sudo mv elasticsearch-* elasticsearch
sudo mv elasticsearch /usr/local/share
@kevinpschaaf
kevinpschaaf / github_issues_to_csv_v3.rb
Created June 20, 2012 23:24 — forked from tkarpinski/github_issues_to_csv.rb
Exports Github issues to CSV (API v3)
require 'octokit'
require 'csv'
require 'date'
# Description:
# Exports Github issues from one or more repos into CSV file formatted for import into JIRA
# Note: By default, all Github comments will be assigned to the JIRA admin, appended with
# a note indicating the Github user who added the comment (since you may not have JIRA users
# created for all your Github users, especially if it is a public/open-source project:
#
@alainravet
alainravet / config_initializers_export_migrations_as_ddl.rb
Created June 3, 2012 01:18
have `rake db:migrate` export the matching DDL to a file in db/migrate
if $0.end_with?('/rake') && ARGV[0].start_with?('db:migrate') && Rails.env.development?
#require 'active_record/migration'
klass =
case (adapter_class = ActiveRecord::Base.connection.class.to_s)
when 'ActiveRecord::ConnectionAdapters::SQLite3Adapter'
require 'active_record/connection_adapters/sqlite_adapter'
ActiveRecord::ConnectionAdapters::SQLiteAdapter
when 'ActiveRecord::ConnectionAdapters::Mysql2Adapter'
require 'active_record/connection_adapters/mysql2_adapter'