Skip to content

Instantly share code, notes, and snippets.

@rogerbraun
rogerbraun / output.png
Created June 27, 2011 16:35
Codebrawl #2 - Pixelizing an image with ChunkyPNG
output.png
@rogerbraun
rogerbraun / application.rb
Created August 6, 2011 12:16
Picky gives an error when trying to index japanese
# encoding: utf-8
#
# TODO Adapt the generated example
# (a library books finder) to what you need.
#
# Questions? Mail me, IRC #picky, the google group, http://github.com/floere/picky/wiki.
#
class PickySearch < Application
# How text is indexed. Move to Index block to make it index specific.
@rogerbraun
rogerbraun / application.rb
Created August 7, 2011 17:03
Partially working search with picky and japanese
# encoding: utf-8
#
# TODO Adapt the generated example
# (a library books finder) to what you need.
#
# Questions? Mail me, IRC #picky, the google group, http://github.com/floere/picky/wiki.
#
class PickySearch < Picky::Application
# So we don't have to write Picky::
require "romkan"
class WadokuEntry
def initialize(entry_as_string)
@str = entry_as_string
end
def kana
@str.split("\t")[1] # The reading is the second column in the file
end
@rogerbraun
rogerbraun / optimal.rb
Created September 12, 2011 01:28
Maxixes optimzer
pre_segmented = [["MYDOGISINTHEHOUSE", "MY DOG IS IN THE HOUSE"],
["FOURNICEDOGS", "FOUR NICE DOGS"],
["MYCATLIKESMYDOG", "MY CAT LIKES MY DOG"]]
index = Maxixe::Trainer.generate_corpus_from_io([2,3,4,5], "ILIKEMYDOG
THISHOUSEISMYHOUSE
MYDOGISSONICE
WHOLIKESDOGSANYWAY
CATSANDDOGSUSUALLYFIGHT
INMYHOUSETHEREAREFOURDOGS
IWANTAHOUSEFORMYDOG")
@rogerbraun
rogerbraun / README.md
Created September 13, 2011 15:30
Codebrawl #10

How to get the selective color effect

When I started thinking about this Codebrawl, I had essentially two ideas how to do get the selective color effect: Try to detect each crayon as an object and keep one of them in color, or take a reference color and just keep the colors that are similar to it. The first idea would be more universal, but seems to me much harder to implement. I chose the second one, so I needed a way to measure the distance between to colors.

How to measure the distance between colors

There are several ways to get a value that tells you how much colors are like each other. If you have an RGB pixel, you could just take these 3 values as coordinates in a 3D space and calculate the distance there. I did not actually implement this, as it does not represent similar colors in the way we would see them. For example, the color (255,0,0) and (127,0,0) would both be just red, but they would have the same distance as (255, 128, 0), which introduces green to the color mix and looks pretty diff

@rogerbraun
rogerbraun / test.rb
Created September 21, 2011 14:19
How to ping a list of IP adresses to check if they are still in use
ips = File.readlines("ip_list").map(&:strip)
used_ips = []
if File.exist?("used_ips")
used_ips = File.readlines("used_ips").map(&:strip)
end
ips -= used_ips
while ips.size > 0 do
@rogerbraun
rogerbraun / extensions.rb
Created September 28, 2011 01:15
Codebrawl 10 blog post
module ChunkyPNG::Color
# See http://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
def self.hue(pixel)
r, g, b = r(pixel), g(pixel), b(pixel)
return 0 if r == b and b == g
((180 / Math::PI * Math.atan2((2 * r) - g - b, Math.sqrt(3) * (g - b))) - 90) % 360
end
# The modular distance, as the hue is circular
def self.distance(pixel, poxel)
@rogerbraun
rogerbraun / nodes_and_edges.rb
Created October 19, 2011 14:45
Umwandeln von CoMon-HTML in Knoten und Kanten
require "nokogiri"
require "pry"
class NodesAndEdges
def initialize(filename)
file = open(filename)
@doc = Nokogiri::HTML(file)
end
def nodes
@rogerbraun
rogerbraun / testing_helpers.js
Created October 23, 2011 20:00
Simple Javascript testing
var assert_equal = function(a, b) {
if(a === b){
return {passed: true};
} else {
throw { message: ("Expected:\n\"" + a + "\"\nGot:\n\"" + b + "\""), passed: false}
;
}
}
var indent = function(text) {