Skip to content

Instantly share code, notes, and snippets.

Adam R. Smith sunetos

Block or report user

Report or block sunetos

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sunetos
sunetos / iterize.jl
Last active Aug 29, 2015
Julia macro to generate iterator versions of collection functions
View iterize.jl
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))
@sunetos
sunetos / duke-cc.js
Created Aug 2, 2014
Duke Chromecast Test
View duke-cc.js
/**
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
@sunetos
sunetos / fizzbuzz_explained.py
Last active May 27, 2017
A breakdown of my condensed, obfuscated fizzbuzz for educational purposes
View fizzbuzz_explained.py
#!/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
@sunetos
sunetos / update-julia
Created May 22, 2014
Update to latest Julia nightly on a Mac
View update-julia
#!/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"
@sunetos
sunetos / maybe.jl
Last active Aug 29, 2015
Julia macro for typed optional function arguments
View maybe.jl
# 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
@sunetos
sunetos / udacity-video-expand.js
Last active Aug 29, 2015
Udacity Video Auto-Expand
View udacity-video-expand.js
// ==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,
@sunetos
sunetos / bitey_struct.py
Created Nov 4, 2012
Bitey Autogeneration of Struct Member Names with Ctags
View bitey_struct.py
#!/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
@sunetos
sunetos / gist:1068329
Created Jul 6, 2011
Simple Python ID Allocation Pool
View gist:1068329
__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
View redis-list-index.py
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.
'''
View hillclimb.js
/**
* @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
*/
You can’t perform that action at this time.