Skip to content

Instantly share code, notes, and snippets.

View le0pard's full-sized avatar
:octocat:
Simplicity is the soul of efficiency

Oleksii Vasyliev le0pard

:octocat:
Simplicity is the soul of efficiency
View GitHub Profile
@le0pard
le0pard / git_changlog
Created November 19, 2010 11:29
Automatic git changelog
#!/usr/bin/env ruby
SPECIAL_TOKEN = 'SpecialTokenForSearch'
WITHOUT_MERGES = "--no-merges"
GIT_COMMIT_LINK="https://github.com/some_projects/commit/:commit"
cmd = `git show-ref --tags`
tags = []
cmd.each do |l|
tag_commit, tag_name = l.chomp.split(" ")
@le0pard
le0pard / gist:706435
Created November 19, 2010 12:07
Capistrano recipes for update GD after deploy
require "google_spreadsheet"
namespace :deploy do
desc "Notify GD"
task :gd_notify, :except => { :no_release => true } do
rails_env = fetch(:rails_env, "production")
local_user = ENV['USER'] || ENV['USERNAME']
local_branch = fetch(:branch, "HEAD")
SPECIAL_TOKEN = 'SpecialTokenForSearch'
@le0pard
le0pard / gist:733938
Created December 8, 2010 21:25
Image diff on ruby
require 'RMagick'
class ImageDiff
#max = 20
MATRIX = 15
def generate_array(image_path)
result = []
main_img = Magick::Image.read(image_path).first
@le0pard
le0pard / gist:733942
Created December 8, 2010 21:26
image diff on PHP
<?php
class ImageDiff {
// not bigger 20
private $matrix = 20;
public function getImageInfo($image_path){
list($width, $height, $type, $attr) = getimagesize($image_path);
$image_type = '';
@le0pard
le0pard / getconf.sh
Created February 5, 2011 17:13
Simple shmsetup script for PostgreSQL
#!/bin/bash
# simple shmsetup script
page_size=`getconf PAGE_SIZE`
phys_pages=`getconf _PHYS_PAGES`
shmall=`expr $phys_pages / 2`
shmmax=`expr $shmall \* $page_size`
echo kernel.shmmax = $shmmax
echo kernel.shmall = $shmall
@le0pard
le0pard / gist:897131
Created March 31, 2011 20:00
Определите свое местоположение по WiFi сети
iwlist wlan0 scan | sed -n 's/.* Address: //p;T;s/ //g;q' |
sed 's/.*/{version:1.1.0,host:maps.google.com,request_address:true,address_language:'${LANG/.*/}',wifi_towers:[{mac_address:"&",signal_strength:8,age:0}]}/' |
curl -sX POST -d @- www.google.com/loc/json |
sed -e 'h;s/.*latitude":\([^,]*\).*/\1/;G;s/\n[^\n]*longitude":\([^,]*\).*/,\1\n/;s|^|http://maps.google.com/maps?q=|;x;s/[,{]/\n/g;s/["}]//g;s/:/\t/g;s/\n//;G'
@le0pard
le0pard / gist:910674
Created April 8, 2011 20:36
Finding the size of your biggest relations
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_relation_size(C.oid)) AS "size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
LIMIT 20;
@le0pard
le0pard / gist:910696
Created April 8, 2011 20:43
Finding the total size of your biggest tables
SELECT nspname || '.' || relname AS "relation",
pg_size_pretty(pg_total_relation_size(C.oid)) AS "total_size"
FROM pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
AND C.relkind <> 'i'
AND nspname !~ '^pg_toast'
ORDER BY pg_total_relation_size(C.oid) DESC
LIMIT 20;
@le0pard
le0pard / gist:910728
Created April 8, 2011 20:57
Count estimate
CREATE LANGUAGE plpgsql;
CREATE FUNCTION count_estimate(query text) RETURNS integer AS $$
DECLARE
rec record;
rows integer;
BEGIN
FOR rec IN EXECUTE 'EXPLAIN ' || query LOOP
rows := substring(rec."QUERY PLAN" FROM ' rows=([[:digit:]]+)');
EXIT WHEN rows IS NOT NULL;
END LOOP;
@le0pard
le0pard / gist:910749
Created April 8, 2011 21:11
Return default value of field in table
CREATE OR REPLACE FUNCTION ret_def(text,text,text) RETURNS text AS $$
SELECT
COLUMNS.column_default::text
FROM
information_schema.COLUMNS
WHERE table_name = $2
AND table_schema = $1
AND column_name = $3
$$ LANGUAGE sql IMMUTABLE;