Skip to content

Instantly share code, notes, and snippets.

@rxqd
rxqd / ip_address.rb
Created October 14, 2012 09:40
Controller action as big logic
def destroy
ip_address = Onapp::IpAddressJoin.find params[:id]
virtual_machine = ip_address.virtual_machine
path = virtual_machine_ip_address_joins_path(virtual_machine)
result = ip_address.api_delete
if result.body.errors
redirect_to(path, alert: result.body.errors.join(', '))
else
vm.reboot if params[:need_reboot]
@rxqd
rxqd / README.md
Last active December 23, 2015 00:09 — forked from agnoster/README.md

agnoster-two-lines.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

For Mac users, I highly recommend iTerm 2 + Solarized Dark

@rxqd
rxqd / usa_states.rb
Last active August 29, 2015 14:19
USA states
def us_states
[
['AK', 'AK'],
['AL', 'AL'],
['AR', 'AR'],
['AZ', 'AZ'],
['CA', 'CA'],
['CO', 'CO'],
['CT', 'CT'],
['DC', 'DC'],
@rxqd
rxqd / convert
Created May 25, 2015 11:26
Convert ruby 1.8 hashes to 1.9 format for all files
find . -name \*.rb -exec perl -p -i -e 's/([^:]):(\w+)\s*=>/\1\2:/g' {} \;
@rxqd
rxqd / gist:759efba82eb1ce638d43
Created May 28, 2015 14:36
Convert rails erb views to haml or slim
gem install html2haml
for file in app/views/**/*.html.erb; do html2haml -e $file ${file%erb}haml && rm $file; done
gem install html2slim
for file in app/views/**/*.html.erb; do erb2slim $file ${file%erb}slim && rm $file; done
@rxqd
rxqd / puma.rb
Created June 2, 2015 10:17
Puma default config
workers ENV.fetch('WEB_CONCURRENCY') { 2 }.to_i
threads_count = ENV.fetch('MAX_THREADS') { 5 }.to_i
threads threads_count, threads_count
rackup DefaultRackup
port ENV.fetch('PORT') { 3000 }
environment ENV.fetch('RACK_ENV') { 'development' }
preload_app!
on_worker_boot do
@rxqd
rxqd / gist:d94b8c40e925b9ebf262
Created June 4, 2015 08:29
Git diff and apply
You can apply the patch as a 3-way merge:
git diff 13.1_dev sale_edit > patch.diff
git apply -3 patch.diff
It should bring up the conflict so that you can resolve manually. Or you could go with a one-liner, piping the patch to git-apply directly:
git diff 13.1_dev sale_edit | git apply -3
To reverse the patch:
git diff 13.1_dev sale_edit | git apply -3 -R
@rxqd
rxqd / post-commit
Created October 21, 2015 07:17
Git push on commit
#!/bin/sh
git push origin master
@rxqd
rxqd / ruby_install
Created June 9, 2017 07:40
Rbenv install ruby 2.2.2 in ArchLinux with patched SSLv3 and OpenSSL 1.0 without RDoc
curl -fsSL https://gist.github.com/mislav/055441129184a1512bb5.txt | RUBY_CONFIGURE_OPTS="--disable-install-doc" PKG_CONFIG_PATH=/usr/lib/openssl-1.0/pkgconfig rbenv install --patch 2.2.2