Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
Shippin Stuffs 🚀

Peter Schröder phoet

:shipit:
Shippin Stuffs 🚀
View GitHub Profile
@phoet
phoet / nil_or.rb
Created June 28, 2009 17:43
nil-or example
View nil_or.rb
# Creates an object you can savely traverse without getting nil.
# This is very pleasant for deep data-structures.
# You can punch the duck until it should become a string:
# NilOr.new(nil).what.the.fuck?.to_s --> nil
class NilOr
def initialize(object, parent = nil)
@object = object
@call_stack = (parent || [])
puts "current stack #{@call_stack}"
@phoet
phoet / i_dont_give_a_shit.rb
Created August 24, 2009 08:49
example of i don't give a shit gem
View i_dont_give_a_shit.rb
alias :method_missing_i_dont_give_a_shit :method_missing
def method_missing(sym,*args, &block)
puts "sym is #{sym}"
method_name = sym.to_s
if /.+\?$/ =~ method_name
puts "i dont care"
target_method = method_name[0..-2]
puts "target is #{target_method}"
puts self.class
@phoet
phoet / bindings.xml
Created April 29, 2010 10:13
jaxws definitions that work
View bindings.xml
<jaxws:bindings version="2.1" wsdlLocation="service.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://java.sun.com/xml/ns/jaxws" xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<enableWrapperStyle>false</enableWrapperStyle>
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xsd:schema[@targetNamespace='http://authentication.integration.crowd.atlassian.com']">
<jxb:globalBindings generateElementProperty="false">
@phoet
phoet / analytics.sh
Created April 29, 2010 11:28
open multiple google analytics accounts
View analytics.sh
#! /usr/bin/env ruby
[25021834, 18768647].each do |product_id|
url = "https://www.google.com/analytics/reporting/?reset=1&id=#{product_id}&pdr=#{(Time.now - (7 * 60 * 60 * 24)).strftime("%Y%m%d")}-#{Time.now.strftime("%Y%m%d")}"
`open "#{url}"`
end
@phoet
phoet / git_and_brew.sh
Created July 1, 2010 15:05
git and homebrew via curl
View git_and_brew.sh
# thx to tobstarr
sudo mkdir -p /usr/local && sudo chown -R $USER /usr/local && curl -Lsf http://bit.ly/9H4NXH | tar xvz -C/usr/local --strip 1 && brew install git
@phoet
phoet / talk.sh
Created August 24, 2010 14:19
using applescript for adium
View talk.sh
#! /usr/bin/env ruby
users = {
:rubiii => 'daniel.harrington',
:tri => 'thilko.richter',
}
user = users[ARGV.shift.to_sym]
message = ARGV.join(' ')
@phoet
phoet / rails_admin_without_devise.rb
Created December 17, 2010 15:35
Using RailsAdmin without devise
View rails_admin_without_devise.rb
# add RailsAdmin to the Gemfile
# do NOT add devise
gem "rails_admin", :git => "git://github.com/sferik/rails_admin.git"
# run Bundler
bundle
# run the generator for RailsAdmin
# looks like it's broken, but it just does not install devise
# you may also remove the app/config/locales/devise.en.yml
@phoet
phoet / Gemfile.rb
Created January 30, 2011 14:57
Gemfile fuckup
View Gemfile.rb
source :gemcutter
gem "rails", "~> 3.0.3"
gem "rails_redis_cache", "~> 0.0.4"
gem "haml", "~> 3.0.25"
gem "hashie", "~> 1.0.0"
gem "asin", "~> 0.2.0" # hashie 1.0.0
gem "twitter", "~> 1.1.1" # hashie 0.4.0
gem "coderay", "~> 0.9.3"
@phoet
phoet / action_view_base.rb
Created April 6, 2011 07:42
initializer for helping to find partials in large applications
View action_view_base.rb
if development?
module ActionView
class Base
alias_method :rails_render, :render
# add debugging comments for partials to the rendered html
def render(options = {}, local_assigns = {}, &block)
output = rails_render(options, local_assigns, &block)
if options.respond_to?(:keys) && options[:partial] && (response.content_type.nil? || response.content_type =~ /html/)
@phoet
phoet / dsl.rb
Created April 12, 2011 16:19
examples of dsl api stuff
View dsl.rb
# encoding utf-8
module DSL
link_to "Articles", { :controller => "articles" }, :id => "news", :class => "article"
def doit_with(some, parameters)
# does it
end
def doit_with(mandatory, optional=nil, parameters=nil)