Skip to content

Instantly share code, notes, and snippets.

@zaphod42
zaphod42 / expr.pl
Created August 7, 2011 12:27
Perl 6 expression parser
grammar Expr {
token number { \d+ {*} }
token operator { <op> {*} }
proto token op { <...> }
token op:sym<+> { <sym> }
token op:sym<-> { <sym> }
token op:sym<*> { <sym> }
token op:sym</> { <sym> }
@zaphod42
zaphod42 / gist:1130455
Created August 7, 2011 15:24
Simple S-Expr to Perl 6 compiler
grammar Scheme {
rule TOP { ^ <program> $ {*} }
rule program { <s_expression>* {*} }
rule s_expression {
<number>
| <ident>
| <cons_list>
{*}
}
@zaphod42
zaphod42 / Gemfile.noFeatures
Created August 2, 2012 16:45
An example, flexible Gemfile for puppet
source :rubygems
facter_location = ENV['PUPPET_FACTER']
def type_of(location)
case location
when /github/
:git
else
:path
@zaphod42
zaphod42 / gist:4051853
Created November 10, 2012 17:32
Solution to the coin changer kata
class Object
def when_defined(primary, alternate)
primary.call(self)
end
end
class NilClass
def when_defined(primary, alternate)
alternate.call(self)
end
def lookupvar(name, options = {})
unless name.is_a? String
raise Puppet::DevError, "Scope variable name is a #{name.class}, not a string"
end
table = ephemeral?(name) ? @ephemeral.last : @symtable
if name =~ /^(.*)::(.+)$/
class_name = $1
variable_name = $2
Notice: BENCHMARK: Setup server facts for compiling in 0.02 seconds
Notice: BENCHMARK: Found facts in 0.07 seconds
Info: Caching node for aparker
Notice: BENCHMARK: Found node information in 0.01 seconds
Notice: BENCHMARK: Compile: Set node parameters in 0.00 seconds
Notice: BENCHMARK: Compile: Created settings scope in 0.01 seconds
Notice: BENCHMARK: Compile: Evaluated main in 0.00 seconds
Warning: Host is missing hostname and/or domain: aparker
Notice: BENCHMARK: Compile: Evaluated AST node in 0.02 seconds
Notice: BENCHMARK: Compile: Evaluated node classes in 0.00 seconds
Debug: 1.1 [Request] Setup server facts for compiling in 0.0072 seconds
Debug: 1.2 [Request] Found facts in 0.0043 seconds
Info: Caching node for aparker.guest.youdevise.com
Debug: 1.3 [Request] Found node information in 0.0061 seconds
Debug: 1.4.1 [Request] Compile: Set node parameters in 0.0004 seconds
Debug: 1.4.2 [Request] Compile: Created settings scope in 0.0149 seconds
Debug: 1.4.3 [Request] Compile: Evaluated main in 0.0003 seconds
Debug: 1.4.4 [Request] Compile: Evaluated AST node in 0.0238 seconds
Debug: 1.4.5 [Request] Compile: Evaluated node classes in 0.0000 seconds
Debug: 1.4.6.1.1.1 [Request] Evaluated resource Foo[testing] in 0.0004 seconds
hierarchy:
- name: node
locator: %{certname}
backend: local_yaml
- name: dc
backend: zookeeper
- name: common
locator: common
backend: local_yaml
> bundle exec puppet apply t.pp
Notice: Scope(Class[Foo]): Class: foo
Notice: Scope(Class[Foo]): Module:
Notice: Scope(Class[Foo]): Module Orig: foo
Notice: Scope(Class[Foo]): Module Alias:
Notice: Scope(Class[Foo]): Module Puppet:
Notice: Scope(Class[Foo::Bar]): Class: foo::bar
Notice: Scope(Class[Foo::Bar]): Module:
Notice: Scope(Class[Foo::Bar]): Module Orig: foo
Notice: Scope(Class[Foo::Bar]): Module Alias:
@zaphod42
zaphod42 / hello-world.hs
Created May 10, 2013 23:52
Learning Haskell and OpenGL at the same time.
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Data.IORef
main :: IO ()
main = do
(progname, _) <- getArgsAndInitialize
createWindow "Hello World"
angle <- newIORef 0.0
displayCallback $= display angle