Skip to content

Instantly share code, notes, and snippets.

View iGEL's full-sized avatar

Johannes Barre iGEL

View GitHub Profile
@iGEL
iGEL / build_light
Last active August 29, 2015 13:56
Build light
#!/usr/bin/env ruby
require 'net/http'
require 'json'
require 'uri'
class Light
GREEN_ID = 4762304
RED_ID = 4762303
@iGEL
iGEL / pentadactyl_usage.md
Last active August 29, 2015 13:57
Some stuff I learned about Pentadactyl

Pentadactyl is VIM for your Firefox. If you think that the mouse is a productive way to control your browser, think again! It's awesome.

Here some stuff I've learned about it (Still WIP). Please write a comment or message for improvements!

Copy & paste

To copy the URL of the current page, press y. Open a copied URL in the current tab, press p (P for a new tab).

To select text, press i. A cursor appears and you can move to the position you want with the usual commands like (h, j,k,l etc) (maybe you want to search in the page to get to the approximate position). With v you change to select mode and then press Y to copy it.

class ExceptionHandler
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
rescue ActionController::ParameterMissing, ActionController::BadRequest => e
Rails.logger.info "Handled #{e.class}: #{e.message} with 400 Bad Request"
[400, {}, ['400 Bad Request']]
@iGEL
iGEL / lazy.rb
Created June 29, 2014 15:18
lazy Ruby 2.0
# Evaluate everything in the array and then find the result:
[1,2,3,4,5,6].map { |z|
puts "Expensive operation with #{z}"
z.to_s
}.find { |s| s.to_i > 1 }
Expensive operation with 1
Expensive operation with 2
Expensive operation with 3
Expensive operation with 4
@iGEL
iGEL / wtf.rb
Last active August 29, 2015 14:03
From classes, you can reference toplevel constants even with a namespace! It'll just issue warnings. From modules, you get a NameError
C = 1
CA = 1
CB = 1
class A
CA = 2
class B
CB = 3
def c
@iGEL
iGEL / fix_nl_at_eol.sh
Last active August 29, 2015 14:03
Fix all missing newline at EOL recursively
find -name '*.rb' -exec sed -i -e '$a\' {} \;
# From http://www.regular-expressions.info/email.html
# Do NOT use it!
/(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])/
@iGEL
iGEL / webmock_curl.rb
Last active September 9, 2015 14:16
Patch WebMock to print the curl command on disabled net connect. Just copy & paste it to execute.
module WebMock
class NetConnectNotAllowedError < Exception
alias_method :stubbing_instructions_without_curl, :stubbing_instructions
private
def stubbing_instructions(request_signature)
[
stubbing_instructions_without_curl(request_signature),
CurlInstructions.new(request_signature).instructions
# Another example with YAML. Consider this file (the <c> is my cursor):
en:
test:
hello: "World"<c>
# Now I press Enter
en:
test:
hello: "World"