Skip to content

Instantly share code, notes, and snippets.

@zah
zah / gist:1232112
Created September 21, 2011 14:05
Forwarding references
type Connection = object
userName: string
messageHistory: list[string]
type ConnectionManager = object
networkConnections: map[string, Connection]
const
NULL_CONNECTION : Connection = ...
macro foo(s: stmt) =
result = ast:
echo [. s[1] .]
@zah
zah / gist:1273686
Created October 9, 2011 13:27
Text blocks (for embedded languages)
x = xml ::
<item>
<field>
</field>
</item>
scanner = ragel ::
action dgt { printf("DGT: %c\n", fc); }
action dec { printf("DEC: .\n"); }
action exp { printf("EXP: %c\n", fc); }
@zah
zah / chef-standalone-bootstrap.sh
Created October 15, 2011 16:29 — forked from sometimesfood/chef-standalone-bootstrap.sh
Chef standalone bootstrap with chef-admin-essentials
#!/bin/bash
sudo apt-get install curl git-core lsb-release
bash < <( curl -sL https://raw.github.com/sometimesfood/chef-admin-essentials/master/contrib/install-chef.sh )
mkdir ~/cookbooks
cd ~/cookbooks
echo '*~' > .gitignore
git init
git add .
git commit -am 'Initial commit'
git submodule add git://github.com/sometimesfood/chef-admin-essentials.git admin-essentials
@zah
zah / gist:1290725
Created October 16, 2011 10:03
Install Chef
#!/bin/bash
sudo apt-get install ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential wget ssl-cert curl
sudo gem install chef --no-ri --no-rdoc
@zah
zah / gist:1339159
Created November 4, 2011 11:38
New closure syntax
new closure syntax:
do (formal args): block
# passing a closure as a last argument of a nkCall or nkCommand
command "Foo" do (args: string):
code
code
code
btn.click do (e: TClickEvent):
template openFile: expr =
var x: File
type `%dummy` = object
f: File
var `%d` = `%dummy`(x)
proc destroy(x: `%dummy`) =
callAtExitCode x.f
@zah
zah / os_proc.c
Created November 20, 2011 22:14
os_proc.asm
N_NIMCALL(TY77202*, Startcmd_77238)(NimStringDesc* Command_77240, NU8 Options_77243) {TY77202* Result_77244;TY45613* C_77245;TY45613* A_77247;NI I_77287;NI HEX3Atmp_77288;NI Res_77290;Result_77244 = 0;C_77245 = 0;
#line 80 "/Volumes/home/zahary/Projects/nim/lib/pure/osproc.nim"
C_77245 = nosparseCmdLine(Command_77240);A_77247 = 0;
#line 82 "/Volumes/home/zahary/Projects/nim/lib/pure/osproc.nim"
A_77247 = (TY45613*) newSeq(NTI45613, (NI64)(C_77245->Sup.len - 1));I_77287 = 0;HEX3Atmp_77288 = 0;
#line 83 "/Volumes/home/zahary/Projects/nim/lib/pure/osproc.nim"
HEX3Atmp_77288 = (NI64)(C_77245->Sup.len - 1);Res_77290 = 0;
#line 1154 "/Volumes/home/zahary/Projects/nim/lib/system.nim"
Res_77290 = 1;
#line 1155 "/Volumes/home/zahary/Projects/nim/lib/system.nim"
@zah
zah / gist:1392058
Created November 24, 2011 19:23
The case for Option[T]
# Option[T] and safe navigation:
# Some languages have a specialized syntax for what is usually called "safe navigation"
foo?.bar[10]?.baz
# Option[T] could be implemented as a proxy type that rewrites any operation on it
# as a operation applied to the stored value (if there is any)
# The original example then becomes:
Option(foo).bar[10].baz # returns Option[type(baz)]
# Another point to note: proxy types used in this fashion are pretty much equivalent to Haskell's monads
@zah
zah / let.nimrod
Created December 1, 2011 14:55
Let - first tests
type
TBar = object
f: int
TFoo = object
str: string
sq: seq[string]
bar: TBar
proc makeFoo: TFoo =