Skip to content

Instantly share code, notes, and snippets.

View matthewrudy's full-sized avatar

Matthew Rudy Jacobs matthewrudy

View GitHub Profile
@matthewrudy
matthewrudy / maddy
Created November 30, 2008 23:28 — forked from roag/maddy
data Btree a = ND | Data a | Branch (Btree a) (Btree a)
deriving (Show,Eq)
data Dir = L | R
deriving (Show,Eq)
type Path = [Dir]
--- Part a)
# each approach
locations = []
stocks.each {|stock| locations << stock.location}
return locations
# refactored with inject
stocks.inject([]) {|locations, stock| locations << stock.location}
# the correct approach
stocks.map {|stock| stock.location}
set :site_path, Proc.new { Capistrano::CLI.ui.ask "Site to export (e.g. 'all', 'JGP' etc.): " }
# we don't want exporting all sites if nothing is provided
# that would be a costly mistake...
raise ArgumentError, "Site path must be specified" if site_path == ""
# site_path here is whatever we specify, 'JGP' for example
# if 'all' was provided, reset site_path to .../sites/
site_path = "" if site_path == "all"
module Widgets::GeneralHelper
def stylesheets_include(options = {})
set_minify
default_options = {:stylesheets => "all", :blueprint => false, :site_code => false, :ie => false}
stylesheets_options = default_options.merge(options)
raise Dir["#{Rails.root}/public/sites/#{site.site_code}/css/*"].to_yaml
...
%%%6. Define a predicate list_of_divisors(N,L) which for a positive integer N
%%% calculates the list of its proper divisors. (A proper divisor of n is a positive
%%% integer m < n such that m divides n.)
divisor(N,P) :-
P>0,
N>P,
0 is N mod P.
<!-- HTMLTrace:Start sites/vacancies/_dam_link_rdfa.rhtml -->
<%
return unless file = dam_link_rdfa.downloadable_application_form
return unless file_name = file.file_name
if file_found?(file)
file_name_for_link = case file_name
when /\.pdf$/i then "Downloadable Form (PDF)"
>> vdaf = VacancyDownloadableApplicationForm.last
VacancyDownloadableApplicationForm Load (0.122909) SELECT * FROM `vacancy_downloadable_application_forms` ORDER BY vacancy_downloadable_application_forms.id DESC LIMIT 1
VacancyDownloadableApplicationForm Columns (0.063622) SHOW FIELDS FROM `vacancy_downloadable_application_forms`
=> #<VacancyDownloadableApplicationForm id: 54228, vacancy_id: 53520, attachment_id: 3104, name: "Welwyn Hatfield Council - Standard">
>> vdaf.downloadable_application_form
DownloadableApplicationForm Columns (0.027216) SHOW FIELDS FROM `uploaded_files`
DownloadableApplicationForm Load (0.042126) SELECT * FROM `uploaded_files` WHERE (`uploaded_files`.`id` = 3104) AND ( (`uploaded_files`.`type` = 'DownloadableApplicationForm' ) )
=> #<DownloadableApplicationForm id: 3104, file_name: "568.pdf", file_type: "pdf", type: "DownloadableApplicationForm", name: nil, organisation_id: nil, jgp4_id: nil, originated_from: nil>
irb(main):001:0> name = "réunion-journalière"
=> "r\303\251union-journali\303\250re"
irb(main):002:0> File.open(name, 'w'){|f| f.write 'x' }
=> 1
irb(main):003:0> exit
$ ls -al
> total 36
> drwxr-xr-x 2 rlivsey rlivsey 4096 Jul 3 22:00 .
> drwxrwxr-x 10 rlivsey rlivsey 4096 Jul 3 12:20 ..
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def with_explicit
return 1
end
def with_implicit
1
end
# I'm creating some classes and modules on the fly, but things aren't hooking up quite the way I'd hoped.
# Can anyone explain why when an instance of Mod::Sibling tries to call Child.cry, that it
# doesn't call Mod::Child.cry, but instead looks for Behaviour::Child?
class Base
def self.cry
"#{self.name}.cry called!"
end
end