Skip to content

Instantly share code, notes, and snippets.

View psychocandy's full-sized avatar

Amir Friedman psychocandy

  • Berlin, Germany
View GitHub Profile

Keybase proof

I hereby claim:

  • I am psychocandy on github.
  • I am amirf (https://keybase.io/amirf) on keybase.
  • I have a public key ASAZbAd4OFmWD8QsDVNMaMI_vcpJh79LpJpjeZyu8gkW_wo

To claim this, I am signing this object:

@psychocandy
psychocandy / fish_prompt.fish
Created January 25, 2016 10:42
robbyrussell fish_prompt.fish with timestamp
# name: RobbyRussel
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty ^/dev/null)
end
function fish_prompt
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@psychocandy
psychocandy / .pryrc
Created May 28, 2014 12:27
AwesomePrint + Pry
begin
require 'awesome_print'
AwesomePrint.pry!
rescue
puts 'There is no Awesome Print gem installed'
end
@psychocandy
psychocandy / pg_config_dir.sh
Created April 28, 2014 14:24
when the pg gem doesn't install on mavericks:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
@psychocandy
psychocandy / install_ruby_with_readline.sh
Created April 28, 2014 12:56
install ruby on mavericks with Readline 6.3
brew uninstall readline
cd /usr/local/
git checkout 0181c8a Library/Formula/readline.rb
brew install readline
RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline) --with-openssl-dir=$(brew --prefix openssl)" ruby-install ruby
@psychocandy
psychocandy / create_list.rb
Created May 28, 2013 13:14
Factory girl example
# one way:
FactoryGirl.create_list(:monetization_campaign, 10)
# another way:
10.times { FactoryGirl.create(:monetization_campaign) }
# guarentee ids:
10.times { |n| FactoryGirl.create(:monetization_campaign, id: n) }
@psychocandy
psychocandy / autovivify_hash.rb
Created February 17, 2013 13:57
Autovivification which allows you to nest away and save you a lot of nil? checks.
hash = Hash.new { |h,k| h[k] = Hash.new(&h.default_proc) }
hash[:foo]["bar"][:baz] = 13
# => {:foo=>{"bar"=>{:baz=>13}}}
@psychocandy
psychocandy / map_hash.rb
Created February 17, 2013 11:17
An idea for mapping to a hash. Kudos to @dorkalev.
# [1,2,3].map_hash { |x| [x, x*2] }
# => {1=>2, 2=>4, 3=>6}
# { foo: "bar", fiz: "baz" }.map_hash { |k,v| [v,k] }
# => {"bar"=>:foo, "baz"=>:fiz}
module Enumerable
def map_hash
Hash[*self.inject([]) { |arr, a| arr += yield(a) }]
end
end
@psychocandy
psychocandy / enum.rb
Last active December 12, 2015 09:59
A fair implementation of an enum in Ruby. Inspired by Elad Meidar's article on gistflow - http://gistflow.com/posts/682-ruby-enums-approaches
# usage:
# FRUITS = Enum.new(:apples, :oranges)
# FRUITS[:apples] # => 0
# FRUITS[0] # => :apples
class Enum < Hash
def initialize(*members)
super()
@reverse = {}