This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require('fs') | |
triangle = fs.readFileSync('../triangle.txt', 'utf-8') | |
.split('\r\n') | |
.map((x) -> x.split(' ').map((y) -> +y)) | |
.reverse() | |
.splice(1) | |
reduction = (prev, current) -> | |
current.map (x, i) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# LiquidView is a action view extension class. You can register it with rails | |
# and use liquid as an template system for .liquid files | |
# | |
# Example | |
# | |
# ActionView::Base::register_template_handler :liquid, LiquidView | |
class LiquidView | |
PROTECTED_ASSIGNS = %w( template_root response _session template_class action_name request_origin session template | |
_response url _request _cookies variables_added _flash params _headers request cookies | |
ignore_missing_templates flash _params logger before_filter_chain_aborted headers ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def nil.method_missing(method, *args) | |
(@@activeRecordClasses ||= ObjectSpace.each_object(Class).find_all { |c| | |
c.respond_to?(:ancestors) && c != ActiveRecord::Base && c.ancestors.include?(ActiveRecord::Base) | |
}).choice.order("rand()").first || self.method_missing(method, *args) | |
rescue | |
self.method_missing(method, *args) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ref from http://stackoverflow.com/questions/2361945/detecting-consecutive-integers-in-a-list | |
from itertools import groupby | |
from operator import itemgetter | |
class PageRange(object): | |
@staticmethod | |
def to_text_range(array_of_numbers): | |
text_buffer = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeController < AC::Base | |
# defines the general view model along with a way to introduce the state and pre-scope models | |
view_model = MyGeneralViewModel do |state| | |
user = get_user | |
state.user = user | |
state.scope = Model.where(:user => user) | |
end | |
# interact with the view model just like an active record model | |
# scopes would be present and things would feel like AR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim $(grep -lr --include=*.rb omc_data_service .) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ref http://spin.atomicobject.com/2012/10/30/activerecord-black-magic/ | |
class EmployeeFinder | |
def self.accessible_by(user) | |
Employee.joins(:companies) \ | |
.merge(Company.where(:id => user.company_ids)) \ | |
.uniq | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compiled javascript file | |
(function() { | |
var appendToContainer, buildElement, buildElements, getAllPeople, getAllPets, getPeople, getPets, | |
__slice = [].slice; | |
$(document).ready(function() { | |
return getAllPeople().then(getAllPets).then(buildElements).then(appendToContainer); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# grep across all commits | |
git grep <pattern> $(git rev-list --all) | |
# find out which branch(es) contains said commit | |
git branch -r --contains <sha1> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def render(template, save_path, vars) | |
template_file = File.open("lib/templates/#{template}", 'r').read | |
erb = ERB.new(template_file) | |
results = erb.result(OpenStruct.new(vars).instance_eval { binding }) | |
File.open(save_path, 'w+') { |file| file.write(results) } | |
end |