Skip to content

Instantly share code, notes, and snippets.

time_select = (time_str) ->
time_str = time_str.match /(\d+):(\d+)/
if (time_str)
[h, m] = time_str[1..2]
hour_options = for hour in [0...24]
hour_s = if hour < 10 then "0#{hour}" else hour
"<option #{if hour == h then 'selected' else ''}>#{hour_s}</option>" # TODO Coffee == -> === macht wahrscheinlich stress
minute_options = for minute in [0...60]
minute_s = if minute < 10 then "0#{minute}" else minute
"<option #{if minute == m then 'selected' else ''}>#{minute_s}</option>"
sdasdas
@janv
janv / proctest.rb
Created July 28, 2011 20:32
Small sample program to illustrate process management in ruby
#!/usr/bin/env ruby
require 'set'
class Monitor
@@max_procs = 3
def initialize(worker_class)
@worker = worker_class.new
@interrupted = false
@threads = []
@janv
janv / polyline_encoder.rb
Created November 13, 2011 09:35
Polyline Encoder
class PolylineEncoder
# Encode an rgeo exterior ring/interior ring,
# anything with an attribute points, containing an array
# of object with x and y float attributes
def self.encode(ring)
encoded = ""
px = 0
py = 0
@janv
janv / .irbrc
Created November 16, 2011 15:36 — forked from adamcrown/.irbrc
My Bundler proof .irbrc file including wirble, awesome_print, hirb, console logging and route helpers
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
def unbundled_require(gem)
loaded = false
if defined?(::Bundler)
Gem.path.each do |gems_path|
gem_path = Dir.glob("#{gems_path}/gems/#{gem}*").last
@janv
janv / install_ruby_debug.sh
Created December 9, 2011 00:22
Install Ruby-debug with RVM using Ruby 1.9.3-p0-falcon
#!/bin/sh
curl -LO http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -LO http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install linecache19-0.5.13.gem
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$HOME/.rvm/rubies/ruby-1.9.3-p0-falcon/include/ruby-1.9.1/ruby-1.9.3-p0/
rm linecache19-0.5.13.gem
rm ruby-debug-base19-0.11.26.gem
@janv
janv / have_content_type.rb
Created January 20, 2012 15:47 — forked from jcf/MIT License
RSpec matcher for parsing `response.headers['Content-Type']`
RSpec::Matchers.define :have_content_type do |content_type|
CONTENT_HEADER_MATCHER = /^(.*?)(?:; charset=(.*))?$/
chain :with_charset do |charset|
@charset = charset
end
match do |response|
_, content, charset = *content_type_header.match(CONTENT_HEADER_MATCHER).to_a
@janv
janv / spec_helper.rb
Created January 21, 2012 18:36 — forked from yitzhakbg/spec_helper.rb
My spec_helper.rb
require 'rubygems'
require 'spork'
def start_simplecov
require 'simplecov'
SimpleCov.start 'rails' unless ENV["SKIP_COV"]
end
def spork?
defined?(Spork) && Spork.using_spork?
@janv
janv / fix.php
Created February 9, 2012 16:46
Wordpress imgly-gallery fix
<?
function imgly_pics($username = '', $num = 4, $linked = true, $size = 75, $margin = 5, $border = 0, $bordercolor = '#FFFFFF') {
$file = @file_get_contents("http://img.ly/images/".$username.".rss");
preg_match_all('/<link>http:\/\/img.ly\/(\w+)<\/link>/i', $file, $matches);
$imageids = $matches[1];
for($i = 0; $i < $num; ++$i) {
$imageid = $imageids[$i];
@janv
janv / application.rb
Created February 15, 2012 13:30 — forked from mcmire/application.rb
Integrating the Logging framework into your Rails 3 app
#-----------------------------------------------------------------------------------------------
# config/application.rb
#-----------------------------------------------------------------------------------------------
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(:default, Rails.env) if defined?(Bundler)
# Bring in the Railtie that will set Rails' various logger variables to
# instances of Logging::Logger instead of Rails' built-in ActiveSupport::BufferedLogger.