Skip to content

Instantly share code, notes, and snippets.

Avatar
🦆
🦆 🦆 🦆 🦆

Henrik Nyh henrik

🦆
🦆 🦆 🦆 🦆
View GitHub Profile
@henrik
henrik / gfm.rb
Created Apr 16, 2009 — forked from mojombo/gfm.rb
GitHub Flavored Markdown
View gfm.rb
# GitHub Flavored Markdown Layer
def fix_markdown_quirks(text)
# prevent foo_bar_baz from ending up with an italic word in the middle
text.gsub!(/(\w+_\w+_\w[\w_]*)/) do |x|
x.gsub('_', '\_') if x.split('').sort.to_s[0..1] == '__'
end
# in very clear cases, let newlines become <br /> tags
text.gsub!(/(\A|\n\n)(^\w[^\n]*\n)(^\w[^\n]*\n)+/m) do |x|
x.gsub(/^(.+)\n/, "\\1 \n")
View epic snow leopard upgrade guide.txt
=== Epic Snow Leopard Upgrayyyyd Guide ===
Son, you’re now living in the land of 64-bit systems.
That means that some of your 32-bit shit is now broken.
Not all is lost.
== Fixing MySQL weirdness
@henrik
henrik / .bashrc
Created Jul 15, 2010 — forked from filipsalomonsson/.bashrc
grep that doesn't wait forever for STDIN with unspecified filename.
View .bashrc
# Call grep, with stdin closed if it is a terminal.
#
# Avoids the "eternal wait" problem when you've forgotten
# to specify a filename.
function grep { (tty -s && exec <&-; $(which grep) $@); }
View aws_zone.rb
def aws_zone
[ ["east", "d"], ["west", "c"] ].inject([]) do |array, (zone, max)|
'a'.upto(max) { |letter| array << "us-#{zone}-1#{letter}" }
array
end.sample
end
View gist:1296042
# Sort lexicographically, but sorting numbers into their proper position.
#
class Array
def sort_preserving_numbers
sort_by { |x|
x.split(/(\d+)/).
map { |piece| piece.match(/\d/) ? piece.to_i : piece }
}
end
end
@henrik
henrik / example_output.txt
Created Jan 16, 2012 — forked from joakimk/example_output.txt
Ruby on Rails initializer to log Savon SOAP XML as pretty JSON instead. Also show what line of code called it.
View example_output.txt
--------------------------------------------------
lib/foo.rb:22:in `save'
# foo.book
>> REQUEST:
{
"CashBook_Book": {
"cashBookHandle": {
"Number": "14"
@henrik
henrik / my_sinatra_app.rb
Created Mar 3, 2012 — forked from brandonweiss/gist:1965390
Avoid listing gem requirements both in Gemfile and app for e.g. Sinatra on Heroku (and locally).
View my_sinatra_app.rb
require 'rubygems'
require 'bundler'
Bundler.require(:default, (ENV['RACK_ENV'] || "development").to_sym)
View git-submodule-rm.sh
#!/bin/bash
function actual_path() {
if [ [ -z "$1" ] -a [ -d $1 ] ]; then
echo $(cd $1 && test `pwd` = `pwd -P`)
return 0
else
return 1
fi
}
@henrik
henrik / config-initializers-resque_failure.rb
Created Nov 7, 2012 — forked from monde/honeybadger_resque.rb
Honeybadger based error reporting backend for Resque
View config-initializers-resque_failure.rb
require 'resque/failure/multiple'
require 'resque/failure/redis'
require 'resque_failure_honeybadger'
Resque::Failure::Multiple.classes = [
Resque::Failure::Redis,
Resque::Failure::Honeybadger
]
Resque::Failure.backend = Resque::Failure::Multiple
@henrik
henrik / tz_identifiers_to_rails_identifiers.rb
Created Aug 23, 2018 — forked from jpmckinney/tz_identifiers_to_rails_identifiers.rb
Maps tz database time zone identifiers to Rails time zone identifiers
View tz_identifiers_to_rails_identifiers.rb
# blog post: http://blog.slashpoundbang.com/post/2613268281/changing-from-tz-database-identifiers-to-rails-friendly
{
"Australia/Adelaide" => "Adelaide",
"Australia/Broken_Hill" => "Adelaide",
"America/Anchorage" => "Alaska",
"America/Juneau" => "Alaska",
"America/Nome" => "Alaska",
"America/Yakutat" => "Alaska",
"Pacific/Gambier" => "Alaska",
"Asia/Almaty" => "Almaty",