Skip to content

Instantly share code, notes, and snippets.

@electronicbites
electronicbites / test_state.rb
Created June 15, 2012 15:45
play with state_machine gem
class TestState
include Mongoid::Document
include Mongoid::Timestamps
state_machine :state, initial: :authorized do
event :capture_money do
transition :authorized => :captured
end
def send_events_for_song_change(user, old_song, new_song)
timenow = Time.now.to_i
EventSender.send_user_played_song(user, old_song, timenow)
EventSender.send_user_started_playing_song(user, new_song, timenow)
end
playlist.started_at = Time.now
ORIG_ARTIST = "Jichael Mackson"
Media.where(:artist => ORIG_ARTIST).each(&:destroy)
ActiveRecord::Base.logger = Logger.new(STDOUT)
require 'factory_girl'
begin
FactoryGirl.define do
factory :media do
comment "dummy_foo"
@electronicbites
electronicbites / map_reduce_timespans.js
Created July 4, 2011 15:20
reduce function for couch
{
"_id": "_design/num_ar_id",
"_rev": "36-145879462ded07757a29757bb5b5b92b",
"language": "javascript",
"views": {
"count_of_ar_id": {
"map": "function(doc) {\n if (doc.ar_id) {\n emit(doc.ad_id, doc.ar_id );\n }\n}",
"reduce": "function(keys, values, rereduce) {\n if (rereduce) {\n return sum(values);\n }\n else {\n return values.length;\n }\n}"
},
"count_of_ar_id_impl": {
@electronicbites
electronicbites / dir_scan.rb
Created February 8, 2011 18:46
scan a directory for audio files
def dir_scan(src, files = [])
Dir.foreach(src) do |e|
# Don't bother with . and ..
next if [".",".."].include? e
fullname = src + "/" + e
if FileTest::directory?(fullname)
files = dir_scan(fullname, files)
else
if (e.match("(.)m4a") || e.match("(.)aac") || e.match("(.)mp3"))
@electronicbites
electronicbites / coredata_exception
Created January 6, 2011 13:04
exception when referencing a deleted object
Assertion failed: (_Unwind_SjLj_Resume() can't return), function _Unwind_SjLj_Resume, file /SourceCache/libunwind/libunwind-24.1/src/Unwind-sjlj.c, line 326.
Program received signal: “SIGABRT”.
@electronicbites
electronicbites / gist:662586
Created November 4, 2010 15:03
logKeysOfDict.m
void logKeysOfDictName(NSDictionary *dict, NSString *dictName) {
for (id key in dict) {
NSLog(@">>>> [%@] key - loaded %@", key, dictName);
}
}
consumer_secret = <<END_OF_STRING
-----BEGIN PUBLIC KEY-----
KEY HERE HERE
-----END PUBLIC KEY-----
END_OF_STRING
request_proxy = OAuth::RequestProxy::ActionControllerRequest.new(request)
signature_base_string = request_proxy.signature_base_string
public_key = OpenSSL::PKey::RSA.new(consumer_secret).public_key
logger.error "public_key returned: #{public_key} "
user = User.all[100..120]
root_url = "www.wahwah.fm"
current_user = User.find(150)
jsonstring = "[#{user.collect { |u|
listenerhash = {:listenercount => u.listeners.count}
u.listeners.around_me(point1, point2).each_with_index do |listener, i|
listenerhash.merge!({i => {:name => listener.name}})
end
[Mon, 27 Sep 2010 16:17:39 +0200] DEBUG: Headers in authenticate_every: {:x_ops_authorization_6=>"imC54SWH3uOoFINFX4X6ebe7XSz66cKKZ5/ZmGfKzw==", :x_ops_timestamp=>"2010-09-27T13:25:29Z", :x_ops_authorization_1=>"p+z+A97hGnHHkVbSF+/JZg53mKJL9PXD0Y6IH5wOgOxPekPqppV6U74xNL31", :x_ops_authorization_2=>"ltMeizl/NfQk33hJB8Vvm9sQQpp8dtwCei151eREuUD2p5xVGFiopegAnC2E", :x_ops_content_hash=>"ZtrGElA6L96p3Pf8nQLZsbOPE7s=", :x_ops_authorization_3=>"zVHJSXEMH8OuXxdumq3NIJ3Anh5yCgsICj/NFWJ9SiJr5eQ2A0/gVnA3AS2k", :x_ops_sign=>"version=1.0", :connection=>"close", :version=>"HTTP/1.1", :x_ops_userid=>"chef-validator", :accept=>"application/json", :x_ops_authorization_4=>"LVmp4lXeQLYNOSEPCr4bqDGMW/eGgHaSZLZh+ifKE19HVwNw2f08Uf/Hpc5E", :host=>"centos-chef.wahwah.local:4000", :x_ops_authorization_5=>"g4ZRHXeRZoWeYUTUoDFnr/JJzk9ZFYw7CKms1rOR5NmYu7MXRW6TcJjMkFMf", :x_chef_version=>"0.8.16"}
[Mon, 27 Sep 2010 16:17:39 +0200] INFO: Authenticating client chef-validator
[Mon, 27 Sep 2010 16:17:39 +0200] DEBUG: Sending HTTP Request via