SlideShare ist ein Scribd-Unternehmen logo
1 von 78
Downloaden Sie, um offline zu lesen
Triskelion
                                  and
                           Crapshoot
                            Miami Ruby Brigade
                             January 17, 2010




Monday, January 17, 2011
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
Pen and Paper Games
                           Pens
                           Paper        Talking
                           Dice         Snacks
                           Books
Monday, January 17, 2011
Pen and Paper Games
                           Pens
                           Paper        Talking
                           Dice         Snacks
                           Books
Monday, January 17, 2011
Monday, January 17, 2011
Monday, January 17, 2011
m p
                                 sta
                               e
                           T im




Monday, January 17, 2011
m p        e
                                 sta        am
                               e          N
                           T im




Monday, January 17, 2011
m p        e          d e
                                 sta        am         c o
                               e          N         rip
                           T im                    T




Monday, January 17, 2011
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
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
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
Chat
auto_link chat.content,
 :html=>{:target=>'_blank'}




Monday, January 17, 2011
Chat
auto_link chat.content,
 :html=>{:target=>'_blank'}



                           http://www.flickr.com/photos/lostvegas/2214183472/




Monday, January 17, 2011
Roll

                           4d6v + 40 =57 ((3+5+6+6-3)+40)
    <span class="code">
      <%=h roll.code %></span>
    <span class="result">
      <%=h roll.result %></span>
    <span class="description">
      <%=h roll.description %></span>

Monday, January 17, 2011
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
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
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
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
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
Dice Language
   4d6v                    + 3d10^   – 2d6 - 300




Monday, January 17, 2011
Dice Language
   4d6v                    + 3d10^ – 2d6 - 300
                              Expression



Monday, January 17, 2011
Dice Language
   4d6v                    + 3d10^   – 2d6 - 300




Monday, January 17, 2011
Dice Language
                           2d6 - 300




Monday, January 17, 2011
Dice Language
                              2d6 - 300
                           BinaryExpression



Monday, January 17, 2011
Dice Language
                           2d6 - 300




Monday, January 17, 2011
Dice Language
                           2d6
                                 -
                                     300
Monday, January 17, 2011
Dice Language
                           2d6             Series
                                 -
                                     300
Monday, January 17, 2011
Dice Language
                                  2d6             Series
                           Arithmetic   -
                                            300
Monday, January 17, 2011
Dice Language
                                  2d6             Series
                           Arithmetic   -
                             Constant       300
Monday, January 17, 2011
Dice Language
                           2d6
                                 -
                                     300
Monday, January 17, 2011
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
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
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
Ragel




Monday, January 17, 2011
Ragel
                           scan.rl: 62 lines




Monday, January 17, 2011
Ragel
                           scan.rl: 62 lines
                           scan.rb: 330 lines




Monday, January 17, 2011
Ragel
                           scan.rl: 62 lines
                           scan.rb: 330 lines
                           scan.pdf: priceless




Monday, January 17, 2011
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
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
Parsed Dice
  4d6v                     + 3d10^      - 2d6        - 300
  count: 4                  count: 3     count: 2     value: 300
  sides: 6                  sides: 10    sides: 6
  drop: ‘v’                 drop: ‘^’    drop: nil




Monday, January 17, 2011
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
Infix & Postfix




Monday, January 17, 2011
Infix & Postfix

                           Infix
                           1+2+3+4
                           Used for centuries
                           Hard for computers




Monday, January 17, 2011
Infix & Postfix

                           Infix                 Postfix
                           1+2+3+4              12+3+4+
                           Used for centuries   Easy for computers
                           Hard for computers   Convertible from infix




Monday, January 17, 2011
Parsed Dice
  4d6v                     + 3d10^      - 2d6        - 300
  count: 4                  count: 3     count: 2     value: 300
  sides: 6                  sides: 10    sides: 6
  drop: ‘v’                 drop: ‘^’    drop: nil




Monday, January 17, 2011
Postfixed Dice
  4d6v                     3d10^       + 2d6        - 300         -
  count: 4                 count: 3     count: 2     value: 300
  sides: 6                 sides: 10    sides: 6
  drop: ‘v’                drop: ‘^’    drop: nil




Monday, January 17, 2011
Postfix Evaluation




Monday, January 17, 2011
Postfix Evaluation

                           •Series




Monday, January 17, 2011
Postfix Evaluation

                           •Series
                            •Roll dice




Monday, January 17, 2011
Postfix Evaluation

                           •Series
                            •Roll dice
                            •Do drop




Monday, January 17, 2011
Postfix Evaluation

                           •Series
                            •Roll dice
                            •Do drop
                            •Push result to stack


Monday, January 17, 2011
Postfix Evaluation

                                                    •Constant
                           •Series
                            •Roll dice
                            •Do drop
                            •Push result to stack


Monday, January 17, 2011
Postfix Evaluation

                                                    •Constant
                           •Series
                                                     •Push value to stack
                            •Roll dice
                            •Do drop
                            •Push result to stack


Monday, January 17, 2011
Postfix Evaluation

                                                    •Constant
                           •Series
                                                     •Push value to stack
                            •Roll dice
                                                    •Arithmetic
                            •Do drop
                            •Push result to stack


Monday, January 17, 2011
Postfix Evaluation

                                                    •Constant
                           •Series
                                                     •Push value to stack
                            •Roll dice
                                                    •Arithmetic
                            •Do drop
                                                     •Pop twice
                            •Push result to stack


Monday, January 17, 2011
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
Postfix Evaluation
  4d6v                     3d10^       + 2d6        - 300         -
  count: 4                 count: 3     count: 2     value: 300
  sides: 6                 sides: 10    sides: 6
  drop: ‘v’                drop: ‘^’    drop: nil


   Stack



Monday, January 17, 2011
Postfix Evaluation
   15                      3d10^       + 2d6        - 300         -
                           count: 3     count: 2     value: 300
                           sides: 10    sides: 6
                           drop: ‘^’    drop: nil


   Stack



Monday, January 17, 2011
Postfix Evaluation
                           3d10^       + 2d6        - 300         -
                           count: 3     count: 2     value: 300
                           sides: 10    sides: 6
                           drop: ‘^’    drop: nil


   Stack

  15
Monday, January 17, 2011
Postfix Evaluation
                           5         + 2d6          - 300         -
                                        count: 2     value: 300
                                        sides: 6
                                        drop: nil


   Stack

  15
Monday, January 17, 2011
Postfix Evaluation
                                  + 2d6         - 300         -
                                    count: 2     value: 300
                                    sides: 6
                                    drop: nil


   Stack

  15 5
Monday, January 17, 2011
Postfix Evaluation
                                    2d6         - 300         -
                                    count: 2     value: 300
                                    sides: 6
                                    drop: nil


   Stack

  15 + 5
Monday, January 17, 2011
Postfix Evaluation
                                    2d6         - 300         -
                                    count: 2     value: 300
                                    sides: 6
                                    drop: nil


   Stack

  20
Monday, January 17, 2011
Postfix Evaluation
                                    9     - 300         -
                                           value: 300




   Stack

  20
Monday, January 17, 2011
Postfix Evaluation
                                          - 300         -
                                           value: 300




   Stack

  20 9
Monday, January 17, 2011
Postfix Evaluation
                                           300          -
                                           value: 300




   Stack

  20 - 9
Monday, January 17, 2011
Postfix Evaluation
                                           300          -
                                           value: 300




   Stack

  11
Monday, January 17, 2011
Postfix Evaluation
                                           300   -


   Stack

  11
Monday, January 17, 2011
Postfix Evaluation
                                               -


   Stack

  11 300
Monday, January 17, 2011
Postfix Evaluation




   Stack

  11 - 300
Monday, January 17, 2011
Postfix Evaluation




   Stack

  -289
Monday, January 17, 2011
Result


                           -289



Monday, January 17, 2011
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
Randomness

                           Computers are deterministic
                           Gather and store entropy where
                           possible
                           Use secure hashes to disburse entropy


Monday, January 17, 2011
Randomness

                           Just use
                           OpenSSL
Monday, January 17, 2011
SecureRandom

                           Ruby 1.9 and ActiveSupport
                                random_number
                                 random_bytes
                                      hex


Monday, January 17, 2011
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

Weitere ähnliche Inhalte

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Triskelion and Crapshoot

  • 1. Triskelion and Crapshoot Miami Ruby Brigade January 17, 2010 Monday, January 17, 2011
  • 2. 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
  • 3. Pen and Paper Games Pens Paper Talking Dice Snacks Books Monday, January 17, 2011
  • 4. Pen and Paper Games Pens Paper Talking Dice Snacks Books Monday, January 17, 2011
  • 7. m p sta e T im Monday, January 17, 2011
  • 8. m p e sta am e N T im Monday, January 17, 2011
  • 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
  • 14. Chat auto_link chat.content, :html=>{:target=>'_blank'} http://www.flickr.com/photos/lostvegas/2214183472/ Monday, January 17, 2011
  • 15. Roll 4d6v + 40 =57 ((3+5+6+6-3)+40) <span class="code"> <%=h roll.code %></span> <span class="result"> <%=h roll.result %></span> <span class="description"> <%=h roll.description %></span> 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
  • 24. Dice Language 2d6 - 300 Monday, January 17, 2011
  • 25. Dice Language 2d6 - 300 BinaryExpression Monday, January 17, 2011
  • 26. Dice Language 2d6 - 300 Monday, January 17, 2011
  • 27. Dice Language 2d6 - 300 Monday, January 17, 2011
  • 28. Dice Language 2d6 Series - 300 Monday, January 17, 2011
  • 29. Dice Language 2d6 Series Arithmetic - 300 Monday, January 17, 2011
  • 30. Dice Language 2d6 Series Arithmetic - Constant 300 Monday, January 17, 2011
  • 31. Dice Language 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
  • 36. Ragel scan.rl: 62 lines Monday, January 17, 2011
  • 37. Ragel scan.rl: 62 lines scan.rb: 330 lines Monday, January 17, 2011
  • 38. Ragel scan.rl: 62 lines scan.rb: 330 lines scan.pdf: priceless 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
  • 41. Parsed Dice 4d6v + 3d10^ - 2d6 - 300 count: 4 count: 3 count: 2 value: 300 sides: 6 sides: 10 sides: 6 drop: ‘v’ drop: ‘^’ drop: nil Monday, January 17, 2011
  • 42. 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
  • 43. Infix & Postfix Monday, January 17, 2011
  • 44. Infix & Postfix Infix 1+2+3+4 Used for centuries Hard for computers Monday, January 17, 2011
  • 45. Infix & Postfix Infix Postfix 1+2+3+4 12+3+4+ Used for centuries Easy for computers Hard for computers Convertible from infix Monday, January 17, 2011
  • 46. Parsed Dice 4d6v + 3d10^ - 2d6 - 300 count: 4 count: 3 count: 2 value: 300 sides: 6 sides: 10 sides: 6 drop: ‘v’ drop: ‘^’ drop: nil Monday, January 17, 2011
  • 47. Postfixed Dice 4d6v 3d10^ + 2d6 - 300 - count: 4 count: 3 count: 2 value: 300 sides: 6 sides: 10 sides: 6 drop: ‘v’ drop: ‘^’ drop: nil Monday, January 17, 2011
  • 49. Postfix Evaluation •Series Monday, January 17, 2011
  • 50. Postfix Evaluation •Series •Roll dice 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
  • 58. Postfix Evaluation 4d6v 3d10^ + 2d6 - 300 - count: 4 count: 3 count: 2 value: 300 sides: 6 sides: 10 sides: 6 drop: ‘v’ drop: ‘^’ drop: nil Stack Monday, January 17, 2011
  • 59. Postfix Evaluation 15 3d10^ + 2d6 - 300 - count: 3 count: 2 value: 300 sides: 10 sides: 6 drop: ‘^’ drop: nil Stack Monday, January 17, 2011
  • 60. Postfix Evaluation 3d10^ + 2d6 - 300 - count: 3 count: 2 value: 300 sides: 10 sides: 6 drop: ‘^’ drop: nil Stack 15 Monday, January 17, 2011
  • 61. Postfix Evaluation 5 + 2d6 - 300 - count: 2 value: 300 sides: 6 drop: nil Stack 15 Monday, January 17, 2011
  • 62. Postfix Evaluation + 2d6 - 300 - count: 2 value: 300 sides: 6 drop: nil Stack 15 5 Monday, January 17, 2011
  • 63. Postfix Evaluation 2d6 - 300 - count: 2 value: 300 sides: 6 drop: nil Stack 15 + 5 Monday, January 17, 2011
  • 64. Postfix Evaluation 2d6 - 300 - count: 2 value: 300 sides: 6 drop: nil Stack 20 Monday, January 17, 2011
  • 65. Postfix Evaluation 9 - 300 - value: 300 Stack 20 Monday, January 17, 2011
  • 66. Postfix Evaluation - 300 - value: 300 Stack 20 9 Monday, January 17, 2011
  • 67. Postfix Evaluation 300 - value: 300 Stack 20 - 9 Monday, January 17, 2011
  • 68. Postfix Evaluation 300 - value: 300 Stack 11 Monday, January 17, 2011
  • 69. Postfix Evaluation 300 - Stack 11 Monday, January 17, 2011
  • 70. Postfix Evaluation - Stack 11 300 Monday, January 17, 2011
  • 71. Postfix Evaluation Stack 11 - 300 Monday, January 17, 2011
  • 72. Postfix Evaluation Stack -289 Monday, January 17, 2011
  • 73. Result -289 Monday, January 17, 2011
  • 74. 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
  • 75. Randomness Computers are deterministic Gather and store entropy where possible Use secure hashes to disburse entropy Monday, January 17, 2011
  • 76. Randomness Just use OpenSSL Monday, January 17, 2011
  • 77. SecureRandom Ruby 1.9 and ActiveSupport random_number random_bytes hex Monday, January 17, 2011
  • 78. 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