Skip to content

Instantly share code, notes, and snippets.

View bstrie's full-sized avatar

bstrie bstrie

View GitHub Profile
fn compact<T>(x: &mut ~[T],
keep: |&T| -> bool) {
if x.len() == 0 {
return;
}
let mut kept = 0;
let mut finger = 0;
let mut last = x.len() - 1;
while finger <= last {
@magical
magical / gist:6878341
Created October 8, 2013 02:14
Pokemon level-up movepool sizes. The numbers on the left show the size of a pokemon's level-up moveset in the versions on the right. The last number is the product of those numbers. This is the cost (in both time and space) of performing an optimal multi-dimensional sequence alignment.
Bulbasaur
9 RBY
11 GSCRSECoXDFRLG
14 DPPtHGSSBWB2W2
1386
Ivysaur
10 RBY
13 GSCRSECoXDFRLG
16 DPPtHGSSBWB2W2
use std::hashmap::HashMap;
fn main() {
// create a hashmap
let mut hm = HashMap::new();
hm.insert(~"foo", 10);
hm.insert(~"bar", 23);
hm.insert(~"baz", 99);
hm.insert(~"meh", 2);
hm.insert(~"muh", -13);
fn r̄ͬ̇ͦ̓u͗͗̅̐s̔̈́ͯ̄̓ͭ͋tͣͯͦ̂̃̆̓_̍͌̉̃l̆a͐̾̿̋̈́n̉ͬͥ́ͪ̊gͭ͛̾_́cͪͬ͑͂̈oͭͨ̊̋̓ͧm̌̿̐̿ͤ̆͐e̔̓̆ͭͨ̾̚s() {
println("ĭ̒̚tͧ̂͆ͫ̄ ̃ͬ͗̍̂c̈͒̊õ͑̓ͩͦ͒m̊͗̐̒esͩ͛!ͨ̀ͩ̀͆̄̚ ĭ̿̈̍̀ͮ͑tͦ͂̉̒̔̇ ̓co͛́̾ͤ̄̉͌m͂͆̀ͫe͛ͨ͌̇͆ͣͥs͂!̇̌̎̆");
}
fn main() {
r̄ͬ̇ͦ̓u͗͗̅̐s̔̈́ͯ̄̓ͭ͋tͣͯͦ̂̃̆̓_̍͌̉̃l̆a͐̾̿̋̈́n̉ͬͥ́ͪ̊gͭ͛̾_́cͪͬ͑͂̈oͭͨ̊̋̓ͧm̌̿̐̿ͤ̆͐e̔̓̆ͭͨ̾̚s();
}
@bstrie
bstrie / 1.c
Last active December 15, 2015 17:29
Nontrivial Lua binding from Rust, with C equivalent.
#include <stdio.h>
#include <stdlib.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int main()
{
lua_State *L = luaL_newstate();
anonymous
anonymous / RustSyntaxProposal
Created March 18, 2013 16:33
Proposal for new syntax for type definition. Motivation: Rust tries to mix concepts from Functional languages with syntax from C/C++. structs (records) are equivalent to the C/C++ version. However enums in rust do not behave like enums from c: Enums in rust are used to define Algebraic Data Types (sum types) that act similar to 'tagged unions' i…
type Name = {
first: ~str,
last: ~str
}
type Shape = Circle(int) | Rect(int, int) // Variants with constructors
type Direction = North | South | East | West // without constructors
@tuchida
tuchida / brainfuck.js
Created March 11, 2013 14:49
Brainfuck in sweet.js
macro bf {
case ($body ...) => {
eval('var p = 0, b = [], buf = new Buffer(1);');
_bf($body ...);
}
}
macro _bf {
case (>) => {
eval('p++;');
}
Go Rust
----------- ------
break break
case (syntax)
chan (library)
const const
continue loop
default (syntax)
defer
else else
fn main() {
run_command("ls");
run_command("ls -l");
run_command("ls -l -a");
run_command("lua LoadGen.lua style=pointer_rust -spec=gl -version=3.3 \
-profile=core core_3_3");
}
fn run_command(command: &str) -> int {
let split = command.split_char(' ');
#!/bin/bash
DIR="$PWD"
while [[ "$DIR" != "/" && "$DIR" != "$HOME" ]]; do
if [[ -r "$DIR/src/libsyntax/syntax.rc" ]]; then
echo "$DIR"
exit 0
fi
DIR=$(dirname "$DIR")
done