Skip to content

Instantly share code, notes, and snippets.

@KensoDev
KensoDev / gist:6933057
Created October 11, 2013 11:11
Provider
module NuregoConnector
class Billing
def self.provider=(some_provider)
@@provider = some_provider.new
end
def self.provider
@@provider
end
@KensoDev
KensoDev / decrypt.rb
Last active December 25, 2015 06:29
Get a hashed string from JSON
CLIENT_SECRET = '2057f37a2b5275ef1ecf8f93c8e88628ded594ce'
#this is the data from encrypt.rb
data = 'YUVoYVMwSnVkVkJxU2pGa1RHOTRlbGR3U25WVUt6ZDNSRE5MZVhKd1YyVnZTbFUyUVhSdWRUUk5MM05ZYkVobVJVRlBVWHBKVjBaQlNHRkRhVFZzYlVsWlJHdERZV1pqYTA5d1pETTVjSEZyY21RNE5HNVBSMEpLTmpsVU1uSnZUMVkzV1RrelJraHlPSGxHVDBJNFJGWjRSVTgyWlZkamJHUlplV0V6T0hRdExWUlZSMUF2T1hoNU1HUjJkRE5qV21welVraEdOVkU5UFE9PS0tNTA1YjMzMjliYmU3NjVmMDVlN2E4MmU3MjM3ODE4ODVlZjJlNzNlYw=='
data = Base64.strict_decode64(data)
encryptor = ActiveSupport::MessageEncryptor.new(CLIENT_SECRET)
encryptor.decrypt_and_verify(data)
@KensoDev
KensoDev / gist:6917303
Created October 10, 2013 12:08
nginx down
server {
listen 80;
server_name mysite.com;
root /var/www/mysite.com/;
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
... # the rest of your config goes here
def remove_records(existing_records, records, method)
records.each { |record| callback(:before_remove, record) }
records.each { |record| callback(:before_destroy, record) }
delete_records(existing_records, method) if existing_records.any?
records.each { |record| target.delete(record) }
records.each { |record| callback(:after_destroy, record) }
records.each { |record| callback(:after_remove, record) }
end
def remove_records(existing_records, records, method)
records.each { |record| callback(:before_remove, record) }
delete_records(existing_records, method) if existing_records.any?
records.each { |record| target.delete(record) }
records.each { |record| callback(:after_remove, record) }
end
@KensoDev
KensoDev / gist:4772440
Created February 12, 2013 19:11
Module functions
class User
include ModelUtils
def some_method
unique_id_for(self)
end
end
module ModelUtils
module_function
@KensoDev
KensoDev / gist:4578286
Created January 20, 2013 12:31
Replace CSS rules with the JS equivalent.
var exp = /-([a-z])/gi;
s = 'background-color';
s.replace(exp, function(m, c, i, str) {
return c.toUpperCase();
}
);
query = GraphEngine::UserPlace.where(place_id: place_id).or(
{:user_id.in => user.gogobot_following_ids, :ext_app_type => GraphEngine::ExtAppType::GOGOBOT},
{:user_id.in => user.facebook_friend_ids, :ext_app_type => GraphEngine::ExtAppType::FACEBOOK}
).asc(:ext_app_type)
# ~/.tmuxinator/graph_engine.yml
# you can make as many tabs as you wish...
project_name: graph_engin
project_root: ~/dropbox/projects/graph_engine
rvm: ruby-1.9.3-p0@graph_engine
tabs:
- editor:
layout: main-horizontal
panes:
if cookies
@arrival_date = cookies['check_in_date'].to_s
@departure_date = cookies['check_out_date'].to_s
end
@number_of_nights = (@departure_date.to_date - @arrival_date.to_date).to_i