This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Devectorize | |
macro makeiter(func, name) | |
expr = quote | |
immutable $name{X} | |
x::X | |
end | |
Base.start(i::$name) = start(i.x) | |
Base.next(i::$name, s) = ((v, s) = next(i.x, s); ($func(v), s)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Copyright (C) 2013 Google Inc. All Rights Reserved. | |
Licensed under the Apache License, Version 2.0 (the "License"); | |
you may not use this file except in compliance with the License. | |
You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 | |
Unless required by applicable law or agreed to in writing, software |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
__author__ = 'Adam R. Smith (adam@adamia.com)' | |
# Loop from 0 through 99. Need zero-based for the later cyclic bit-shifting. | |
for x in xrange(100): | |
# There are 4 possible outputs on each iteration of the loop. | |
# 4 possibilities requires 2 bits to store (0, 1, 2, 3): | |
# 0 == 00b == the number (x + 1) | |
# 1 == 01b == 'Fizz' when a multiple of just 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
VERSION="0.3.0" | |
URL="http://status.julialang.org/download/osx10.7+" | |
APP="/Applications/Julia-$VERSION-prerelease.app" | |
echo "Downloading Julia v$VERSION nightly..." | |
dmg="/tmp/julia-v$VERSION-installer.dmg" | |
curl -fsSL "$URL" > "$dmg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mark a function argument of any type as optional by generating a Union. | |
# If a default value is not defined, it assumes "nothing". | |
# | |
# Examples: | |
# function(x::Int, @maybe y::MyType) | |
# function(x::Int, @maybe y::MyType=someval) | |
macro maybe(argexpr) | |
default = :nothing | |
if argexpr.head == :(=) | |
argexpr, default = argexpr.args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Udacity Video Auto-Expand | |
// @namespace http://about.me/adam.r.smith | |
// @version 1.0 | |
// @description Make Udacity videos automatically fill the page. Handy with Chromecast/Airplay. | |
// @match https://www.udacity.com/course/viewer | |
// @copyright 2014+, http://about.me/adam.r.smith | |
// ==/UserScript== | |
var w = 1280, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Patch bitey to auto-generate struct member names with exuberant ctags.""" | |
__author__ = 'adam@adamia.com (Adam R. Smith)' | |
from collections import OrderedDict | |
import logging as log | |
import os | |
import subprocess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 'Adam R. Smith' | |
class IDPool(object): | |
''' | |
Create a pool of IDs to allow reuse. The "new_id" function generates the next | |
valid ID from the previous one. If not given, defaults to incrementing an integer. | |
''' | |
def __init__(self, new_id=None): | |
if new_id is None: new_id = lambda x: x + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import redis | |
from contextlib import contextmanager | |
@contextmanager | |
def redisLock(r, key): | |
''' | |
Acquire a lock on a particular key (makes a new mutex key). | |
This is not meant for very high concurrency, just to avoid | |
data corruption in simple cases. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @preserve | |
* | |
* Javascript Hill Climb Algorithm. | |
* @author Adam R. Smith http://codi.st/ | |
* | |
* Licensed under the new BSD License: | |
* http://www.opensource.org/licenses/bsd-license.php | |
*/ |
NewerOlder