Skip to content

Instantly share code, notes, and snippets.

View dmitry-ilyashevich's full-sized avatar

Dzmitry Ilyashevich dmitry-ilyashevich

View GitHub Profile
@dmitry-ilyashevich
dmitry-ilyashevich / post-checkout
Created June 28, 2012 12:45 — forked from oivoodoo/post-checkout.rb
post-checkout for changing database name in rails projects. place this file into .git/hooks folder.
#!/usr/bin/ruby
require 'yaml'
class Database
attr_reader :config_file, :settings
def initialize
@config_file = File.expand_path(File.join(File.dirname(__FILE__), "../../config/database.yml"))
@dmitry-ilyashevich
dmitry-ilyashevich / input.scss
Created December 5, 2011 06:34 — forked from twe4ked/input.scss
FREE! Sass (SCSS) mixin for including retina images (useful when developing for iOS).
@mixin background-image-retina($file, $type, $width, $height) {
background-image: url($file + '.' + $type);
@media (-webkit-min-device-pixel-ratio: 2) {
& {
background-image: url($file + '@2x.' + $type);
-webkit-background-size: $width $height;
}
}
}
@dmitry-ilyashevich
dmitry-ilyashevich / fixBrewLionPostgres.sh
Created November 15, 2011 17:48
Brew Install Postgresql on OS X Lion
BREW_POSTGRES_DIR=`brew info postgres | awk '{print $1"/bin"}' | grep "/postgresql/"`
LION_POSTGRES_DIR=`which postgres | xargs dirname`
LION_PSQL_DIR=`which psql | xargs dirname`
sudo mkdir -p $LION_POSTGRES_DIR/archive
sudo mkdir -p $LION_PSQL_DIR/archive
for i in `ls $BREW_POSTGRES_DIR`
do
if [ -f $LION_POSTGRES_DIR/$i ]
@dmitry-ilyashevich
dmitry-ilyashevich / snippets.js
Created November 1, 2011 18:57
Snippets for Javascript
$.extend({ max: function(a, b) { return a > b ? a : b; } });
@dmitry-ilyashevich
dmitry-ilyashevich / imagick.sh
Created September 18, 2011 06:53
ImageMagick snippets
# Convert to grayscale, keep transparency
convert image.png -colorspace gray image-gray.png
(function($) {
var minimumTime = 1000; // minimum ms between events
var canFireEvent = true;
function myTimedEvent() {
if (canFireEvent) {
canFireEvent = false;
window.setTimeout(function() {
canFireEvent = true;
}, minimumTime);
executeFunction();
require 'json'
class Hash
def deep_merge(tree)
merger = proc { |key,v1,v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 }
self.merge(tree, &merger)
end
end
class HashStorage
@dmitry-ilyashevich
dmitry-ilyashevich / install-rails-ruby-1.9.2.sh
Created January 21, 2011 20:37
Installing rails on rvm ruby 1.9.2
#!/bin/bash
# created by Josh Frye | joshfng@gmail.com
# Check if the user has sudo privileges.
sudo -v >/dev/null 2>&1 || { echo $(whoami) has no sudo privileges ; exit 1; }
# Update the system before going any further
echo "Updating system..."
sudo apt-get update >> install.log && sudo apt-get -y upgrade >> ~/install.log
echo "done.."
require 'rubygems'
require 'rmagick'
require 'color_namer'
img = Magick::ImageList.new('photo.jpg')
img.resize_to_fit!(500) # resize the image to have faster quantization
quantized = img.quantize(16) # quantize the photo to reduce number of colors
img.destroy! # prevent memory leaks