Skip to content

Instantly share code, notes, and snippets.

View killerswan's full-sized avatar

Kevin Cantú killerswan

View GitHub Profile
@killerswan
killerswan / gist:1258000
Created October 2, 2011 21:40 — forked from swannodette/gist:1257981
redblacknew.cljs
(defn balance [node]
(match [node]
[( [:black [:red [:red a x b] y c] z d]
| [:black [:red a x [:red b y c]] z d]
| [:black a x [:red [:red b y c] z d]]
| [:black a x [:red b y [:red c z d]]]
)]
[:red [:black a x b] y [:black c z d]]
:else
node))
@killerswan
killerswan / gist:1327136
Created October 31, 2011 08:46
averages of a list of numbers
import Control.Arrow
import Control.Applicative
import Control.Monad.Instances
import Data.List (genericLength)
import Data.Foldable
import Data.Function
avg_fold xs =
@killerswan
killerswan / gist:1346107
Created November 7, 2011 20:40
awk one liner
awk '/.*7fff.*/{print $4 " " $6}'
@killerswan
killerswan / files.hs
Created December 1, 2011 06:12
filesystem manipulation in Haskell
import System.Cmd
import System.FilePath.Posix
import System.IO.HVFS
import System.IO.HVFS.Utils
copyFiles :: String -- prefix
-> FilePath -- destination dir
-> [FilePath] -- files to copy
-> IO ()
@killerswan
killerswan / gist:1533252
Created December 29, 2011 09:45
Rust function syntax
// Kevin Cantu
// December 2011
/*
fn sendfn lambda block
closures no immutable immutable mutable
keyword def yes no no no e.g., fn xyz () {...}
@killerswan
killerswan / gist:1533530
Created December 29, 2011 11:00
Rust function types
// Kevin Cantu
// December 2011
// why do the types, fn(), sendfn(), lambda(), and block() require parens?
// why isn't there a way to name a block?
// why isn't there a top level equivalent to fn for each of the others?
use std;
@killerswan
killerswan / gist:1533812
Created December 29, 2011 12:16
sendfn related syntax segfault (816b0ac)
use std;
fn usingSendfn ( f : sendfn() ) {
f();
}
fn main (args: [str]) {
usingSendfn ({|| std::io::println ("this is block syntax..."); }); // segfault
}
@killerswan
killerswan / rr.bash
Created December 30, 2011 06:59
like runhaskell, but for rust
#!/bin/bash
# runrust: compile and run rust source code
#
# Kevin Cantu (c) 2011 ==> free use and modification, no warranty, enjoy!
if [[ ! "${1#*.}" == "rs" ]]
then
ME="$(basename "$0")"
echo "Usage: $ME rust-source-file.rs"
exit 1
@killerswan
killerswan / gist:1539396
Created December 30, 2011 11:25
Rust functions (test script)
// Kevin Cantu
// basic Rust function behavior
/*
fn sendfn lambda block
closures no immutable immutable mutable
keyword def yes no no no e.g., fn xyz () {...}
@killerswan
killerswan / gist:1563980
Created January 5, 2012 06:15
a #[test] involving an unsafe function
use std;
use vec2;
// OK this both compiles and works as expected!
// BEFORE(aa): [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]
// AFTER (dd): [0x04030201, 0x08070605]
// compare with libstd/io.rs at 77-84 (fn read())
#[test]