Skip to content

Instantly share code, notes, and snippets.

View simonask's full-sized avatar

Simon Ask Ulsnes simonask

View GitHub Profile
child: fork()
if !child
// this is the child process
while true
message: Process.message_queue.get_next()
// do something with the message
end
else
// this is the mother process
scope_ext: Object.new()
scope_ext.lol: 123
foo: {
puts(lol)
}
foo.inject_scope(scope_ext)
foo() // => "123"
/*
Why we need Continuations in Snow
*/
ArticleController: controller {
.index: {
articles: Article.find(#all)
render(articles)
}
a: 0
result: try {
8 / a
}
if result.error
// DivisionByZeroException, handle it...
else
puts(result.value)
add: [a, b] {
a + b
}
b: add(4, c)
c: add(5, 6)
sideeffect puts(c)
sideeffect puts(muh)
Foo: class {
get_stuff: { /* do it */ }
.property(#stuff, get_stuff, nil)
}
foo: Foo.new()
foo.stuff // => get_stuff()
foo.stuff: 2 // => ERROR
require("dlopen")
Something: module {
lib: dlopen("libsomething.dylib")
.foo: lib.symbol("foo", INT, POINTER)
.bar: lib.symbol("bar", POINTER)
}
ptr: Something.bar()
#include <stdio.h>
#include <dlfcn.h>
extern "C" int foo() {
puts("LOOOOOL");
}
int main() {
void* handle = dlopen(NULL, RTLD_NOW);
int(*my_foo)() = dlsym(handle, "foo");
template <typename T> class Delegate;
template <typaname T> class DelegateFunction;
// Specialization for 2-argument callbacks:
template <typename C, typename R, typename A1, typename A2>
class DelegateMemberFunction : public DelegateFunction<R, A1, A2> {
private:
C* m_Instance;
R (*m_Function)(A1, A2);
public:
xml: XmlBuilder()
xml {
.root {
.element1(attr: "hej") {
.cdata("MUUUUH")
}
.element2(whatever: "lals") {
.cdata("...")
}