Skip to content

Instantly share code, notes, and snippets.

View derekchiang's full-sized avatar

Derek Chiang derekchiang

View GitHub Profile
#include <stdio.h>
// A generator that generates 0..10 infinitely
int generator(void) {
static int i, state = 0;
switch (state) {
case 0: goto LABEL0;
case 1: goto LABEL1;
}

I like Learn You a Haskell as a reference and cheat-sheet but I found it a little slow for learning Haskell.

Here's my recommended order for just learning Haskell:

http://yannesposito.com/Scratch/en/blog/Haskell-the-Hard-Way/ 80% completion here is fine if you feel your attention waning, the next thing will address hammering in things like functors and monads via typeclasses.

https://github.com/NICTA/course/ this will hammer in the lessons in a very direct form by forcing you to confront the challenges and lessons learned by the creators and community of Haskell itself. Doing the exercises here is critical for being fluent.

Real World Haskell is available online. (Thanks bos!)

@derekchiang
derekchiang / native_bench.rs
Created February 14, 2014 02:22
A benchmark of Rust libnative.
extern mod native;
extern mod extra;
extern mod sync;
use sync::mutex::{StaticMutex, MUTEX_INIT};
use std::os;
static mut LOCK: StaticMutex = MUTEX_INIT;
#[start]
fn start(argc: int, argv: **u8) -> int {
@derekchiang
derekchiang / green_bench.rs
Created February 14, 2014 02:20
A benchmark of Rust libgreen.
extern mod extra;
extern mod sync;
use sync::mutex::{StaticMutex, MUTEX_INIT};
use std::os;
static mut LOCK: StaticMutex = MUTEX_INIT;
fn work() {
for _ in range(0, 10000000) {
unsafe {
@derekchiang
derekchiang / split_owned_vec.rs
Created January 5, 2014 14:23
A Rust function for splitting an owned vector into two owned vectors.
fn split_owned_vec<T>(mut v: ~[T], index: uint) -> (~[T], ~[T]) {
assert!(index <= v.len());
let new_len = v.len() - index;
let mut new_v = vec::with_capacity(v.len() - index);
unsafe {
ptr::copy_nonoverlapping_memory(new_v.as_mut_ptr(), v.as_ptr().offset(index as int), new_len);
v.set_len(index);
new_v.set_len(new_len);
}
@derekchiang
derekchiang / json_example.rs
Created November 22, 2013 09:24
It's amazing how hard it is to get code to compile in Rust. This is the result of an hour-long struggle. It demonstrates one usage of `extra::json`. Hope it helps someone.
// Compile with rustc 0.9-pre (727b70d 2013-11-17 21:11:24 -0800)
#[feature(managed_boxes)];
extern mod extra;
use extra::json;
use std::io::stdio;
use extra::serialize::Encodable;
@derekchiang
derekchiang / simple-server.py
Created August 22, 2013 04:27
A script for serving static files from the current directory. Very handy.
#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
from argparse import ArgumentParser
import socket
parser = ArgumentParser(
description='Serve static files in the current directory.')
@derekchiang
derekchiang / get-erlang-deps.sh
Created June 5, 2013 06:34
Install all dependencies needed for compiling Erlang R16B from source.
# for erlang
apt-get install fop
apt-get install libncurses5-dev
apt-get install openjdk-7-jdk
apt-get install unixodbc-dev
apt-get install g++
apt-get install make
apt-get install libssl-dev
@derekchiang
derekchiang / basename.coffee
Created May 25, 2013 09:23
A little function that returns the basename of a filename.
baseName = (str) ->
base = new String(str).substring(str.lastIndexOf("/") + 1)
base = base.substring(0, base.lastIndexOf(".")) unless base.lastIndexOf(".") is -1
return base
@derekchiang
derekchiang / getExtension.coffee
Last active December 17, 2015 16:49
A simple function for getting the extension of a filename.
getExtension = (filename) ->
i = filename.lastIndexOf '.'
return if i < 0 then '' else filename.substr (i+1)