Skip to content

Instantly share code, notes, and snippets.

View le0pard's full-sized avatar
🕷️
Your friendly neighborhood coder

Oleksii Vasyliev le0pard

🕷️
Your friendly neighborhood coder
View GitHub Profile
@le0pard
le0pard / gist:4048375
Created November 9, 2012 21:28
Unicorn config for chef-solo
app_root = '<%= node['app']['web_dir'] %>'
rails_root = "#{app_root}/current"
rails_env = '<%= node['app']['env'] %>'
pid_file = "#{app_root}/shared/tmp/pids/unicorn.pid"
socket_file= "#{app_root}/shared/tmp/sockets/unicorn.sock"
log_file = "#{rails_root}/log/unicorn.log"
username = '<%= node['user']['name'] %>'
group = '<%= node['user']['name'] %>'
old_pid = "#{pid_file}.oldbin"
@le0pard
le0pard / fix_ssl.rb
Created June 21, 2012 20:17
Fix ssl problem on ruby 1.9
require 'open-uri'
require 'net/https'
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
self.ca_file = Rails.root.join('lib/ca-bundle.crt').to_s
self.verify_mode = OpenSSL::SSL::VERIFY_PEER
@le0pard
le0pard / with index and sorting. 1000000 count
Created April 28, 2012 20:35
Search similar images in PostgreSQL
EXPLAIN ANALYZE SELECT smlar(images.image_array, '{1010259,1011253,1012249,1013251,1014249,1015249,1016247,1017252,1018252,1019251,1020251,1021253,1022258,1023257,1024257,1110258,1111258,1112252,1113251,1114251,1115250,1116247,1117252,1118252,1119252,1120252,1121253,1122257,1123257,1124257,1210258,1211258,1212258,1213253,1214251,1215251,1216248,1217253,1218253,1219253,1220253,1221253,1222253,1223253,1224252,1310258,1311258,1312258,1313258,1314258,1315252,1316248,1317253,1318257,1319257,1320253,1321253,1322257,1323253,1324253,1410258,1411258,1412258,1413258,1414258,1415257,1416250,1417253,1418257,1419257,1420257,1421253,1422257,1423257,1424253,1510258,1511258,1512258,1513258,1514258,1515257,1516251,1517253,1518257,1519253,1520252,1521252,1522252,1523251,1524250,1610258,1611258,1612258,1613258,1614258,1615257,1616252,1617252,1618251,1619250,1620247,1621251,1622251,1623250,1624250,1710258,1711258,1712258,1713258,1714258,1715257,1716252,1717257,1718257,1719257,1720252,1721253,1722252,1723253,1724253,1810258,18112
@le0pard
le0pard / gist:2521710
Created April 28, 2012 20:06
Generate digital signature for image on php and compare
<?php
class ImageDiff {
// not bigger 20
private $matrix = 15;
public function getImageInfo($image_path){
list($width, $height, $type, $attr) = getimagesize($image_path);
$image_type = '';
@le0pard
le0pard / gist:2521687
Created April 28, 2012 20:01
Generate digital signature for image on ruby and compare
require 'RMagick'
require 'yaml'
class ImageDiff
#max = 20
MATRIX = 15
def generate_array(image_path)
result = []
@le0pard
le0pard / gist:2500488
Created April 26, 2012 15:45
If you want to prevent dragging on iphone
function preventBehavior(e) {
e.preventDefault();
};
document.addEventListener("touchmove", preventBehavior, false);
@le0pard
le0pard / gist:2002829
Created March 8, 2012 19:20
app.js generated content
 var couchapp = require('couchapp')
, path = require('path')
;
ddoc =
{ _id:'_design/app'
, rewrites :
[ {from:"/", to:'index.html'}
, {from:"/api", to:'../../'}
, {from:"/api/*", to:'../../*'}
@le0pard
le0pard / 0-readme.md
Created February 21, 2012 21:58 — forked from burke/0-readme.md
ruby-1.9.3-p125 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@le0pard
le0pard / gist:1571839
Created January 6, 2012 18:40
Erlang factorial
-module(recursive).
-export([fac/1, tail_fac/1]).
fac(N) when N == 0 -> 1;
fac(N) when N > 0 -> N*fac(N-1).
tail_fac(N) -> tail_fac(N,1).
tail_fac(0,Acc) -> Acc;
tail_fac(N,Acc) when N > 0 -> tail_fac(N-1,N*Acc).
@le0pard
le0pard / gist:1234632
Created September 22, 2011 12:09
rails 3.1 initializable list
handle_lib_autoload: 0.000 sec
set_load_path: 0.001 sec
set_load_path: 0.001 sec
set_load_path: 0.001 sec
set_load_path: 0.000 sec
set_load_path: 0.001 sec
set_autoload_paths: 0.000 sec
set_autoload_paths: 0.000 sec
set_autoload_paths: 0.000 sec
set_autoload_paths: 0.000 sec