Skip to content

Instantly share code, notes, and snippets.

View joeljunstrom's full-sized avatar
🥰

Joel Junström joeljunstrom

🥰
  • Stockholm, Sweden
View GitHub Profile
before_save :hash_new_key, :if => :key_not_blank?
def key_not_blank?
!self.key.blank?
end
before_save :hash_new_key, :unless => :no_key?
def no_key?
self.key.blank?
end
module Encryptor
def encryptor(salt)
ActiveSupport::MessageEncryptor.new(Digest::SHA1.hexdigest(salt + Configuration.encryption_salt))
end
end
class Thing
include Encryptor
def hash_new_key
def http_methods
methods = Array.new
methods << 'GET' if self.http_get
methods << 'POST' if self.http_post
methods << 'PUT' if self.http_put
methods << 'DELETE' if self.http_delete
methods << 'HEAD' if self.http_head
methods
end
module Blargh
class Engine < Rails::Engine
initializer 'blargh.authentication' do |app|
ActiveSupport.on_load :action_controller do
# loloololol
end
end
end
end
# Page has datums ( data[] )
# A datum can have datums (data[]) [sic!]
# I need to pull a datum from page.data[0..infinity].data[something] == 'stuff'
# Tried:
Page.pull({}, {
data: {
data: { 'content_template_id' => some_id }
}
puts $db.collection('pages').update({ 'data._type' => 'ContentBlock' }, {
'$set' => {
'data.$.allow_texts' => true,
'data.$.allowed_asset_filetypes' => ['image'],
'data.$.allowed_page_template_ids' => page_template_ids
}
}, :multi => true, :safe => true)
class Sku
attr_reader :identifier
attr_reader :price
end
class Cart
many :cart_items
def quantity
cart_items.inject(0) { |quantity, item| quantity += item.quantity }
class Account < ActiveRecord::Base
scope :scope1, where("domain in('bit', 'bite')")
scope :scope2, where("custom_domain = 'bites'")
end
>> Account.scope1.scope2.to_sql
=> "SELECT \"accounts\".* FROM \"accounts\" WHERE (domain in('bit', 'bite')) AND (custom_domain = 'bites')"
>> Account.scope2.scope1.to_sql
=> "SELECT \"accounts\".* FROM \"accounts\" WHERE (custom_domain = 'bites') AND (domain in('bit', 'bite'))"
def create
@my_thing = MyThing.create(params[:my_thing])
respond_to do |format|
format.json { @my_thing.to_json }
end
end
$(document).ready(function() {
var $list = $('#list'),
$form = $('#my_form');
@joeljunstrom
joeljunstrom / deploy.rake
Created November 9, 2010 08:00
ugly hack for caching out merged assets for heroku deploy
require 'jsmin'
require 'aws/s3'
require 'yui/compressor'
task :deploy => ['deploy:console']
namespace :deploy do
task :console => :environment do
if Rails.env != 'production'
puts "We need to be running in production environment, ie 'rake RAILS_ENV=production deploy'"