Skip to content

Instantly share code, notes, and snippets.

@voidius
voidius / bash_profile
Created October 26, 2012 12:39
bash_profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
#PS1='\[\033[0;32m\]\W \u$ \[\033[0m\]'
source ~/.git-completion.bash
PS1='\[\e[0;33m\]\u\[\e[0;33m\]@\[\e[0;33m\]\h \[\e[0;32m\]\w\[\e[0;35m\]$(__git_ps1) \[\e[0;36m\]$(~/.rvm/bin/rvm-prompt) \n\[\e[0;31m\]\$\[\e[0;37m\] '
#alias ci="git commit -m"
#alias cia="git commit --amend -m"
#alias fix="git commit -m \"bugfix\""
@voidius
voidius / git-completion.bash
Created October 26, 2012 12:41
git-completion.bash
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
@voidius
voidius / how_to_rails_ic.txt
Last active October 12, 2015 04:38
How to get running a Rails project that uses Instant Client
# Probably you will need to start with removing all your ruby stuff :)
rvm uninstall all
# Install just 32bit ruby
# NB! I failed with ruby-1.9.3, so...
rvm install 1.9.2 -n i386 --with-arch=i386
# Then 32bit libyaml
CONFIGURE_OPTS="--with-arch=i386" CFLAGS="-arch i386" LDFLAGS="-arch i386" rvm pkg install libyaml
@voidius
voidius / date_enhancements.rb
Last active January 4, 2016 05:29
Ruby on Rails 'Date' object enhancements
class Date
def beginning_of_halfyear
beginning_of_month.change(:month => [7, 1].detect { |m| m <= self.month })
end
def end_of_halfyear
beginning_of_month.change(:month => [6, 12].detect { |m| m >= self.month }).end_of_month
end
#!/bin/bash
# To close a misbehaving program properly.
#
# by desgua (desgua@gmail.com)
#
# License GPL
#
# version 0.03 02/22/2013
@voidius
voidius / customFormBuilder.rb
Created January 28, 2014 13:43
Example of custom form builder (RoR)
class CustomFormBuilder < ActionView::Helpers::FormBuilder
def text_field_with_error_placeholder field_name
text_field field_name, placeholder: (error_message_on field_name).scan(/\>(.*)\</).join(', ').html_safe
end
end
@voidius
voidius / post_put_request_generation.rb
Created February 7, 2014 13:18
Dynamic generation of Post and Put methods using Module.const_get method
# def post
# def put
[:post, :put].each do |type|
define_method type do |url, content|
uri = URI("http://google.com")
request = Module.const_get("Net::HTTP::#{type.capitalize}").new(uri)
request.body = content
Net::HTTP.start(uri.host, uri.port) { |http| http.request(request) }
end
@voidius
voidius / capistrano_rsync.rb
Last active December 9, 2015 13:47
Deploy your local working copy (capistrano >= 3)
# Deploy your local working copy bypassing VCS
#
# Put this file into lib/capistrano/tasks/ and setup, e.g.:
#
# set :rsync_enabled, true
# set :rsync_options, %w[
# --recursive --delete --delete-excluded
# --exclude .git*
# --exclude /test/***
# --exclude /tmp/***
require 'ostruct'
class DeepStruct < OpenStruct
def initialize(hash=nil)
@table = {}
@hash_table = {}
if hash
hash.each do |k,v|
@table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
@voidius
voidius / chrome_auth_server_whitelist.sh
Last active July 25, 2016 07:03
Enable Kerberos SSO in OS X Chrome
defaults write com.google.Chrome AuthServerWhitelist '.domain1.com,.domain2.com'