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 / 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 / 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 / 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|
class RuoteObserver
def initialize(context, options={})
end
def on_msg(msg)
case msg['action']
when 'launch'
msg['launched_at'] = Time.now
when 'terminated'
Project.logger.debug "{#{msg['wfid']}} [#{msg['workitem']['wf_name']}] took %.2fs" % (Time.now - msg['launched_at'])
class PreferedImplementation < Ruote::ProcessObserver
def on_launch(wfid, workitem, variables) # stash and pdef could also be there
$stderr.puts "Hey! #{wfid} started with #{workitem.fields}"
end
def on_end(wfid, workitem)
$stderr.puts "#{wfid} finaly made it! (the workitem ended up as #{workitem.fields})"
end
def on_flunk(wfid, workitem, error)
require 'tmpdir'
require 'ruote'
#
# blah
#
# Note: using ruote 2.3.0 (master), not too difficult to port to 2.2.0.
#
class ConvertFilesParticipant
include Ruote::LocalParticipant
def test_with_numbers
pdef = Ruote.define do
set 'commission' => 2.310000
set 'scommission' => '2.310000'
echo 'a', :if => '${f:commission} > 0'
echo '.'
echo 'b', :unless => '${f:commission} > 0'
@coffeeaddict
coffeeaddict / close_many_tabs.md
Created September 5, 2012 07:34
Close many tabs (Chromium)

Tired of hitting ctrl+w 20 times in a row?

Me too - so I just did it. I tried if my browser would behave as expected. And it did!

I went to the first tab I wanted to close by clicking on it with the mouse. Then, with the shift-button down, I clicked on the last tab. Now I held one hand before my eyes (peeking between 2 fingers) and hit ctrl+w.

It closed all those tabs. As one would expect.

Wow

@coffeeaddict
coffeeaddict / gist:3699848
Created September 11, 2012 17:02 — forked from JiriChara/gist:3697487
ALL CREDIT CARD PIN CODES IN THE WORLD / in 1 line :-p
(0..9999).map{|x|"%.4i"%x}.each_slice(10){|x|puts x.join("\t")}
@coffeeaddict
coffeeaddict / DORY.md
Created October 27, 2012 06:14
An explanation of DORY

DORY

DO Repeat Yourself

But why?

There is one very powerful phrase that describes the 'why?' very well: "Wax-on, wax-off!"