Skip to content

Instantly share code, notes, and snippets.

View hannestyden's full-sized avatar

Hannes Tydén hannestyden

  • Stockholm, Sweden
View GitHub Profile
View git branch in prompt
# 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
View oauth_signature.rb
# 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:
View console
controller = returning(ControllerClass.new()) { |c| c.send(:assign_shortcuts, ActionController::TestRequest.new, ActionController::TestResponse.new): c.send(:initialize_current_url) }
@hannestyden
hannestyden / array_to_ordered_hash.rb
Created December 9, 2009 11:24
Suggestion for ActiveSupport::CoreExtensions::Array::Conversions
View array_to_ordered_hash.rb
module ActiveSupport::CoreExtensions::Array::Conversions
def to_ordered_hash
self.inject(ActiveSupport::OrderedHash.new) do |ordered_hash, (key, value)|
ordered_hash[key] = value
ordered_hash
end
end
end
View argument_error_interning_empty_string.rb
begin; "".to_sym; rescue; $!.inspect; end # => "#<ArgumentError: interning empty string>"
begin; "".intern; rescue; $!.inspect; end # => "#<ArgumentError: interning empty string>"
View snowwhite.sh
while true; do echo '.*^{zZz}'; sleep 10; done
View array_range.rb
class Array
def range
[ self.min, self.max ]
end
end
View one_line_random_string.19.rb
# Ruby 1.9
(0...8).map { (@__alphanums ||= [ ('a'..'z'), ('A'..'Z'), ('0'..'9') ].map { |r| r.to_a }.flatten).sample }.join
View random_things.rb
module RandWaltzmann # Named after my first CS prof
extend self
def string(length=8)
(0...length).map { (@__alphanums ||= [ ('a'..'z'), ('A'..'Z'), ('0'..'9') ].map { |r| r.to_a }.flatten)[rand(@__alphanums.size)] }.join
end
end
View attempts.rb
# Inspired by/stolen from: http://refactormycode.com/codes/1065-retry
require 'logger'
module Kernel
def logger
@logger = Logger.new(STDOUT)
end
end