Skip to content

Instantly share code, notes, and snippets.

View hannestyden's full-sized avatar

Hannes Tydén hannestyden

  • Stockholm, Sweden
View GitHub Profile
def scream(s)
s.upcase
end
s = scream(<<-TEXT.gsub('z', 's')).gsub('EE', 'I')
Theez eez a lot of text.
Not really, but eet could be.
TEXT
# http://rubular.com/r/UMTb5KhY8A
DATE=/\d{4}-\d{2}-\d{2}/
ZONE=/Z|[-+]\d{2}(?::\d{2})?/
TIME=/\d{2}(?::\d{2}(?::\d{2}(?:\.\d+)?)?)?/
TIME_WITH_ZONE=/#{TIME}(?:#{ZONE})?/
ISO8601_FORMAT=/^(#{DATE})(?:T(#{TIME_WITH_ZONE}))?$/
ISO8601_FORMAT.match('2008-08-30T01:45:36.100Z') # => #<MatchData "2008-08-30T01:45:36.100Z" 1:"2008-08-30" 2:"01:45:36.100Z">
tmush-first-window() {
session_name=$1
window_name=$2
cmd=$3
work_dir=$4
start_window=$window_name
if [[ "$work_dir" != "" ]]; then
cd "$work_dir"
@hannestyden
hannestyden / spake.sh
Last active August 29, 2015 14:01
Make with space
# Make with double space instead tabs.
spake () {
cat Makefile | sed 's/ /\t/g' > Spakefile
make -f Spakefile $@
rm Spakefile
}
# dog = cat || less
dog () {
a=$(</dev/stdin)
echo $a | $((($(echo $a | wc -l) < $LINES)) && echo cat || echo less)
}
class Fixnum
def +@
2
end
def -@ # !> method redefined; discarding old -@
-2
end
def +(o) # !> method redefined; discarding old +
def scream(s)
s.upcase
end
array = %w[i scream u scream we all scream for icecream]
## "On" the object
array.map(&:upcase)
# => ["I", "SCREAM", "U", "SCREAM", "WE", "ALL", "SCREAM", "FOR", "ICECREAM"]
array.map { |c| c.method(:upcase).call }
# Lots of colors
export PS1='\[\033[00;32m\]\u\[\033[01m\]@\[\033[00;36m\]\h\[\033[01m\]:\[\033[00;35m\]\w\[\033[00m\]\[\033[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\[\033[00m\]\$ '
# Branch name colored yellow
export PS1='\u@\h:\w\[\033[00m\]\[\033[01;33m\]`git branch 2>/dev/null|cut -f2 -d\* -s`\[\033[00m\]\$ '
# No colors
export PS1='\u@\h:\w`git branch 2>/dev/null|cut -f2 -d\* -s`\$ '
@hannestyden
hannestyden / oauth_signature.rb
Created July 14, 2009 09:37
Reference implementation for OAuth request signing
# Signing an OAuth request
# Hannes Tydén, hannes@soundcloud.com, 2009-07-14
# Updated at 2009-09-03 to support OAuth 1.0a
# This is designed to be executed in an editor evaluating expressions and outputting the result inline.
# The spec:
# http://oauth.net/core/1.0#signing_process
# Read more:
controller = returning(ControllerClass.new()) { |c| c.send(:assign_shortcuts, ActionController::TestRequest.new, ActionController::TestResponse.new): c.send(:initialize_current_url) }