Skip to content

Instantly share code, notes, and snippets.

View listrophy's full-sized avatar

Brad Grzesiak listrophy

View GitHub Profile
scope :latest_by_hashtag, lambda {|hashtag| {
:where => { :hashtags => hashtag },
:order_by => :tweeted_at.desc,
:limit => 20 }
}
# OR #
module MyModelModules
module Scopes
@listrophy
listrophy / gist:669821
Created November 9, 2010 21:11
brew install -v povray
### Without libpng installed
$ brew install -v povray
==> Build Environment
CC: /usr/bin/cc => /usr/bin/gcc-4.2
CXX: /usr/bin/c++ => /usr/bin/c++-4.2
LD: /usr/bin/cc => /usr/bin/gcc-4.2
CFLAGS: -O3 -w -pipe
CXXFLAGS: -O3 -w -pipe
MAKEFLAGS: -j4
:%s/{/(/g|%s/}/)/g
jr}w./[
r{jj.kF(r[f)r]ZZ
@listrophy
listrophy / gist:1065746
Created July 5, 2011 19:55
Using AES in Ruby
require 'openssl'
require 'base64'
secret_message = 'foo!'
aes = OpenSSL::Cipher.new 'AES-256-CBC'
aes.encrypt
iv = aes.random_iv # never EVER use the same IV if you're reusing a key
rnd = aes.random_key
@listrophy
listrophy / create_join_table_for_domains_and_users.rb
Created October 15, 2011 23:32
simple has_and_belongs_to_many example (from memory...)
class CreateJoinTableForDomainsAndUsers < ActiveRecord::Migration
def change
create_table :domains_users, id: false do |t|
t.integer :user_id
t.integer :domain_id
end
add_index :domains_users, [:user_id, :domain_id]
add_index :domains_users, [:domain_id, :user_id]
end
end
@listrophy
listrophy / foo.js
Created October 17, 2011 22:59
Slug-compilation-time Asset Precompilation
// ...
// source pretty-printed
// some values elided/obscured since I'm not sure which ones are sensitive... though the one's remove are certainly not able to be keyed off of
foo = [
["DATABASE_URL","postgres://user:[email protected]/dbname"],
["SSH_CLIENT","10.194.1.1 12345 12346"],
["USER","xxxxxx"],
["MAIL","/var/mail/xxxxxx"],
["RAILS_GROUPS","assets"],
["SHLVL","1"],
@listrophy
listrophy / ugh.sh
Created March 27, 2012 17:15
simulate instruments' behavior
#!/usr/bin/env bash
if [[ "$1" == "--fail" ]]
then
echo 'Instruments Trace Error'
fi
if [ -t 1 ]
then
echo A
@listrophy
listrophy / roman.rb
Created April 11, 2012 17:00
To/From Roman numerals
class Fixnum
def to_roman
return '' if self == 0
roman, arabic = {
M: 1000,
CM: 900,
D: 500,
CD: 400,
C: 100,
XC: 90,
@listrophy
listrophy / stdout
Created April 25, 2012 17:38
UIATargetHasGoneAWOLException
honor TravisCI(原*) rake test
running: /Users/brad/dev/bwoken/bin/unix_instruments.sh -D /Users/brad/dev/ios/TravisCI/integration/tmp/trace -t /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -v /Users/brad/dev/ios/TravisCI/build/TravisCI.app -e UIASCRIPT /Users/brad/dev/ios/TravisCI/integration/tmp/javascript/iphone/favorites.js -e UIARESULTSPATH /Users/brad/dev/ios/TravisCI/integration/tmp/results
Instruments : Plugin Search Paths (
"/Users/brad/Library/Application Support/Instruments/PlugIns",
"/Library/Application Support/Instruments/PlugIns",
"/Applications/Xcode.app/Contents/Developer/usr/PlugIns",
"/Applications/Xcode.app/Contents/Developer/usr/bin/PlugIns",
"/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns",
"/Applications/Xcode.app/Contents/Developer/Library/Instruments/PlugIns",
@listrophy
listrophy / validate.rb
Created May 17, 2012 22:56
Credit card number validator?
# Do NOT assume this is production code.
class String
def to_is
self.chars.map(&:to_i)
end
end
def luhn cc
cc.