Skip to content

Instantly share code, notes, and snippets.

View bil-bas's full-sized avatar

Bil Bas bil-bas

View GitHub Profile
@bil-bas
bil-bas / gist:3419649
Created August 21, 2012 21:38 — forked from anonymous/gist:3419574
Traffic CSV for nullsign
require 'csv'
# Read the list of hosts.
hosts = {}
CSV.open('./datafile.csv', 'r') do |fields|
hosts[fields[0]] = { :location => fields[1], :device_type => fields[3] }
end
# Find out the date to report on.
report_file = './report.csv'
require 'fastercsv' # Gem I'm assuming is beign used, but there are others.
hash = {} # So apeiros_ doesn't murder me
FasterCSV.foreach("path/to/file.csv") do |line|
hash[line[0].to_sym] = { :location => line[1], :device_type => line[3] }
end
# then you can reference with
class RawDataController < ApplicationController
helper_method :sort_column, :sort_direction
def index
end
protected
def sort_column
logger.debug self.class::SORT_MODEL.inspect
@bil-bas
bil-bas / gist:3221023
Created July 31, 2012 21:57
Random hash picker
heftig:
first, do target = rand(a.inject(0){|m,h| m + h[:prob]})
to get a value between 0 and (sum of all probs - 1)
then just a.find { |h| target -= h[:prob]; target < 0 }
steps through the array, reducing target by prob until it's < 0
@bil-bas
bil-bas / gist:3170006
Created July 24, 2012 13:51
Ashton benchmarks

Benchmarks for Ashton

(results in milliseconds per call, operating on a image/texture of size 1022x1022)

Ashton::PixelCache

PixelCache#to_image             32.61720

PixelCache#refresh 1.83594

translate -@camera_x, -@camera_y do
@map.draw
@player.draw
end
translate 10, 10 do
score_text = "Collected: #{@player.items}"
score_width = @score_font.text_width score_text
draw_quad 0, 0, 0xaa000000,
@bil-bas
bil-bas / gosu_shader_segfault.rb
Created July 12, 2012 15:29
Gosu Window#gl segfaults with shader when deferring drawing.
# Failing case of Window#gl used with shaders.
require "opengl" # Gem must be "opengl" gem, not "ruby-opengl" gem
require 'gosu'
def media_path(file); File.expand_path "media/#{file}", File.dirname(__FILE__) end
class TestWindow < Gosu::Window
def initialize
super 640, 480, false
@bil-bas
bil-bas / shader.vert
Created July 9, 2012 11:41
vertex shader issue
#version 110
attribute vec2 in_TexCoord;
varying vec2 var_TexCoord;
void main()
{
gl_Position = ftransform();
var_TexCoord = in_TexCoord;
@bil-bas
bil-bas / .gitignore
Created July 6, 2012 13:44
Shader/Framebuffer tests
/framebuffer.png
/framebuffer_section.png
@bil-bas
bil-bas / gist:3049003
Created July 4, 2012 19:12
programatically define a method that accepts a block
class Test
def self.define_me_a_method(name)
self.send(:define_method, name, proc { |&block|
block.call
})
end
define_me_a_method 'awesome'
end