Skip to content

Instantly share code, notes, and snippets.

View evie404's full-sized avatar

Evelyn Pai evie404

View GitHub Profile
@evie404
evie404 / gist:6287918
Created August 20, 2013 22:01
rails controller with ivar set in private method
class HistoryController < ApplicationController
before_filter :get_history, only: [:show, :edit, :update, :destroy]
def index
@histories = History.all
end
def show
@history = History.find(params[:id])
end
@evie404
evie404 / class_var.rb
Last active December 21, 2015 05:18
Class variable propagates to child classes in Ruby
class Parent
def self.class_var
@@class_var ||= self.name
end
def self.instance_var
@instance_var ||= self.name
end
end
Lemongrass & Citrus
Earl Grey
Breakfast Blend
Royal Blend
Green Tea w/ Yuzu
Pu Erh w/ Ginger
Irish Cream (really creamy black tea)
Apple & Elderflower
Hi all,
I recently attended a local tech meetup where they talked about the deficiencies of javascript and the prominence of this new coffeescript language and how it improves developer productivity. For example, instead of stitching strings together in an old and ugly way:
str = "<a href=\""+url+"\">"+text+"</a>"
you can write in a rubyique way:
str = "<a href=\"#{url}\">#{text}</a>"
class Costume < ActiveRecord::Base
extend Namable
extend Commentable
extend Collectable
extend Viewable
extend HasPhotos
belongs_to :character
belongs_to :series
belongs_to :variation
@evie404
evie404 / gist:5347970
Created April 9, 2013 18:09
Don't try this at home
puts 1+2
class Fixnum
def +(y)
self * y
end
end
puts 1+2
# I use nateware/redis-objects as an easy way to implement atomic counters in my ActiveRecord models in Rails.
# But I still need counters in sql to sort models with them.
# So the CounterSyncWorker goes through the object space, selects all class that is an AR model and includes Redis::Objects,
# check for all columns that have _sql equivalents, fetches the value in redis and store into the AR attribute.
# Example:
# when uploading a photo that belongs to first user:
class Photo < ActiveRecord::Base
#...
def image_url *args
url = super
url.gsub!('.', '@2x.') if args[0] == :square_thumb #add @2x to filename if square_thumb is requested
url
end
@evie404
evie404 / gist:3895535
Created October 15, 2012 21:13
fix brew permission problems
sudo chown -R $USER:admin /usr/local/*