Skip to content

Instantly share code, notes, and snippets.

def distributed_number(num)
k = 9 # number of distributed groups
start = 216000
stop = 1521368
total = stop - start
((total / k) * (num % k) + num / k) + start - start / k
end
@puffy
puffy / link_regex.rb
Last active April 24, 2019 15:47
Add attributes for html links
" load up pathogen and all bundles
call pathogen#infect()
call pathogen#helptags()
syntax on " show syntax highlighting
filetype plugin indent on
set autoindent " set auto indent
"set smartindent
set nu
@puffy
puffy / ruby_encode_utf8
Created February 10, 2013 14:46
The pretty way to break away of invalid utf-8 byte sequence error in ruby 1.9 # code got from http://robots.thoughtbot.com/post/42664369166/fight-back-utf-8-invalid-byte-sequences
def replace_name(body, name)
body
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
.gsub(/joel/, name)
end
@puffy
puffy / postgresql os x ordering
Created February 11, 2012 16:38
Существует проблема сортировки текстовых полей postgresql на Mac OS X (возможно и FreeBSD, не знаю как сейчас) при использовании мультибайтовой кодировки UTF-8. Здесь приведен один из вариантов решения данной проблемы.
# psql -h localhost postgres
postgres=# create database mydb_test with lc_collate='C';
ERROR: new collation (C) is incompatible with the collation of the template database (ru_RU.UTF-8)
HINT: Use the same collation as in the template database, or use template0 as template.
postgres=# UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';
postgres=# create database mydb_test with lc_collate = 'C' template = template0;