Skip to content

Instantly share code, notes, and snippets.

View sos4nt's full-sized avatar

Stefan Schüßler sos4nt

View GitHub Profile
class Client
def self.post(&block)
data = DslData.new
Dsl.new(data).instance_eval(&block)
# build request with data from dsl calls
# and execute request
puts "Making a request to #{data.url} with headers #{data.headers}"
response = "response" # this would be your http response
if rand > 0.5 # response.success?
def a_1
{ a: 1 } if condition_1
end
def a_2
{ a: 2 } if condition_2
end
def a_3
{ a: 3 }
@sos4nt
sos4nt / enumerable_lazy_each.rb
Created April 19, 2017 17:22
Chainable Enumerator::Lazy#each
class Enumerator::Lazy
def each(*)
super
self
end
end
require 'money'
require 'json'
Money.use_i18n = false
class Money
def to_json(*)
to_s
end
end
@sos4nt
sos4nt / else_if.rb
Created August 6, 2015 15:41
elsif converted to else if
def describe(inhabitant)
if inhabitant == "sophie"
puts 'gender: female'
puts 'height: 145'
else
if inhabitant == "paul"
puts 'gender: male'
puts 'height: 145'
else
if inhabitant == "dawn"
puts "Hello World"
@sos4nt
sos4nt / iterm_open_with
Created March 26, 2013 13:06
Semantic history command for iTerm2 and Sublime Text 3. In iTerm's Preferences > Profiles > Default > Advanced > Semantic History, choose "Run command..." and enter "/your/path/to/iterm_open_with \1 \2".
#!/bin/sh
file "$1" | grep -q "text"
if [ $? -ne 0 ]; then
/usr/bin/open $1
else
/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl $1:$2
fi
@sos4nt
sos4nt / xterm-256color-italic.terminfo
Created July 27, 2012 12:13
A xterm-256color based TERMINFO that adds the escape sequences for italic
# A xterm-256color based TERMINFO that adds the escape sequences for italic.
#
# Install:
#
# tic xterm-256color-italic.terminfo
#
# Usage:
#
# export TERM=xterm-256color-italic
#
@sos4nt
sos4nt / git-extract.sh
Created February 24, 2012 14:11
Extracts changed files from a specified commit into an output directory
#!/bin/sh
set -e
usage() {
echo "usage: git-extract.sh commit output-directory"
}
extract() {
FILES=`git diff-tree --oneline --no-commit-id --name-only -r $1`
for file in $FILES
@sos4nt
sos4nt / gist:1363753
Last active September 28, 2015 01:38
Using ruby-debug19 with Ruby 1.9.3, RVM and Bundler
#!/bin/bash
# Run using: bash <(curl -s https://raw.github.com/gist/1363753)
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p0/
rm linecache19-0.5.13.gem
rm ruby-debug-base19-0.11.26.gem
bundle update ruby-debug19