Skip to content

Instantly share code, notes, and snippets.

View jdwyah's full-sized avatar

Jeff Dwyer jdwyah

View GitHub Profile
ree-1.8.7-2011.03 :002 > Array("aa\nbb")
=> ["aan", "bb"]
ruby-1.9.2-p180 :008 > Array("aa\nbb")
=> ["aanbb"]
@jdwyah
jdwyah / git-mav alias
Created February 11, 2011 15:33
git alias
[alias]
co = checkout
br = branch
mav = !afplay -v .3 -t 12 '/Users/jdwyah/Music/iTunes/iTunes Music/Kenny Loggins/Top Gun/Danger Zone.mp3' &\ngit rebase -i
panic = !tar cvf ../git_panic.tar *
@jdwyah
jdwyah / MavMark v0.1.rb
Created December 6, 2010 17:18
A text editor benchmark
# MavMark v 0.1
#########################
# Indent a messed up ruby file.
# Goal:
#def excluded_description
# excludes_that_exist = @report.excludes.inject({}) do |memo, (dim,excludes)|
# swap_unrep = (@report.original_dim_labels[dim.to_sym] || []).map{|l| l.blank? ? 'Unreported' : l}
# memo[dim] = excludes & swap_unrep
# memo
pg_restore: [archiver (db)] could not execute query: ERROR: must be member of role "postgres"
Command was: ALTER SCHEMA multum OWNER TO postgres;
pg_restore: [archiver (db)] Error from TOC entry 1217; 2612 200456859 PROCEDURAL LANGUAGE plpgsql postgres
pg_restore: [archiver (db)] could not execute query: ERROR: must be owner of database plmwebsite
Command was: CREATE PROCEDURAL LANGUAGE plpgsql;
pg_restore: [archiver (db)] could not execute query: ERROR: language "plpgsql" does not exist
Command was: ALTER PROCEDURAL LANGUAGE plpgsql OWNER TO postgres;
pg_restore: [archiver (db)] Error from TOC entry 21; 1255 422525031 FUNCTION _group_concat(text, text) postgres
pg_restore: [archiver (db)] could not execute query: ERROR: must be member of role "postgres"
Command was: ALTER FUNCTION public._group_concat(text, text) OWNER TO postgres;
# our multi_group http://rails.lighthouseapp.com/projects/8994/tickets/120-patch-activerecord-calculations-only-accept-one-grouping-field#
# isn't updated for 2.2 yet. In the meantime, this poor man's version gives you the same results with some delimitter tom foolery.
#
# note: be careful to ensure that your group_by do not use the delimitter
# usage:
# self.multi_count(:id, :distinct => true, :group => [:symptom_id, :treatment_id])
# [[["138", "1018"], 187], [["138", "427"], 373], [["6", "1018"], 197], [["6", "427"], 393]]
class ActiveRecord::Base
def self.multi_count(field, opts = {})
fq_field_name = "#{table_name}.#{field}"
def encrypt(string, key)
Base64.encode64(aes(key, string)).gsub /\s/, ''
end
def decrypt(string, key)
aes_decrypt(key, Base64.decode64(string))
end
def aes(key,string)
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
Ajax.Responders.register({
onCreate: function(a) {
if(a.method != 'get'){
a['parameters']['authenticity_token'] = encodeURIComponent('#{form_authenticity_token}');
}
}
});