This file contains 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 Piyo | |
def piyo_func | |
'piyo_func' | |
end | |
end | |
class Hoge | |
include Piyo | |
def initialize | |
class << self |
This file contains 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 monte n #点を打つ数 | |
r = 0 | |
n.times do | |
# PIの確率でHITするから円内にHITすれば+1 | |
r+=1 if Math.sqrt(rand()**2+rand()**2) < 1 | |
end | |
# 円の面積/正方形の面積がPI/4 | |
4.0*r / n | |
end |
This file contains 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
for fib in [1..10].map((x) -> do (x) -> if x is 0 or x is 1 then x else arguments.callee(x-1)+arguments.callee(x-2)) | |
console.log do -> if fib % 15 is 0 then 'FizzBuzz' else if fib % 3 is 0 then 'Fizz' else if fib % 5 is 0 then 'Buzz' else fib | |
### | |
実行結果 | |
1 | |
1 | |
2 | |
Fizz |
This file contains 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
fib = [1..10].map((x) -> do (x) -> if x is 0 or x is 1 then x else arguments.callee(x-1)+arguments.callee(x-2)) | |
for n in [1..10] | |
console.log if n in fib and n % 5 is 0 then 'FibBuzz' else if n in fib then 'Fib' else if n % 5 is 0 then 'Buzz' else n | |
### | |
実行結果 | |
Fib | |
Fib | |
Fib | |
4 |
This file contains 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
for n in [1..100] | |
console.log switch | |
when n % 15 is 0 | |
'FizzBuzz' | |
when n % 5 is 0 | |
'Buzz' | |
when n % 3 is 0 | |
'Fizz' | |
else | |
n |
This file contains 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
### | |
DateFormat.jsは | |
http://yas-hummingbird.blogspot.com/2010/03/javascript-netdate.html | |
さんが書かれたJSのDateのtoString用パッチです。 | |
ライセンスは下記を参照ください。 | |
### | |
### | |
Javascript Date dateFormat | |
Copyright 2010 |
This file contains 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 MyRegexp | |
def self.match(regexp, text) | |
if regexp[0] == '^' | |
return matchhere(regexp[1,regexp.size], text) | |
end | |
text.chars.with_index do |c,i| | |
return true if matchhere(regexp, text[i,text.size]) | |
end | |
return false | |
end |
This file contains 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
# -*- encoding: utf-8 -*- | |
require 'net/http' | |
require 'rubygems' | |
require 'nokogiri' | |
class Comment | |
class << self | |
attr_accessor :cookie | |
end | |
#下の値はブラウザのクッキーから取得してください |
This file contains 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
get: function( num ) { | |
return num == null ? | |
// Return a 'clean' array | |
this.toArray() : | |
// Return just the object | |
( num < 0 ? this[ this.length + num ] : this[ num ] ); | |
} |
This file contains 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
Object.prototype.send = function (name) { | |
return (function (prototype) { | |
if (!prototype) | |
return undefined; | |
if (name in prototype) | |
return prototype[name]; | |
arguments.callee(prototype.__proto__); | |
})(this); | |
}; |
OlderNewer