Skip to content

Instantly share code, notes, and snippets.

View eddyb's full-sized avatar

Eduard-Mihai Burtescu eddyb

View GitHub Profile
@eddyb
eddyb / gist:7640491
Created November 25, 2013 12:22 — forked from cnd/gist:7640445
let (ref cfg, ref appCfg) = if nix {
( Path::new ( "~/.Sync.conf" ) ,
Path::new ( "~/.Mirana.conf" )
)
} else {
let prefix = getenv("HOME").unwrap_or(~"");
( Path::new ( prefix + "~/.Sync.conf" ),
Path::new ( prefix + "~/.Mirana.conf" )
)
};
@eddyb
eddyb / parse.rs
Last active December 28, 2015 23:49 — forked from tiffany352/parse.rs
use std::str::*;
use std::hashmap::*;
trait CloneParser<T> {
fn clone_as_parser(&self) -> ~Parser<T>;
}
impl<T, U: Clone> CloneParser<T> for U {
fn clone_as(&self) -> ~Parser<T> {
~self.clone() as ~Parser<T>
struct Foo(uint);
fn main() {
enum Bar { Baz(Foo) };
let x = Baz(Foo(4));
fn foo(_bar: uint) -> Foo { Foo(3) }
match x {
Baz(foo(x)) => println!("{:?}", x)
};
@eddyb
eddyb / btree.rs
Created October 28, 2013 16:07 — forked from niftynif/gist:7199643
//
// btree.rs
// Nif Ward
// 10/24/13
//
// starting implementation of a btree for rust
// inspired by github user davidhalperin's gist
//What's in a BTree?
@eddyb
eddyb / gist:5755552
Last active December 18, 2015 08:39 — forked from BrendanEich/gist:5753666
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
@eddyb
eddyb / converter.js
Last active December 17, 2015 18:19 — forked from Dinnerbone/gist:5631634
var flatten = x => x.reduce((a, b) => a.concat(b));
function transform(x) {
if(typeof x === 'string')
return [x];
var {color, italic, translate, using, text} = x;
if(color)
return [['c', color, ...transform({italic, translate, using, text})]];
if(italic)
return [['i', ...transform({translate, using, text})]];
if(translate)
'use strict';
$.Math = {};
global.$M = $.Math;
// Vector implementation - general and slow. Shouldn't use, except for matrixes.
$M.Vector = function Vector(elements) {
if(!(this instanceof $M.Vector))
return new $M.Vector(elements);
@eddyb
eddyb / a.js
Last active December 16, 2015 10:29 — forked from jeffmarshall/gist:5420414
function A() {
this.type = 'a'
}
module.exports = A;
var B = require('./b.js');
A.prototype.delete = function deleteA(callback) {
var self = this;
Imports {
Import KERNEL32.dll_GlobalGetAtomNameA(ATOM,LPSTR,INT)@0x455080
Import KERNEL32.dll_GlobalDeleteAtom(ATOM)@0x455084
Import KERNEL32.dll_lstrlenA(LPCSTR)@0x455088
Import KERNEL32.dll_lstrcpyA(LPSTR,LPCSTR)@0x45508c
Import KERNEL32.dll_GetProfileStringA(LPCSTR,LPCSTR,LPCSTR,LPSTR,UINT)@0x455090
Import KERNEL32.dll_GetModuleHandleA(LPCSTR)@0x455094
Import KERNEL32.dll_LocalAlloc(UINT,SIZE_T)@0x455098
Import KERNEL32.dll_GlobalAddAtomA(LPCSTR)@0x45509c
Import KERNEL32.dll_LocalFree(HLOCAL)@0x4550a0
/// <summary>
/// Prompt the user to take a photograph to scan for a barcode.
/// </summary>
/// <param name="callBack">Method to invoke with the scan results.</param>
public void ScanCode(Action<IBarcodeResult> callBack) {
WP7BarcodeManager.ScanBarcode(ProcessBarcode);
_callBack = callBack;
}
/// <summary>