Skip to content

Instantly share code, notes, and snippets.

View troyk's full-sized avatar

Troy Kruthoff troyk

View GitHub Profile
@troyk
troyk / whyme.js
Created October 12, 2011 17:32
Get a list of email addresses from your gmail sent folder using node
// Based off an example from node-imap, will output a list of email addresses from your
// gmail sent folder (so you can copy/paste to the BCC field and let people know your
// sorry for using the same password all over the internet resulting in your buddies
// getting a lame spam message)
var ImapConnection = require('imap').ImapConnection,
imap = new ImapConnection({
username: '{{replace}}@gmail.com',
password: '{{replace}}',
host: 'imap.gmail.com',
@troyk
troyk / gist:1408891
Created November 30, 2011 12:23
How to save your ass from bundle install hell
If you ever run across this error again:
uninitialized constant Psych::Syck (NameError)
sudo gem update --system
IS NOT THE FULL ANSWER DUDE. Although it appears to work, worse problems lie ahead. The real cure is downloading/installing libyaml and re-installing ruby. Atleast that solved my hell.
$ wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
$ tar xzvf yaml-0.1.4.tar.gz
@troyk
troyk / contacts.js
Created February 23, 2012 12:38
Mongoose multiple schemas in single collection
// Don't care much about inheritance at this point, but I'll probably attempt it at
// some point via cloning ancestor schema's
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var Contact = new Schema({
_type: String,
name: String
});
@troyk
troyk / sti_associations_demo.rb
Created March 9, 2012 10:51
Neat little STI association trick, works with to_json but finder include needs some love
# Objective: An association using STI should only query the db once for the base class
class Contact < ActiveRecord::Base
has_many :info, :class_name=>'::Contact::ContactInfo'
has_many :phones, :class_name=>'::Contact::Phone'
has_many :emails, :class_name=>'::Contact::Email'
has_many :addresses, :class_name=>'::Contact::Address'
# load all info's thorugh info
# this is possible due to how associations are mixed into the class via a module
@troyk
troyk / dbo.contacts.sql.js
Created March 20, 2012 16:17
plv8 example
CREATE OR REPLACE FUNCTION dbo.contacts(account_id integer, user_id text, sync text) RETURNS text AS $$
if (typeof DBO !== 'function') executeSql('SELECT dbo.init();');
var Contacts = DBO.Contacts || DBO.extend('Contacts',{
stiContact: function stiContact(contact) {
if (contact.type === 'company') {
delete contact.first_name;
delete contact.last_name;
delete contact.title;
@troyk
troyk / dream.sql.js
Created April 3, 2012 19:05
I had a dream; Make an ORM for plv8; got this far; need to pay the bills == use ruby
CREATE OR REPLACE FUNCTION dboBlit(account_id integer, user_id integer) RETURNS void AS $$
Blit = {};
Blit.DBO = (function(){
// load schemas
var schema = {};
plv8.elog(NOTICE, 'loading schema');
plv8.execute("\
SELECT c.relname as table, \
@troyk
troyk / bould_couch.sh
Created May 3, 2012 22:34
Unworking attempt to build couchdb from sources for OS X
# ICU
curl -O http://download.icu-project.org/files/icu4c/49.1.1/icu4c-49_1_1-src.tgz
tar -xzf icu4c-49_1_1-src.tgz
cd ./icu/source
./runConfigureICU MacOSX --with-library-bits=64 --disable-samples --enable-static
make
sudo make install
# SpiderMonkey
curl -O http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
@troyk
troyk / account_migration.rb
Created May 10, 2012 19:44
Postgres is the snizzle
class CreateAccounts < ActiveRecord::Migration
def up
#return unless connection.schema_search_path == 'public'
#-- create a dummy schema so migrations will run
execute "CREATE SCHEMA crm0;"
#-- citext is cool (I think)
execute "CREATE EXTENSION IF NOT EXISTS citext;"
#-- public/shared types
@troyk
troyk / install_plv8.sh
Created June 26, 2012 23:10
PLV8 build/install
git clone git://github.com/v8/v8.git
cd ./v8
git checkout remotes/origin/3.11
make dependencies
make -j 2 library=shared x64.release
# not sure if this is required, also will be .so lib on linux systems
sudo cp ./out/x64.release/libv8.dylib /usr/lib
cd ../
git clone https://code.google.com/p/plv8js/
make && sudo make install
@troyk
troyk / pg_stat_statements
Created January 5, 2013 18:18
enable postgres pg_stat_statements
1) see re: increasing shmmax http://stackoverflow.com/a/10629164/1283020
2) add to postgresql.conf:
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
136 pg_stat_statements.max = 1000
137 pg_stat_statements.track = all
3) restart postgres
4) check it out in psql