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 Integer | |
def factor_of? (other) | |
other % self == 0 | |
end | |
end | |
1.upto(100) do |x| | |
bt = (3.factor_of?(x) ? "" :"not ") + "divisible by 3" | |
bf = (5.factor_of?(x) ? "" : "not ") + "divisible by 5" | |
puts "The value #{x} is #{bt} and is #{bf}" |
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
%%{ | |
machine telnet_nvt_common; | |
alphtype unsigned char; | |
# Special bytes that must be handled differently from normal text: | |
CR = "\r"; # Only \0 or \n may follow | |
IAC = 255; # Telnet command marker | |
special_byte = CR | IAC; | |
# The only bytes that may follow a CR: |
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 Lupin::Test | |
dynamic_method :foo do |g| | |
ast = Lupin::Parser.parse("1+4- -10", :root => :expression).value | |
Lupin::Compiler.compile(ast, g) | |
g.ret | |
end | |
end | |
puts Lupin::Test.new.foo #=> 15.0 |
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' :: (Integral a) => a -> (a, a) | |
fib' 0 = (0, 0) | |
fib' 1 = (0, 1) | |
fib' x = (b, a + b) | |
where (a, b) = fib'(x-1) | |
fib :: (Integral a) => a -> a | |
fib x = result | |
where (_, result) = fib'(x) |
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 ResponsePadder | |
def initialize (app, minlength, pad=' ', &condition) | |
@app = app | |
@minlength = minlength | |
@pad = pad | |
@condition = condition | |
end | |
def call (env) | |
response = @app.call(env) |
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
var sys = require("sys"); | |
var ANSI = (function() { | |
sys.inherits(ANSI, require("events").EventEmitter); | |
function ANSI() { | |
this.state = "plain"; | |
this.reset(); | |
} | |
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
FG: 7 BG: 0 | |
Italic: 0 | |
Underline: 0 | |
Strike: 0 | |
Text: this is | |
FG: 9 BG: 0 | |
Italic: 0 | |
Underline: 0 | |
Strike: 0 |
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 StringEscaper | |
def process_escapes (str) | |
str.gsub! /\\(u\d{4}|\D)/m do | |
seq = $1 | |
case seq | |
when '/' then "\/" | |
when 'b' then "\b" | |
when 'f' then "\f" | |
when 'n' then "\n" | |
when 'r' then "\r" |
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
%% name = Lupin::Parser | |
%% { | |
require 'rubinius/debugger' | |
require 'ast' | |
attr_accessor :ast | |
def process_string_escapes (text) | |
text = text.to_s | |
text.gsub! /\\(\d{1,3}|\D)/m do |
OlderNewer