Skip to content

Instantly share code, notes, and snippets.

View evie404's full-sized avatar

Evelyn Pai evie404

View GitHub Profile
@evie404
evie404 / gist:3895535
Created October 15, 2012 21:13
fix brew permission problems
sudo chown -R $USER:admin /usr/local/*
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
# 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:
@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
class Costume < ActiveRecord::Base
extend Namable
extend Commentable
extend Collectable
extend Viewable
extend HasPhotos
belongs_to :character
belongs_to :series
belongs_to :variation
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>"
Lemongrass & Citrus
Earl Grey
Breakfast Blend
Royal Blend
Green Tea w/ Yuzu
Pu Erh w/ Ginger
Irish Cream (really creamy black tea)
Apple & Elderflower
@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
@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
//1. Create a variable called test of type boolean and assign the variable the value true.
boolean test = true;
//2.Create a variable called a of type int and assign the variable the value 5.
int a = 5;
/*3.Type in an if statement that adds 1 to a if test has value true and subtracts 1 from a if test has value false.
Helpful hint: The DrJava interactions pane will evaluate an expression after you hit the return key if what you have typed in is a valid expression. To keep the interactions pane from evaluating your if statement prematurely, either type the entire statement in one line or place the statement inside braces { }*/
if (test == true) {
a + 1;
}
else {