Skip to content

Instantly share code, notes, and snippets.

View haraldmartin's full-sized avatar
🌝

Martin Ström haraldmartin

🌝
View GitHub Profile
require 'open-uri'
# url dsl -- the ultimate url dsl!
#
# You just can't beat this:
#
# $ irb -r url_dsl
# >> include URLDSL
# => Object
# >> http://github.com/defunkt.json
#!/bin/bash
#
# Save in your .bash_profile then: isreg domain.com
function isreg {
whois $1 | grep -q 'No match' && echo "No" || echo "Yes"
}
:⌉
=⌉
¦-) as opposed to |
⍥ om nom nom
=== 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
// In most browsers, a <label> tag around a form field, e.g.:
//
// <label>
// <input type="checkbox" id="private" name="private">
// This message is private
// </label>
//
// works just as if you'd specified a for= attribute on the label
// for the first visible field inside the label. In Safari 4, this
// seems not to be the case (i.e. the for= attribute is required).
shared: &shared
# Use different adapters with JRuby vs. MRI
adapter: <%= defined?(JRuby) ? "jdbcmysql" : "mysql" %>
encoding: utf8
username: root
password:
host: localhost
socket: /opt/local/var/run/mysql5/mysqld.sock
<%
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
# $ tweet Hi mom!
#
# Put this in ~/.bashrc or wherever.
# If it doesn't work, make sure your ~/.netrc is right
#
# (Thanks to @anildigital and @grundprinzip for curl-fu)
function tweet {
curl -n -d status="$*" https://twitter.com/statuses/update.xml --insecure &> /dev/null
echo "tweet'd"
# Mimic Mac OS X Finder's sort by name.
class Array
def finder_sort
sort_by do |str|
punctuation = %w[` ^ _ - , ; ! ? ' " ( ) [ ] { } @ *] + ['\\'] + %w[& # % + < = > | ~ $]
str.to_s.gsub(/\d+|[^a-z\s]/i) do |match|
if punctuation.include? match
"1".rjust(200 - punctuation.index(match), "0")
elsif match =~ /0+/ # make an exception for zeros
"1".rjust(101, "0")