Skip to content

Instantly share code, notes, and snippets.

import random
def r_step_generator(lo, hi):
num = lo
diff = hi - lo
while True:
num += random.randint(0, diff) #Feel free to swtich for numpy.random.randint for speed boost
if num < hi:
yield num
else:
import numpy.random as nprnd
from time import clock
def r_step_generator(lo, hi):
num = lo
diff = hi - lo
while True:
num += nprnd.randint(0, diff)
if num < hi:
yield num
@reem
reem / gist:7092920
Created October 21, 2013 23:54
vim 7.4a error
Error detected while processing function pymode#Option:
line 8:
E121: Undefined variable: g:pymode_syntax
E121: Undefined variable: g:pymode_doc
E121: Undefined variable: g:pymode_lint
E121: Undefined variable: g:pymode_rope
E121: Undefined variable: g:pymode_run
E121: Undefined variable: g:pymode_breakpoint
E121: Undefined variable: g:pymode_folding
Error detected while processing /Users/Jonathan/.spf13-vim-3/.vim/bundle/python-mode/after/ftplugin/
@reem
reem / main.js
Created April 29, 2014 17:12
Famous Blurry Text in Scrollview
/*globals define*/
define(function(require, exports, module) {
'use strict';
// import dependencies
var Engine = require('famous/core/Engine');
var Surface = require('famous/core/Surface');
var Scrollview = require('famous/views/Scrollview');
var StateModifier = require('famous/modifiers/StateModifier');
var ViewSequence = require('famous/core/ViewSequence');
@reem
reem / -
Created April 30, 2014 02:15
var compose = function(f, g) { return function(x) { return f(g(x)); }; };
fn main() {
#[deriving(Show)]
struct Foo {
a: i32
}
let mut test:Vec<Foo> = Vec::new();
test.push(Foo { a: 1 });
test.push(Foo { a: 3 });
test.push(Foo { a: 2 });
// Works:
fn sum<T: Zero>(list: &Vec<T>) -> T {
list.iter().fold(Zero::zero(), |a: T, b| a + *b)
}
// Does not work:
// Gives a move error on &b saying you are trying to move out
// of a dereference of an &-pointer.
fn sum<T: Zero>(list: &Vec<T>) -> T {
list.iter().fold(Zero::zero(), |a: T, &b| a + b)
#![feature(phase, macro_rules)]
extern crate regex;
#[phase(plugin)] extern crate regex_macros;
macro_rules! matching(
($($a:tt),+) => (
regex!(concat!("^", glob_to_regex!($($a))+, "$"))
);
)
let isAbsoluteUri = match req.request_uri {
AbsolutePath(_) => true,
_ => false
};
if isAbsoluteUri {
match req.request_uri {
AbsolutePath(ref mut path) => {
*path = path.as_slice().slice_from(self.route.len()).to_string();
},
use std::any::{Any, AnyRefExt, AnyMutRefExt};
use std::intrinsics::TypeId;
use std::collections::HashMap;
/// A map which can contain one value of any type and is keyed by types.
///
/// Values must implement the `Any` trait.
pub struct TypeMap {
map: HashMap<TypeId, Box<Any>>
}