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 / tree.rb
Created July 20, 2012 11:41
For philipp
require 'find'
require 'term/ansicolor'
class Color
extend Term::ANSIColor
end
root = ARGV[0] || Dir.pwd
Find.find(root) do |path|
@coffeeaddict
coffeeaddict / ruote-setup.md
Created July 18, 2012 17:43
For mister_solo, as a reply to a question on #ruote (freenode irc)

Setup

This is my ruote / ruote-kit setup in non Rails project

A Project Module

I tend to have a Project Module for my non-web projects; so that instead of calling Rails.logger I call Project.logger (Where Project would be the actual name, Such as Fubar or SameOld) same goes for ruote. It mostly ends-up in Project.engine where the code would look something like this:

@coffeeaddict
coffeeaddict / application_controller.rb
Created July 11, 2012 18:46
Add a doorkeeper session token to the current user
class ApplicationControler < AC::Base
include FayeHelper
# ... existing code
before_filter {
return if current_user.nil?
if current_user.refresh_session_token
# make a new client with the new token
client = setup_faye_client
@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
@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
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 / 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 }'`
@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 / 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 / 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"