Skip to content

Instantly share code, notes, and snippets.

View troyk's full-sized avatar

Troy Kruthoff troyk

View GitHub Profile
@troyk
troyk / roberto_url_controller.rb
Created June 30, 2013 06:08
quick hack at a doman specific url shortner, decided to go a different route but going to gist it incase I want to come back to it
# A Roberto Url is a tiny url. It depends on the cross-language hashids lib http://www.hashids.org/
class RobertoUrlController < ApplicationController
layout false
# cursory glance at the code, this appears to be threadsafe
HASHER = ::Hashids.new("no offense rob, this is a tribute to your carb intake not your manhood") #change the salt and all urls are invalid!
PREFIX = "#{Rails.configuration.base_url}/l"
# note, extremely important that you do not change the keys of the object map as the
# hashing is tied to the sequence key: So add class maps to the end of the list!
# also, because classes can be models, use the string representation of the class
@troyk
troyk / showsValidation.js
Created June 30, 2013 06:02
Attempt to integrate bootstrap form messages with an angularjs directive. Need to move on, will revisit after clearing some fat from my plate!
// DAMN: THIS NO WORK because it watches the model, some how this also needs to tied
// into form submit for the cases where the model value was left blank
// for now, use this: ng-class || ng-show ="{ error: inviteForm.email.$invalid && inviteForm.email.$dirty }"
// Will toggle the css error class on the .control-group container and create/remove
// the error message. Also assumes data is not invalid in a pristine state
// depends on bootstrap form layout and jQuery; TODO: make work without jQuery
angular.module('blitUi', []).directive('showsValidation', function() {
return {
restrict: 'A',
link:function (scope, element, attrs) {
@troyk
troyk / gist:5384041
Created April 14, 2013 20:17
postgres array manipulation
select (select array(select a.e from unnest(matches) as a(e) where a.e != '%CHAN%')) from sms_keywords;
@troyk
troyk / rocknelephant.sql
Created March 7, 2013 13:19
PostgreSQL, don't leave home without it... MongoDB <giggles>, I guess all the smart kids would know to prejoin their data... MySQL <giggles>, at least it could do half of it...
COPY(
SELECT
p.id as "id",
p.payor_email as "email",
to_char(p.created_at,'YYYYMMDD') as "date",
pgroup.gross*0.01::money as "gross",
pgroup.refunded*0.01::money as "refunded",
f.name as "fund",
pgroup.fee*0.01::money as "fee",
(SELECT 'Paid') as "status",
@troyk
troyk / ablionfix
Created January 22, 2013 01:35
Fix apache bench for mt lion
# download and install pcre
# download and unpack (mine was 2.4.3) latest stable apache
cd httpd-2.4.3
export LTFLAGS='--tag CC'
# might have to symlink this file if you get a toolchain error
# sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain
./configure --silent --prefix=/usr/local/ --disable-debug --disable-dependency-tracking
cd support
make -s ab
@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 / 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 / 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 / restart
Created October 2, 2015 22:39
restart script for blit
#!/bin/bash
# sudo stop www-blit.com
# rm /var/www/blit/tmp/puma/*
# sudo start www-blit.com
# TODO: figure out how to restart sidekiq
ps auxf | grep "blit"
blit_puma_pid=$(ps -C ruby -F | grep '/puma.*\[blit\]' | awk {'print $2'})
echo "sending SIGUSR1 to pid $blit_puma_pid"
kill -s SIGUSR1 $blit_puma_pid
@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, \