Skip to content

Instantly share code, notes, and snippets.

View airhorns's full-sized avatar
🎯
Workin' on Gadget at https://gadget.dev

Harry Brundage airhorns

🎯
Workin' on Gadget at https://gadget.dev
View GitHub Profile
Started GET "/work_orders/queue" for 127.0.0.1 at 2010-07-18 19:53:11 -0400
SQL (1.6ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (1.1ms) SELECT name
FROM sqlite_master
WHERE type = 'table' AND NOT name = 'sqlite_sequence'
SQL (1.1ms) SELECT name
FROM sqlite_master
# model
class GiftIdea
has_many :images
end
# in the view (say app/views/gift_ideas/show.html.erb)
# say we are rendering html about one GiftIdea object, found in the @gift_idea variable
..
..
<div class="gift_idea">
Started GET "/product_categories/autocomplete_for_product_sub_category_name?q=ang&limit=10&timestamp=1279805094583" for 130.15.105.53 at 2010-07-22 09:29:55 -0400
Processing by ProductCategoriesController#autocomplete_for_product_sub_category_name as HTML
Parameters: {"q"=>"ang", "limit"=>"10", "timestamp"=>"1279805094583"}
Rendered inline template (0.6ms)
Completed 200 OK in 58ms (Views: 1.7ms | ActiveRecord: 7.7ms)
Started GET "/product_categories/autocomplete_for_product_sub_category_name?q=ang&limit=10&timestamp=1279805094583" for 130.15.105.53 at 2010-07-22 09:30:05 -0400
Processing by ProductCategoriesController#autocomplete_for_product_sub_category_name as HTML
Parameters: {"q"=>"ang", "limit"=>"10", "timestamp"=>"1279805094583"}
def build_role(&block)
@role = Role.new
self.instance_eval &block if block_given?
r = @role
@role = nil
r
end
Questions: do you always need to have m or can you just use a helper method where you get the number of elements in a, that way you limit the number of parameters you pass always?
1. More on list intersections
Algorithm: commonElementsList( a, m, b, n)
Input: Two arrays, a and b, with m and n distinct String elements respectively
Output: A list of String elements common to both arrays
function commonElementsList( a, m, b, n) {
if( listIntersection( a, m, b, n ) > 0 )
User
- has_many :end_of_day_reports
Quote
- has_and_belongs_to_many :end_of_day_reports
- has_many :time_reports
EndOfDayReport
- has_and_belongs_to_many :quotes
- belongs_to :user
module Toto
module Template
def to_html page, config, &blk
path = ([:layout, :repo].include?(page) ? Paths[:templates] : Paths[:pages])
config[:to_html].call(path, page, self, blk)
end
end
end
toto = Toto::Server.new do
# ...
set :to_html, lambda {|path, page, ctx, blk|
Dir.glob("#{path}/#{page}.*").each do |filename|
return ::Tilt.new(filename).render(ctx, &blk)
end
raise Errno::ENOENT # Tell toto to 404 if no files can be found
}
hash = {foo: 1, bar: 2, baz: 3}
handlers = []
for key, val of hash
callback = ->
console.log "Callback has been called for key #{key}"
handlers[val] = callback
handlers[1].call() # outputs 'baz' instead of the expected 'foo', because baz was the last key assigned.
@airhorns
airhorns / gist:771286
Created January 9, 2011 00:46
Potential Validations syntax
// A complete example.
var Post = Backbone.Model.extend({
validations: {
body: {
required: true, // Uses the built in validation methods
minLength: 100
},
title: {
// Pass multiple arguments to the validation function
lengthInRange: [10,100],