Skip to content

Instantly share code, notes, and snippets.

View eddyb's full-sized avatar

Eduard-Mihai Burtescu eddyb

View GitHub Profile
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 / combinator.rs
Last active December 26, 2015 20:52 — forked from btipling/combinator.rs
fn main() {
fn map<F, T, A>(option: Option<T>, f: F)
-> Option<A>
where F: FnOnce(T) -> A {
match option {
None => None,
Some(value) => Some(f(value)),
}
@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)
@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>
@eddyb
eddyb / gist:4298842
Created December 15, 2012 20:16 — forked from Dav1dde/bridge.lua
function refuel()
if turtle.getFuelLevel() > 10 then
return true
end
for i=1,16 do
turtle.select(i)
if turtle.refuel() then
return true
end
@eddyb
eddyb / filter.js
Created December 15, 2012 18:22 — forked from anonymous/gist:4297815
'183-559160438423-354467135967-54671620\n\
84-113162777230260820483516--75476325641492692197865144648927723647584\n\
65-2565125015350753326712-3274761771-0\n\
516-526032531125-3333251474747-37475320\n\
31-0526-765730-6176261251677772576501\n\
532-52270754776507777271212563371151676553776-61557505576700-73702\n\
576-65715057275-62116571-07710267775\n\
53-5656327-7-627720\n\
73-753612736572575747-763150335-32'.split('\n').forEach(function(x) {
var hex = x.split('-').map(function(x) {