Skip to content

Instantly share code, notes, and snippets.

View mhenrixon's full-sized avatar
🐢
I may be slow to respond.

Mikael Henriksson mhenrixon

🐢
I may be slow to respond.
View GitHub Profile

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
# Usage: rake name:task app_name
task PROD = "appname" # "task" here stubs to prevent rake errors with commandline
task STAGING = "appname-staging"
APP = ARGV[1] || PROD # default app
puts "=== APP #{APP} ==="
namespace :deploy do
@mhenrixon
mhenrixon / pg_kill.sh
Last active December 22, 2019 12:20
Kills all connections to postgresql (un)specified database(s)
#!/usr/bin/env bash
# kill all connections to the postgres server
if [ -n "$1" ] ; then
where="where pg_stat_activity.datname = '$1'"
echo "killing all connections to database '$1'"
else
where="where pg_stat_activity.datname in (select datname from pg_database where datname != 'postgres')"
echo "killing all connections to database"
fi
class Refill
attr_reader :card, :product, :prices, :details, :total_price
def initialize(card, product, discount_price = nil)
@card = card
@product = product
@discount_price = discount_price
@prices = product.prices.map(&:price)
@total_price = if product.product_type === 'discount'
set_discount_price
guard 'spork', rspec_env: { 'RAILS_ENV' => 'test' }, cucumber: false, test_unit: false, wait: 60 do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.*\.rb$})
watch(%r{^config/initializers/.*\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
watch('test/test_helper.rb') { :test_unit }
watch(%r{features/support/}) { :cucumber }
require 'json'
class Saltsider
RANKS = ['Script Kid', 'n00b', 'Programmer', 'Rock Star', 'l33t',
'Saltsider']
P_ATTRIBUTES = [:name, :email, :phone]
S_ATTRIBUTES = [:html, :css, :javascript, :ruby, :ruby_on_rails]
def initialize(attributes = {})
gem list --no-version |xargs gem uninstall -ax
@mhenrixon
mhenrixon / group_count.sql
Created February 14, 2013 19:27
How to perform a group count query on a postgresql array column
explain analyze
with tags as (
select unnest(tags) as tag_name from tasks where user_id = 1
) select
count(9),
tag_name
from
tags
group by
tag_name
# The latest version of this script is now available at
# https://github.com/jasoncodes/dotfiles/blob/master/aliases/rbenv.sh
VERSION=1.9.3-p327
brew update
brew install rbenv ruby-build rbenv-vars readline ctags
if [ -n "${ZSH_VERSION:-}" ]; then
echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.zshrc
else
echo 'eval "$(rbenv init - --no-rehash)"' >> ~/.bash_profile
@mhenrixon
mhenrixon / 0-readme.md
Last active December 13, 2015 22:39 — forked from burke/0-readme.md

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.