Skip to content

Instantly share code, notes, and snippets.

View ltw's full-sized avatar

Lucas Willett ltw

View GitHub Profile
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy for Windows (vers 14 February 2006), see www.w3.org" />
<title></title>
<meta http-equiv="Content-Type"
content="text/html; charset=us-ascii" />
<link href="main.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]>
test1 = [1,2,3]
test2 = [2,3,4,5,6,7,8]
unknown, known = *[test1 - test2, test1 & test2]
#=> [[1],[2,3]]
def self.generate_planned_simulation(model_package_id, start_date, finish_date, increment)
start_date = Date.strptime(start_date,'%B %d, %Y')
finish_date = Date.strptime(finish_date, '%B %d, %Y')
dates = get_dates_with_interval(start_date, finish_date, increment)
activities = Activity.all(
:conditions => [
'(start_date <= :finish_date OR finish_date <= :finish_date) AND model_package_id = :model_package_id',
{ :finish_date => finish_date, :model_package_id => model_package_id }
],
[:last, :this, :next].each do |week|
define_method("#{week}_week") { schedule(week) }
end
def schedule(week)
@schedule ||= YAML.load_file('schedule.yml')["schedule"]
@schedule.select {|d| date_range(week.to_sym).include?(d)}
end
def date_range(week)
@ltw
ltw / best_model.rb
Created February 21, 2011 01:29
Order of a standard Model
class Model < ParentModel
include Foo::Bar
extend Bar::Baz
acts_as_authentic
dsl_specific_flags
module InternalModule
...
end
@ltw
ltw / test.rake
Created January 24, 2012 22:16
List all routes available in a Rails application with the mappings back to controllers and actions
namespace :routes do
desc 'print list of routes'
task :list => [:environment] do
Rails.application.routes.routes.map do |route|
p "#{route.requirements[:controller]} #{route.requirements[:action]} #{route.verb}"
end
end
end
@ltw
ltw / nested_factories.rb
Created January 25, 2012 00:22
Using different factory girl techniques to build specific factories
FactoryGirl.define do
factory :contact do
name 'Nigel Weiner'
factory :admin_contact do
admin true
end
end
end
@ltw
ltw / letterpress.rb
Created October 26, 2012 18:21 — forked from dpick/gist:3956825
class Letterpress
def self.run(board)
all_words = File.open('/usr/share/dict/words').readlines.map! { |line| line.strip.chomp }
valid_words = all_words.select { |w| w =~ /[^#{board.join}]/ }
valid_words = valid_words.select do |w|
bool = true
bool = false if w.size <= 2
split_word = w.downcase.split('')
@ltw
ltw / class_definitions.rb
Last active December 11, 2015 16:58
Fun with API Routes
# app/controllers/api/v1/users_controller.rb
class Api::V1::UsersController
def index
render json: { path: 'v1/users#index' }
end
def show
render json: { path: 'v1/users#show' }
end
end
fn main() {
for int::range(1, 101) |num| {
let mut answer;
if is_fifteen(num){
answer = "FizzBuzz"; }
else if is_three(num) {
answer = "Fizz";
}
else if is_five(num) {
answer = "Buzz"; }