Skip to content

Instantly share code, notes, and snippets.

@bmcorser
bmcorser / throttle.js
Last active August 29, 2015 14:08
Throttle $.ajax calls
define(['jquery'], function ($) {
var THROTTLE = 200; // ms
var previousCalls = {}; // for namespaces
var throttle = function (name, ajaxOpts) {
var now = new Date();
previousCalls[name] = now;
@bmcorser
bmcorser / gist:c1cf4d30cc51c604baba
Created December 2, 2014 17:11
`set` vs `dict`
from operator import itemgetter
data = [
{'id': 1},
{'id': 2},
{'id': 3},
{'id': 4},
]
// user lands
mixpanel.track('<event name>', {})
// user registers
mixpanel.alias('<user email>')
mixpanel.people.set({
// ...
})
mixpanel.identify('<user email>') // flush to mixpanel
import collections
import itertools
import hashlib
import json
import requests
import mixpanel # https://pypi.python.org/pypi/mixpanel-py/4.0.2
def get_mixpanel_datapoints():
url = 'https://data.mixpanel.com/api/2.0/export/'
params = {
git log --format=%H > git-log
shuf git-log > git-log-shuf
git rev-list --no-walk $(< git-log-shuf) > git-rev-list
diff git-log git-rev-list
pyenv virtualenv 2.7.8 pelicanfly-issues-11
pyenv activate pelicanfly-issues-11
pip install pelican markdown
mkdir site && cd site
pelican-quickstart
# ....
curl https://gist.githubusercontent.com/deepzeafish/0b35baa9989aed7b5295/raw/gistfile1.txt > pelicanconf.py
pip install pelicanfly pelican-gist
mkdir content
vim content/keyboard-review.md

I found understanding Rust types really confusing, so I wrote up a small tutorial for myself in an attempt to understand some of them. This is by no means exhaustive. There is a types section in the manual, but it has nowhere near enough examples.

I'm not talking about managed pointers (@) at all. A lot of the difficulty with Rust types is that the language is constantly changing, so this will likely be out of date soon.

First, a few preliminaries: it's easier to play with types if you have a REPL and can interactively check the types of objects. This isn't really possible in Rust, but there are workarounds.

To start out: some help

How to get a Rust REPL

select(0x1, 0x7FFF5E733240, 0x0, 0x7FFF5E7331C0, 0x0) = 1 0
read(0x0, "\0", 0x1000) = -1 Err#5
ioctl(0x0, 0x4004667A, 0x7FFF5E73325C) = 0 0
read(0x0, "\0", 0x1000) = -1 Err#5
ioctl(0x0, 0x4004667A, 0x7FFF5E73325C) = 0 0
<snip>
read(0x0, "\0", 0x1000) = -1 Err#5
ioctl(0x0, 0x4004667A, 0x7FFF5E73325C) = 0 0
read(0x0, "\0", 0x1000) = -1 Err#5
ioctl(0x0, 0x4004667A, 0x7FFF5E73325C) = 0 0
running: cargo build
Compiling git-tags-rs v0.1.0 (file:///Users/ben/work/git-tags-rs)
src/tag/release.rs:101:29: 101:39 error: unable to infer enough type information about `_`; type annotations or generic parameter binding required [E0282]
src/tag/release.rs:101 Err(err) => Result::Ok(()),
^~~~~~~~~~
note: in expansion of for loop expansion
src/tag/release.rs:98:9: 103:10 note: expansion site
src/tag/release.rs:101:29: 101:39 help: run `rustc --explain E0282` to see a detailed explanation
error: aborting due to previous error
Could not compile `git-tags-rs`.
extern crate git2;
extern crate rustc_serialize;
use std::collections::HashMap;
use std::io;
use std::io::prelude::*;
use std::thread;
use git2::{Repository, Oid};
use rustc_serialize::json::{self, ToJson, Json};