Skip to content

Instantly share code, notes, and snippets.

View jdwyah's full-sized avatar

Jeff Dwyer jdwyah

View GitHub Profile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
ruby '2.0.0'
gem 'rails', '4.0.7'
gem 'pg'
gem 'foreigner'
gem 'devise'
gem 'unicorn'
@jdwyah
jdwyah / homebrew.rb
Last active August 29, 2015 14:07 — forked from pincheira/homebrew.rb
ruby -e "$(curl -fsSL https://gist.githubusercontent.com/jdwyah/a7432521ea8fa81c1557/raw/9e5b58c28c7965ff94e6aeb1c718c67be62df1f5/homebrew.rb)"
select date_trunc('month', date), count(distinct user_id) from events
where event = "login" group by 1 order by 1
@jdwyah
jdwyah / 1.sql
Created February 22, 2015 15:37
with monthly_usage as (
select
who_identifier,
datediff(month, '1970-01-01', when_timestamp) as time_period
from events
where event = 'login' group by 1,2 order by 1,2),
@jdwyah
jdwyah / 2.sql
Created February 22, 2015 15:37
lag_lead as (
select who_identifier, time_period,
lag(time_period,1) over (partition by who_identifier order by who_identifier, time_period),
lead(time_period,1) over (partition by who_identifier order by who_identifier, time_period)
from monthly_usage),
@jdwyah
jdwyah / 3.sql
Created February 22, 2015 15:38
lag_lead_with_diffs as (
select who_identifier, time_period, uses_outlook, lag, lead,
time_period-lag lag_size,
lead-time_period lead_size
from lag_lead),
create table events (
user_id int
date date_time
event text
)
Ajax.Responders.register({
onCreate: function(a) {
if(a.method != 'get'){
a['parameters']['authenticity_token'] = encodeURIComponent('#{form_authenticity_token}');
}
}
});
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")