Skip to content

Instantly share code, notes, and snippets.

@tomelm
tomelm / gist:3334944
Created August 12, 2012 22:27
colors for skalnik!
#F18D05 - vibrant
#ED9936 - vibrant kind of muted
#192A44 - dark muted
#CBC5AF - light muted
#B1B9AC - light muted 2
#EFFFFF - light kind of muted kind of vibrant?
#334455 - dark muted
#FF4422 - vibrant kind of muted
@tomelm
tomelm / gist:3772915
Created September 23, 2012 20:16
rails presentation outline for skalnik
  • linux users make sure you have sqlite3 and libsqlite3-dev
  • gem install rails
  • why rails?
  • github's on rail!
  • rails new
  • generates a shit ton of file, the fuck is all that for?
  • primarily going to be concerned with app/ and config/
  • routes
  • app/ => MVC
  • models
@tomelm
tomelm / gist:3776030
Created September 24, 2012 13:44
Ruby version of Jesse's n way merge from Java
def n_way_merge(arrays, chunks, chunk_size, new_array)
indices = []
(0..chunk_size-1).each_with_index do |n,i|
min = (1..chunks).select { |j|
indices[j] < chunk_size && arrays[chunk_size * j + indices[j]] < arrays[chunk_size * min + indices[min]]
}.first
new_array[i] = arrays[chunk_size * min + indices[min]]
indices[min] += 1
end
@tomelm
tomelm / gist:3955122
Created October 25, 2012 20:13
Chocolate Banana Bread Pudding for skalnik
Ingredients:
* 4 cups cubed french bread (get something nice, fresh and tasty!)
* 4 eggs
* 2 cups milk
* 1 cup white sugar
* 1 tbl spoon vanilla extract
* 2 bananas, sliced (optional)
* 1 cup semi-sweet chocolate chips (optional)
Steps:
public static class MapClass extends MapReduceBase
implements Mapper<Text, Text, Text, Text> {
public void map(Text key, Text value, OutputCollector<Text, Text> ouput, Reporter reporter)
throws IOException {
output.collect(value, key);
}
}
(1..31).each_with_object({}) { |day,hash| hash[day] = nil }
=> {1=>nil,
2=>nil,
3=>nil,
4=>nil,
5=>nil,
6=>nil,
7=>nil,
8=>nil,
9=>nil,
@tomelm
tomelm / problem1.c
Last active December 11, 2015 11:09
// %s/ctof_factor\|ctof_offset/~&/g
#include <stdio.h>
#define CTOF_FACTORCTOF_FACTOR 1.8
#define CTOF_OFFSETCTOF_OFFSET 32
int CtoF(int C)
{
int F;
@tomelm
tomelm / simple_polygon.rb
Created February 12, 2013 18:39
figure out if a simple polygon is valid
class Point
attr_accessor :x, :y
end
class SimplePolygon
def initialize(points)
@points = points
@lines = []
end
@tomelm
tomelm / data.json
Last active December 13, 2015 20:58
{"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla pulvinar mattis neque sit amet venenatis. Pellentesque ut mauris eget nulla suscipit aliquet et eu lectus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Nulla vulputate vehicula justo, in posuere felis adipiscing in. Duis bibendum erat sed arcu dapibus at tincidunt erat feugiat. Donec ut purus laoreet felis facilisis pharetra et vitae sem. Morbi semper pellentesque ligula in tincidunt. Nunc ut nisi eget quam accumsan tristique. Vestibulum tincidunt, metus eu malesuada vehicula, augue nunc varius risus, ac malesuada felis eros quis lectus. Nam ac turpis vitae est dictum ultrices. Pellentesque viverra, urna sed rutrum bibendum, turpis nibh viverra erat, et mattis nunc arcu nec massa. Phasellus non diam vel sem vehicula pulvinar a porta dolor. Cras ut leo massa. Sed vel vestibulum nibh."}
{"text": "Ut vel libero fringilla elit placerat adipiscing ullamcorper ac lacus. Nulla tortor tortor, cursus in
4974214|master⚡ ⇒ ruby asdf.rb --run --local data.json output.txt
/Users/telmalem/.rvm/gems/ruby-1.9.3-p362/gems/wukong-2.0.2/lib/wukong/script.rb:268: Use RbConfig instead of obsolete and deprecated Config.
I, [2013-02-17T19:19:41.211925 #31942] INFO -- : Launching hadoop!
I, [2013-02-17T19:19:41.212019 #31942] INFO -- : Running
/usr/lib/hadoop/bin/hadoop \
jar /usr/lib/hadoop/contrib/streaming/hadoop-*streaming*.jar \
-D mapred.job.name='asdf.rb---data.json---output.txt' \
-mapper '/Users/telmalem/.rvm/rubies/ruby-1.9.3-p362/bin/ruby asdf.rb --map --log_interval=10000 --log_seconds=30 --local=true' \
-reducer '/Users/telmalem/.rvm/rubies/ruby-1.9.3-p362/bin/ruby asdf.rb --reduce --log_interval=10000 --log_seconds=30 --local=true' \