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
# | |
# This module is a collection of named_scope for time column. | |
# Requires MySQL to work because of usage of MySQL functions. | |
# But you can easly replace that part to work with another databases. | |
# | |
# Example | |
# | |
# class Article < ActiveRecord::Base | |
# include TimeScopes[:created_at] | |
# 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
# This rack app overrides http method by __method=xxx query. | |
# | |
# Example | |
# | |
# link_to 'Destroy', post_path(@post, :__method => :delete) | |
class RequestMethodOverrider | |
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS) | |
HTTP_METHOD_OVERRIDE_KEY = "__method".freeze | |
def initialize(app) |
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 Daemons | |
class Base | |
include SSH | |
attr_accessor :server | |
delegate :logger, :address, :to => :server | |
class << self | |
def inherited(klass) |
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
#!/usr/bin/env ruby | |
a = [1,2,3,4] | |
a.each { |x| a.delete(x) } | |
#=> [2,4] | |
a = [1,2,3,4] | |
a.each { |x| a -= [x] } | |
#=> [] |
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
#!/usr/bin/env Rscript | |
# 統計データがなかったので、お正月番組に触発されてテーブルクロス引きでコップが | |
# ずれた距離を測りました。コップの中の水の容量は | |
# (x1, x2,..., x5) = (0, 50,.., 200) | |
# です。それぞれの容量で5回ずつ測定。単位はcmとccです。 | |
x1 <- c(1.5, 2.2, 2.4, 2.2, 2.7) | |
x2 <- c(1.8, 1.6, 1.9, 1.6, 1.6) | |
x3 <- c(1.7, 2.1, 1.6, 1.5, 2.0) |
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
#!/usr/bin/env ruby | |
module Teacher | |
def self.included(model) | |
model.instance_eval do | |
extend ClassMethods | |
include InstanceMethods | |
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
; This is from http://www.learningclojure.com/2009/09/fractal-tree.html | |
(import '(javax.swing JFrame JPanel ) | |
'(java.awt Color Graphics Graphics2D)) | |
(defn draw-tree [#^Graphics g2d angle x y length branch-angle depth] | |
(if (> depth 0) | |
(let [new-x (- x (* length (Math/sin (Math/toRadians angle)))) | |
new-y (- y (* length (Math/cos (Math/toRadians angle)))) | |
new-length (fn [] (* length (+ 0.75 (rand 0.1)))) | |
new-angle (fn [op] (op angle (* branch-angle (+ 0.95 (rand)))))] |
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 Maybe | |
class NullObject | |
def initialize | |
@origin = caller.first | |
end | |
def __null_origin__ | |
@origin | |
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
/** | |
* Builder pattern example from Effective Java. | |
*/ | |
public final class NutritionFacts { | |
private final int servingSize; | |
private final int servings; | |
private final int calories; | |
private final int fat; | |
private final int sodium; | |
private final int carbohydrate; |
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
*.png | |
*.eps |
OlderNewer