This file contains hidden or 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
function getViewportOffset(forElement) { /* ported from prototype.js */ | |
var valueT = 0, valueL = 0; | |
var element = forElement; | |
while (element){ | |
valueT += element.offsetTop || 0; | |
valueL += element.offsetLeft || 0; | |
// Safari fix | |
if (element.offsetParent == document.body && element.css('position') == 'absolute') break; | |
element = element.offsetParent; | |
} |
This file contains hidden or 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 Period | |
attr_reader :start, :extent, :duration | |
def initialize(start, extent, duration) | |
@start, @extent, @duration = start, extent, duration | |
end | |
def finish | |
start + duration | |
end |
This file contains hidden or 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
module KnowsAboutItsImplementations | |
class << self | |
attr_reader :implementations | |
end | |
@implementations = [] | |
def self.included(klass) | |
self.implementations << klass | |
end |
This file contains hidden or 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
module Moderatable | |
@moderatable_classes = [] | |
class << self | |
attr_reader :moderatable_classes | |
def included(klass) | |
@moderatable_classes.include?(klass) || @moderatable_classes.push(klass) | |
klass.class_eval do | |
acts_as_state_machine :initial => :pending, :column => :moderation_state | |
state :pending | |
state :approved |
This file contains hidden or 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 Proc | |
def and_maybe(&func) | |
val = self.call | |
val ? func.call(val) : val | |
end | |
end |
This file contains hidden or 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
<!-- Got this in the html: --> | |
<div class="privacy"> | |
<input checked="checked" id="region_visible_public" name="user[region_visible]" type="radio" value="true" /> | |
<label for="region_visible_public">public</label> | |
<input id="region_visible_private" name="user[region_visible]" type="radio" value="false" /> | |
<label for="region_visible_private">private</label> | |
<script type="text/javascript"> | |
console.log("region_visible_public " + document.getElementById("region_visible_public").checked) |
This file contains hidden or 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
<!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 http-equiv="content-type" content="text/html; charset=UTF-8" /> | |
<link rel="shortcut icon" href="/images/favicon.ico"/> | |
<title>NCSL</title> | |
<script src="/javascripts/prototype.js?1252667573" type="text/javascript"></script> | |
<link href="/stylesheets/master.css?1252667573" media="screen" rel="stylesheet" type="text/css" /> | |
<link href="/stylesheets/reset.css?1252667573" media="screen" rel="stylesheet" type="text/css" /> |
This file contains hidden or 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
pascalTriangle :: (Integral a) => a -> [[a]] | |
pascalTriangle n = map pascalRow [1..n] | |
pascalRow :: (Integral a) => a -> [a] | |
pascalRow n = applyRepeatedly (n - 1) nextRow [1] | |
where | |
applyRepeatedly :: (Integral a) => a -> (b -> b) -> (b -> b) | |
applyRepeatedly 0 func = (\x -> x) | |
applyRepeatedly 1 func = func | |
applyRepeatedly n func = func . (applyRepeatedly (n - 1) func) | |
nextRow :: (Integral a) => [a] -> [a] |
This file contains hidden or 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 Object | |
def when(*a, &block) | |
a.inject(true) {|m, n| m && n} ? block.call(*([self] + a)) : self | |
end | |
end | |
upper_limit = nil | |
puts [1, 2, 3, 4, 5].when(upper_limit) {|array, upper_limit| array.select {|e| e < upper_limit}}.map {|n| n ** 2}.inject(0) {|m, n| m + n} | |
# => 55 |
This file contains hidden or 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 to_rows(array, rows) | |
new_array = [] | |
while !array.empty? | |
new_array << (1..rows).to_a.map { array.shift } | |
end | |
new_array | |
end |