This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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 :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
require 'java' | |
include Java | |
include_package 'javax.swing' | |
class MyView < JFrame | |
def initialize | |
super "Casper" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Foo | |
def bar | |
puts "Hello" | |
end | |
class Panel | |
end | |
class View < Panel | |
def foo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
for file in $* | |
do | |
path=`dirname $file` | |
name=`basename $file` | |
if [ `printf "%.1s" $path` = "/" ] | |
then | |
echo "Files must be specified relative: $file" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
bundle exec rspec -f d `git status | grep _spec | awk '{ print $NF }'` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |