Skip to content

Instantly share code, notes, and snippets.

View practicingruby's full-sized avatar

Gregory Brown practicingruby

View GitHub Profile
class Proxy
def initialize(document, style)
@document = document
@style = style
end
def text(string, params)
params[:size] ||= @style[:font_size]
params[:color] ||= @style[:font_color]
Start every day coding, end every day thinking.
1. Warmup exercise (30 mins)
Make sure to have these ready the night before, pick stuff
that you can work on right away without having to study
in advance.
They can either be book exercises or stuff
from other sources, but they should be self-verifiable
this_is.a_really_really.really.really.really.really.really.really
.long.method_chain # continuation of the line above
this.is_some +
math.split_across_lines
this(is: "some",
keyword_args: "across lines")
# Defines a parser roughly equivalent to the regular expression
# pattern /(a|c)*abb/
#
# To try it out, run the following commands:
#
# $ gem install racc
# $ racc parser_example.y -o parser
# $ ruby parser abb
# $ ruby parser acccaaaabb
# $ ruby parser zaaa
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;
class Parser
rule
string
| a_or_cs abb
| abb
;
a_or_cs
: a_or_cs a_or_c
| a_or_c
;

From http://www.cse.ohio-state.edu/~neelam/courses/788/lwb.pdf

A type specification contains the following information:

  • The type's name
  • A description of the type's value space
  • For each of the type's methods:
    • its name
    • its signature (including signalled exceptions)
  • its behavior in terms of preconditions and postconditions
MODES = { "0" => "---",
"1" => "--x",
"2" => "-w-",
"3" => "-wx",
"4" => "r--",
"5" => "r-x",
"6" => "rw-",
"7" => "rwx" }
def permissions(num)

There's no general rule you can follow here, because it's always going to depend on context. In my experience the kind of feedback loops you create, and the kind of safety nets you need are defined entirely by the domain, the organization, and the team culture.

Here are a few examples:

  1. I do a bit of work for a medium-sized dental clinic. The business manager there is really fun to work with, but has the tendency of changing his mind six times before he settles his ideas. So when he asks for a report, I don't put any effort at all into writing tests or worrying about minor bugs even, because my only goal is to flesh out in code something vaguely resembling what he asked for.

Often times, this means doing a handful of 30 minute prototypes until the requirements settle, each of which would have taken me 2 hours if I drove them via TDD. When things finally cool down, I evaluate the complexity and maintainability of the resulting code and either leave it untested, add some acceptance tests, backfill unit tes

A LALR parser is a parser that:

  • Parses text in a single direction. Backtracking is avoided by looking ahead in the input stream before deciding how to parse a single token. (LA = Look-ahead)

  • Parses text starting from the left-most side of the input stream. (L=Left-to-right input processing)

  • Builds a parse-tree from the bottom up by repeatedly attempting to match