Skip to content

Instantly share code, notes, and snippets.

View coffeeaddict's full-sized avatar

Hartog C. de Mik coffeeaddict

View GitHub Profile
@coffeeaddict
coffeeaddict / humidex.rb
Created June 28, 2011 13:19
Calculate the humidex
#!/usr/bin/env ruby
# estimate the dewpoint temperature
def dew_point(temp, rv)
e = 6.1121 * (10 ** (7.502 * temp / (237.7 + temp)))
p = (rv * e) / 100.0
dp = (-430.22 + 237.7 * Math.log(p))/(-(Math.log(p)) + 19.08);
end
# estimate the wet bulb temperature
@coffeeaddict
coffeeaddict / alL_any.rb
Created July 11, 2011 07:16
Didnt know
[2,4].any? { |n| n % 2 == 0 }
[2,4].all? { |n| n % 2 == 0 }
[2,4].empty? { |n| n % 2 == 0 }
# yield: true, true, false
# I never knew or suspected any? or empty? could be given a block - this makes live pleasant :-)
@coffeeaddict
coffeeaddict / 20110210144658_create_entity_jobs.rb
Created July 13, 2011 09:06
Get (some) control over your Delayed::Job's
class CreateEntityJobs < ActiveRecord::Migration
def self.up
create_table :entity_jobs do |t|
t.references :entity, :polymorphic => true
t.references :delayed_job
t.timestamps
end
add_index(:entity_jobs, :entity_id)
@coffeeaddict
coffeeaddict / include_once.rb
Created July 27, 2011 13:56
include_package
module Foo
require 'java'
include Java
include_package 'javax.swing'
class MyView < JFrame
def initialize
super "Casper"
@coffeeaddict
coffeeaddict / poc.rb
Created July 27, 2011 14:14
Will it blend?
module Foo
def bar
puts "Hello"
end
class Panel
end
class View < Panel
def foo
@coffeeaddict
coffeeaddict / bak.sh
Created January 30, 2012 07:38
My backup solution
#!/bin/sh
for file in $*
do
path=`dirname $file`
name=`basename $file`
if [ `printf "%.1s" $path` = "/" ]
then
echo "Files must be specified relative: $file"
@coffeeaddict
coffeeaddict / unspec.sh
Created February 22, 2012 11:41
Run uncommited specs
#!/bin/sh
bundle exec rspec -f d `git status | grep _spec | awk '{ print $NF }'`
pdefs
# fire and forget a workitem into the great unknown
# => 'Saturn, we are sending a ship. In 10 years'
#
sequence do
notify_saturn :forget => true
build_spaceship
launch_spaceship :destination => 'saturn'
end
@coffeeaddict
coffeeaddict / alt.rb
Created March 6, 2012 16:09
Akka 2.0 experiment
# A JRuby alternative for the Akka.io homepage scala and java examplatory code.
require 'java'
require './lib/scala-library.jar'
require './lib/akka/akka-actor-2.0.jar'
module Akka
include_package 'akka.actor'
end
@coffeeaddict
coffeeaddict / http_authentication
Created April 16, 2012 18:09 — forked from ipoval/http_authentication
Http basic authentication for padrino
module HttpAuthentication
module Basic
def authenticate_or_request_with_http_basic(user, pass, realm = 'Application')
authenticate_with_http_basic(user, pass) || request_http_basic_authentication(realm)
end
def authenticate_with_http_basic(user, pass)
if auth_str = request.env['HTTP_AUTHORIZATION']
return ActiveSupport::Base64.decode64(auth_str.sub(/^Basic\s+/, '')) == [ user, pass ].join(":")
end