Skip to content

Instantly share code, notes, and snippets.

View hakanensari's full-sized avatar

Hakan Ensari hakanensari

  • Amsterdam
  • 14:45 (UTC +02:00)
View GitHub Profile
@hakanensari
hakanensari / request.rb
Last active August 29, 2015 13:57
Minimal Ruby interface for the Amazon MWS API
require 'jeff'
module MWS
class Request
include Jeff
HOSTS = {
'A2EUQ1WTGCTBG2' => 'mws.amazonservices.ca',
'AAHKV2X7AFYLW' => 'mws.amazonservices.com.cn',
'A1PA6795UKMFR9' => 'mws-eu.amazonservices.com',
require 'benchmark'
require './lib/excon'
include Excon
uris = {
'Good URI' => "http://example.org/#{'foo/' * 10}?#{10.times.map { 'bar=baz' }.join('&')}",
'Bad URI' => "http://example.org/#{'foo /' * 10}?#{10.times.map { 'bar=baz' }.join('&')}"
}
#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
#!/usr/bin/ruby -w
require 'digest/md5'
filename = 'MD5.rdoc'
all_digest = Digest::MD5.hexdigest(File.read(filename))
incr_digest = Digest::MD5.new()
file = File.open(filename, 'r')
file.each_line do |line|
incr_digest << line
# config/initializers/sidekiq.rb
if Sidekiq.server?
config = ActiveRecord::Base.connection.pool.spec.config
ActiveRecord::Base.establish_connection(config.merge(pool: Sidekiq.options.fetch(:concurrency)))
end
/* How to calculate postgreSQL database size in disk ? */
SELECT pg_size_pretty(pg_database_size('thedbname'));
/* Calculate size of a table including or excluding the index */
SELECT pg_size_pretty(pg_total_relation_size('big_table'));
SELECT pg_size_pretty(pg_relation_size('big_table')); /* without index */
/* See indexes on a table with `\d tablename` */
@hakanensari
hakanensari / remount.md
Created May 10, 2013 07:06
You are on OVH, have gone with the default layout on a box, and now realise you'd rather mount differently.
  1. Make sure you allow root to ssh in: Edit your /etc/ssh/sshd_config, add your public key to root's authorised keys, and so on.
  2. Move home, e.g. mv /home /home.bak.
  3. Comment out the line that mounts home in /etc/fstab.
  4. Reboot.
  5. Rename home.bak back to home.
  6. Stop PostgreSQL.
  7. mv /var/lib/postgresql /var/lib/postgresql.bak.
  8. Edit /etc/fstab, remove comment and replace /home with /var/lib/postgresql.
  9. Create /var/lib/postgresql with chown it to postgres:postgres.
  10. Mount it.
@hakanensari
hakanensari / 1_create_products.rb
Created April 30, 2013 23:47
Sequel + uuid-ossp
Sequel.migration do
up do
run 'CREATE EXTENSION "uuid-ossp"'
create_table :products do
column :id, :uuid, :default => Sequel.function(:uuid_generate_v4), :primary_key => true
end
end
end
#!/bin/sh
filename=$1
echo "Begin processing file:" $filename
dimensions=$(identify -format '%w %h' $filename)
IFS=' ' read -a array <<< "$dimensions"
width=${array[0]}
height=${array[1]}