Skip to content

Instantly share code, notes, and snippets.

View felixrabe's full-sized avatar
🦀
Focusing on Rust

Felix Rabe felixrabe

🦀
Focusing on Rust
View GitHub Profile
@felixrabe
felixrabe / google-simplify.rb
Created February 28, 2012 12:50
Simplify Google search URL
#!/usr/bin/env ruby
require 'cgi'
require 'uri'
PREFIX = "https://www.google.com/search?q="
# Examples:
# http://www.google.ch/webhp?sourceid=chrome-instant&ix=sea&ie=UTF-8&ion=1#sclient=psy-ab&hl=de&site=webhp&source=hp&q=ruby%20parse%20url%20query&pbx=1&oq=&aq=&aqi=&aql=&gs_sm=&gs_upl=&fp=6c2025d738093ae5&ix=sea&ion=1&bav=on.2,or.r_gc.r_pw.,cf.osb&biw=1920&bih=1114
# => https://www.google.com/search?q=ruby+parse+url+query
@felixrabe
felixrabe / unhash.rb
Created February 28, 2012 16:05
Filter for Haml files to convert %tag{:attr => "value"} into %tag(attr="value")
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# See: https://gist.github.com/1933369
# Filter for Haml files to convert %tag{:attr => "value"} into %tag(attr="value")
$tag_attr_order = {
"link" => %w( rel sizes href ),
"meta" => %w( name content )
@felixrabe
felixrabe / truth.rb
Created February 29, 2012 14:38
truth.rb
#!/usr/bin/env ruby
class Object
def > other # implication operator: false > true == true
if self == true or self == false
!self or other
else
super
end
end
@felixrabe
felixrabe / hiera.rb
Created March 13, 2012 16:17
hiera.rb
selection = (ARGV[0] || 0).to_i
input = STDIN.readlines
if input[-1]
input[-1] += "\n" unless input[-1].end_with? "\n"
else
input << "\n"
end
whitespace_re = /^(\s*)/
i = 0
whitespace = selection == 0 ? "" : nil
require 'csv'
# Please someone include this in the csv module proper. Thanks.
# Public domain. Author: Felix Rabe (heavily based on 1.9.3 stdlib csv docs)
class CSV
def CSV.unparse array
CSV.generate do |csv|
array.each { |i| csv << i }
end
@felixrabe
felixrabe / gist:2665708
Created May 12, 2012 10:29
Recode Java files, ISO-8859-1 => UTF-8
find . -type f -name '*.java' | sort | while read fn ; do
echo "$fn" &&
iconv -f ISO-8859-1 -t UTF-8 "$fn" -o "$fn.MOD" &&
mv "$fn.MOD" "$fn"
done
@felixrabe
felixrabe / Ruby.sublime-build
Created October 9, 2012 21:26 — forked from pmarreck/Ruby.sublime-build
Get Sublime Text 2 to use your RVM ruby and bundle Gemfile
# Get Sublime to use your rvm ruby... Change your ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build to this, replacing YOURUSERNAME:
{
"cmd": [
"bundle", "exec", "$HOME/.rvm/bin/rvm-auto-ruby", "$file"
],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
@felixrabe
felixrabe / Formular.html
Created October 20, 2012 13:52
Formular
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>This is a form example</title>
</head>
<body>
<h1>This is a form example</h1>
<form action="" method="post">
@felixrabe
felixrabe / timedgrep
Created October 25, 2012 16:32
Timestamped grep-ing for log files and similar sources that provide no timestamps.
#!/bin/bash
# Public domain. Written by Felix Rabe in 2012.
# Timestamped grep-ing for log files and similar sources that provide no timestamps.
# Usage example (used for a Redmine 1.4 / Rails 2.3 project):
# tail -f log/production.log | timedgrep email
look_for="$1"
@felixrabe
felixrabe / gist:4110745
Created November 19, 2012 13:49
abspath
function abspath() {
cd -P -- "$(dirname -- "$1")" &&
echo "$(pwd -P)/$(basename -- "$1")"
}