Skip to content

Instantly share code, notes, and snippets.

View iGEL's full-sized avatar

Johannes Barre iGEL

View GitHub Profile
@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\' {} \;
@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 / 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
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 / 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.

@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 / .Xresources
Last active August 31, 2020 11:26
Xft.dpi: 96
URxvt.font: xft:DejaVu\ Sans\ Mono:size=11
URxvt.scrollBar: off
URxvt.saveLines: 4096
URxvt.perl-ext-common: default,url-select,keyboard-select,font-size,clipboard
URxvt.urlLauncher: xdg-open
@iGEL
iGEL / prepare-commit-msg
Last active December 22, 2015 17:59
Gets the Trello card ID from your branch name and includes it into the commit message
#!/bin/bash
# Takes the last token of the branch name (separated with an underscore)
# takes adds is into the commit message.
#
# Note: If you want to about committing from the editor, remove the tag and save the file
#
# 1) Put this file into .git/hooks/prepare-commit-msg
# 2) Make it executable: chmod +x .git/hooks/prepare-commit-message
@iGEL
iGEL / gist:3137210
Created July 18, 2012 16:12
Get a Date (the Monday) of a given ISO 8601 week by it's week number in Ruby
class Date
# Returns the monday of the given week number
def self.by_iso_weekno(year, weekno)
# January 4th is always in the first week according to ISO 8601
date = Date.civil(year, 1, 4) + (weekno - 1) * 7
date - (date.wday != 0 ? date.wday - 1 : 6) % 7
end
end