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: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 / 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: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: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 / 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 / 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 / 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"
# ROUTER
GWS.Router.map (match) ->
#match("/").to("home") # home.handlebars gets rendered automatically and mapped to /
# according to guide the previous logic shouldn't be needed. but it won't work without it
# you can either use model: () -> or
# setupController: (controller, model) ->
# controller.set 'content', model
@le0pard
le0pard / scout_simple_check_ssl.rb
Last active December 16, 2015 09:49
This scout plugin give info about ssl cert, which installed on web server. You can create trigger, which will notify before ssl cert expired.
require 'net/https'
require 'uri'
class SimpleSslCheckPlugin < Scout::Plugin
OPTIONS=<<-EOS
url:
default: https://localhost
EOS
def build_report
@le0pard
le0pard / pg_bloat.sql
Last active August 29, 2015 14:01
PG table and indexes bloat
WITH constants AS (
SELECT current_setting('block_size')::numeric AS bs, 23 AS hdr, 4 AS ma
), bloat_info AS (
SELECT
ma,bs,schemaname,tablename,
(datawidth+(hdr+ma-(case when hdr%ma=0 THEN ma ELSE hdr%ma END)))::numeric AS datahdr,
(maxfracsum*(nullhdr+ma-(case when nullhdr%ma=0 THEN ma ELSE nullhdr%ma END))) AS nullhdr2
FROM (
SELECT
schemaname, tablename, hdr, ma, bs,