Skip to content

Instantly share code, notes, and snippets.

View arwagner's full-sized avatar

Andrew Wagner arwagner

  • Northern Virginia
View GitHub Profile
@arwagner
arwagner / _.md
Created January 18, 2013 20:51 — forked from enjalot/inlet.js
just another inlet to tributary
@arwagner
arwagner / _.md
Created January 18, 2013 16:07 — forked from anonymous/config.json
An inlet to Tributary
public static Sprite fromSpriteSheet(String path, int totalWidth, int width, int height, int x, int y) throws IOException{
BufferedImage target = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
int[] pixels = ((DataBufferInt)target.getRaster().getDataBuffer()).getData();
BufferedImage source = ImageIO.read(Sprite.class.getResource(path));
int[] sourcePixels = ((DataBufferInt)source.getRaster().getDataBuffer()).getData();
for (int i = 0; i < width; i++){
for (int j = 0; j < height; j++){
pixels[width * j + i] = sourcePixels[totalWidth * y + x + i];
@arwagner
arwagner / gist:3927048
Created October 21, 2012 14:01
Bitwise vs. division benchmark
public class Main {
static final int CALCULATIONS_PER_TRIAL = 10000000;
static final int TRIALS_PER_RUN = 100;
public static void main(String[] args) throws InterruptedException{
int bitwiseWins = 0;
for (int trial = 0; trial < TRIALS_PER_RUN; trial++){
long modulusStart = System.nanoTime();
for (int calculation = 0; calculation < TRIALS_PER_RUN; calculation++){
@arwagner
arwagner / gist:3768353
Created September 23, 2012 00:30
observer
require 'observer'
class Target
include Observable
end
class Watcher
def initialize target
target.add_observer self
end
class Changes < Actor
out :timeline_tweets_out
takes :tweets_in, :friends_in
def before
@friends = @friends_in.pop
end
def pump
tweet = @tweets_in.pop
@arwagner
arwagner / gist:2629362
Created May 7, 2012 18:06
Problem with native extensions
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/Users/andrewwagner/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for libxml/parser.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
@arwagner
arwagner / gist:2202072
Created March 26, 2012 01:28
Recumbent bicycles
class Recumbent < Bicycle
attr_reader :flag
def post_initialize(args)
@flat = args[:flag]
end
def local_spares
{flag: flag}
end
@arwagner
arwagner / gist:1479246
Created December 15, 2011 00:23
default parameter value
(defn f
([x] (f x 1))
([x y]
( ... )))
@arwagner
arwagner / gist:1479137
Created December 14, 2011 23:42
understanding the output of prn
user=> (for [[x y] (seq {'a 1 'b 2})] (prn x))
(a
b
nil nil)
user=>