Skip to content

Instantly share code, notes, and snippets.

@patsanch
patsanch / passenger-management.rb
Created April 6, 2016 17:49 — forked from loopj/passenger-management.rb
Checks memory usage of all paseenger child process and kill if grows too large. Additionally kill off long running passengers to prevent memory leak issues (similar to the PassengerMaxRequests config variable in apache's passenger version, but works on bo
#!/usr/bin/env ruby
#
# Passenger management script
# By James Smith http://loopj.com
# Based heavily on a similar script by Jon Bettcher
#
# Check memory usage of all paseenger child process and kill if grows
# too large.
#
@patsanch
patsanch / db_server.rb
Created January 16, 2016 01:05 — forked from exoer/db_server.rb
Create postgres users and databases from Chef
include_recipe "postgresql::server90"
# inspiration from
# https://gist.github.com/637579
execute "create-root-user" do
code = <<-EOH
psql -U postgres -c "select * from pg_user where usename='root'" | grep -c root
EOH
command "createuser -U postgres -s root"
@patsanch
patsanch / yaml_to_json.rb
Created November 4, 2015 00:44 — forked from xiaohanyu/yaml_to_json.rb
convert yaml to json in ruby
require 'json'
require 'yaml'
input_filename = ARGV[0]
output_filename = input_filename.sub(/(yml|yaml)$/, 'json')
input_file = File.open(input_filename, 'r')
input_yml = input_file.read
input_file.close
t = 236 # seconds
Time.at(t).utc.strftime("%H:%M:%S")
=> "00:03:56"
# Reference
# http://stackoverflow.com/questions/3963930/ruby-rails-how-to-convert-seconds-to-time
# TODO can be optimized to use custom class and `model_ids` method
module SortPhotos
def sort_photos!(ids)
raise ArgumentError, "ids isn't an array" if !ids.is_a?(Array)
ids.map!(&:to_i)
old_ids = self.photo_ids
ids = ids - (ids - old_ids)
raise ArgumentError, "Not all the ids were passed to sort! method" if old_ids.size != ids.size
reflections[:photos].klass.update_all(['position = FIND_IN_SET(id, ?)', ids.join(',')], {:id => ids})
@patsanch
patsanch / 01_step.sh
Last active August 29, 2015 14:07 — forked from Mikke/01_step.sh
rails g scaffold Book title:string description:text
rails g scaffold Pubhouse title:string address:text
rails g model BookPubhouse book_id:integer pubhouse_id:integer
rake db:migrate
@patsanch
patsanch / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@patsanch
patsanch / as3.rake
Created September 4, 2013 22:28 — forked from otobrglez/as3.rake
# 1) Put 's3' gem in Gemfile.
# 2) Create as3.yml configuration for S3
# 3) Create initializer for as3.yml
# 4) Make "assets" folder inside your bucket
# 5) After running task run "RAILS_ENV=production rake assets:precompile"
# 6) Invoke task by running "rake as3:upload"
namespace :as3 do
desc "Uploads compiled assets (public/assets) to Amazone AS3"
task :upload do