9. m p e d e
sta am c o
e N rip
T im T
Monday, January 17, 2011
10. m p e d e n t
sta am c o n te
m e N Trip C o
T i
Monday, January 17, 2011
11. Colored Name
Easier to read than text-only nickname
Shift the first few bytes of hash into LSBs of color
def chat_color
digest = Digest::SHA1.hexdigest(self.tripcode +
self.name)
r = (digest[0..1].to_i(16) >> 1) + 127
g = (digest[2..3].to_i(16) >> 1) + 127
b = (digest[4..5].to_i(16) >> 1) + 127
"##{r.to_s 16}#{g.to_s 16}#{b.to_s 16}"
end
Monday, January 17, 2011
12. Tripcode
Identity without Password or Registration
Used on 4chan
def tripcode_digest
[Digest::SHA1.digest(self.tripcode)].
pack('m').
tr('+/','-_')[0..7]
end
Monday, January 17, 2011
16. Triskelion and Crapshoot
•Triskelion - Rails application
•UI Elements
•Crapshoot - Dice-rolling library
•Parsing with Ragel
•Infix and Postfix Notation
•Random numbers
Monday, January 17, 2011
17. Dice Code
•2d4
•Two four-sided dice
•1d100 + 8
•One hundred-sided die plus eight
•4d6v
•Four six-sided dice, minus the lowest
Monday, January 17, 2011
18. Dice Language
A programming language is […] designed to
express computations, […] to express
algorithms precisely, or as a mode of human
communication.
http://en.wikipedia.org/wiki/Programming_language
Monday, January 17, 2011
19. Triskelion and Crapshoot
•Triskelion - Rails application
•UI Elements
•Crapshoot - Dice-rolling library
•Parsing with Ragel
•Infix and Postfix Notation
•Random numbers
Monday, January 17, 2011
20. Regular Language
In computer science, a regular language is a formal
language […] that satisfies the following equivalent
properties:
•it can be accepted by a deterministic finite state
machine
•it can be generated by a regular grammar
http://en.wikipedia.org/wiki/Regular_language
Monday, January 17, 2011
21. Dice Language
4d6v + 3d10^ – 2d6 - 300
Monday, January 17, 2011
22. Dice Language
4d6v + 3d10^ – 2d6 - 300
Expression
Monday, January 17, 2011
23. Dice Language
4d6v + 3d10^ – 2d6 - 300
Monday, January 17, 2011
32. Dice Language
0 % D
0 IE
1 F
Number = digit+; I
T AR
R L
E U
Constant = Number; C G G E
E UA
R G
Drop = ('^' | 'v'); N
Series = Number 'd' Number Drop?; LA
Arithmetic = ('+' | '-');
UnaryExpression = Series | Constant;
BinaryExpression = UnaryExpression (space* Arithmetic space* UnaryExpression)+;
Expression = UnaryExpression | BinaryExpression;
Monday, January 17, 2011
33. Ragel
Ragel compiles executable finite state machines from regular
languages. Ragel targets C, C++, Objective-C, D, Java and
Ruby.
http://www.complang.org/ragel/
Monday, January 17, 2011
34. scan.rl
%%{
machine scanner;
action _number { @mark_num = p }
Language Actions
action number { @num_stack.push atos(data[@mark_num..p-1]) }
action constant { @tokens << Tokens::Constant.new(@num_stack.pop) }
action series {
drop = @drop_current
@drop_current = nil
sides = @num_stack.pop
count = @num_stack.pop
@tokens << Tokens::Series.new(count, sides, drop)
}
action arithmetic { @tokens << Tokens::Arithmetic.new(data[p-1].chr) }
action drop { @drop_current = data[p-1].chr }
Number = digit+ >_number %number;
Constant = Number %constant;
Drop = ('^' | 'v') %drop;
Series = Number 'd' Number Drop? %series;
Arithmetic = ('+' | '-') %arithmetic;
UnaryExpression = Series | Constant;
BinaryExpression = UnaryExpression (space* Arithmetic space* UnaryExpression)+;
Expression = UnaryExpression | BinaryExpression;
main := Expression;
}%%
Monday, January 17, 2011
39. scan.rl
Transform constant, series, and arithmetic elements into
Token objects
action constant { @tokens << Tokens::Constant.new(@num_stack.pop) }
action series {
drop = @drop_current
@drop_current = nil
sides = @num_stack.pop
count = @num_stack.pop
@tokens << Tokens::Series.new(count, sides, drop)
}
action arithmetic { @tokens << Tokens::Arithmetic.new(data[p-1].chr) }
Monday, January 17, 2011
40. Tokens
Token#eval
Turn token into result during evaluation
Token#independent
Determine if token needs the next token during postfixing
Token#inspect
<Crapshoot::Tokens::Series dice=4d6 drop=nothing>
Monday, January 17, 2011
51. Postfix Evaluation
•Series
•Roll dice
•Do drop
Monday, January 17, 2011
52. Postfix Evaluation
•Series
•Roll dice
•Do drop
•Push result to stack
Monday, January 17, 2011
53. Postfix Evaluation
•Constant
•Series
•Roll dice
•Do drop
•Push result to stack
Monday, January 17, 2011
54. Postfix Evaluation
•Constant
•Series
•Push value to stack
•Roll dice
•Do drop
•Push result to stack
Monday, January 17, 2011
55. Postfix Evaluation
•Constant
•Series
•Push value to stack
•Roll dice
•Arithmetic
•Do drop
•Push result to stack
Monday, January 17, 2011
56. Postfix Evaluation
•Constant
•Series
•Push value to stack
•Roll dice
•Arithmetic
•Do drop
•Pop twice
•Push result to stack
Monday, January 17, 2011
57. Postfix Evaluation
•Constant
•Series
•Push value to stack
•Roll dice
•Arithmetic
•Do drop
•Pop twice
•Push result to stack
•Push result
Monday, January 17, 2011