Skip to content

Instantly share code, notes, and snippets.

View bsa7's full-sized avatar

Belevskij Sergeij bsa7

View GitHub Profile
@bsa7
bsa7 / dump object.js
Created February 21, 2016 20:00
Iterate object keys
t = document.getElementById(elementid)
for(var key in t) {console.log('key: ' + key + '\n' + 'value: ' + t[key]);}
@bsa7
bsa7 / combination and permutation.rb
Last active February 21, 2016 18:17
number of combination and permutation from n symbols in string of k length
def f(n) # factorial
(1..n).to_a.inject{|x,y|x = x * y}
end
n = (('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a).length
k = 8
puts "n = #{n}, k = #{k}"
# 1. Combination with repetition
number_with_repetitions = f(n+k-1) / (f(k) * f(n-1))
@bsa7
bsa7 / make_sql_user
Created February 12, 2016 12:38
bash script for create Rails database and user, using settings from config/database.yml file
#!/bin/bash
if [ ! -f config/database.yml ]
then
echo -e "\e[0;32m error:\e[0m"
echo "put me in root of Rails app."
echo "and define your config/database.yml file"
exit
fi
@bsa7
bsa7 / ru.yml
Created January 31, 2016 21:21
Countries Russian I18n translations
ru:
countries:
AC: о-в Вознесения
AD: Андорра
AE: ОАЭ
AF: Афганистан
AG: Антигуа и Барбуда
AI: Ангилья
AL: Албания
AM: Армения
@bsa7
bsa7 / ru.yml
Created January 31, 2016 21:20
Russia subjects I18n translations
ru:
states:
AD: Адыгея. Южный федеральный округ
AL: Алтай. Сибирский федеральный округ
ALT: Алтайский край. Сибирский федеральный округ
AMU: Амурская область. Дальневосточный федеральный округ
ARK: Архангельская область. Северо-Западный федеральный округ
AST: Астраханская область. Южный федеральный округ
BA: Башкортостан. Приволжский федеральный округ
BEL: Белгородская область. Центральный федеральный округ
@bsa7
bsa7 / spree-api-rest-examples.md
Created January 29, 2016 05:36 — forked from jcowhigjr/spree-api-rest-examples.md
Spree API REST Examples

Products

index of products 25 first

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products.json

Show a product

curl -i -H "X-Spree-Token: YOUR_TOKEN_ID" http://0.0.0.0:3000/api/products/706676762.json

Modify a product

curl -i -X PUT -H "X-Spree-Token: YOUR_TOKEN_ID" -d "product[name]=Headphones" http://0.0.0.0:3000/api/products/706676762.json

@bsa7
bsa7 / bash.sh
Created October 9, 2015 10:29
recursive set proper mode for files and folders
sudo find . -type f -exec chmod 644 {} \;
sudo find -type d -exec chmod 755 {} \;
@bsa7
bsa7 / commands.markdown
Last active October 3, 2015 01:44
XEN XCP vm Autostart

Enable autostart of vm in XEN XCP pool

  1. Get the pool uuid:

xe pool-list
@bsa7
bsa7 / gist:41d628635d2dc28025ff
Created September 22, 2015 06:38
skype disable supernode.reg
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Skype]
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Skype\Phone]
“DisableSupernode”=dword:00000001
@bsa7
bsa7 / http_response_clean.rb
Last active September 21, 2015 04:34
clean ruby http response from unsupportes symbols
def cleaned_content body
begin
cleaned = body.dup.force_encoding('UTF-8')
unless cleaned.valid_encoding?
cleaned = body.encode('UTF-8', 'Windows-1251')
end
content = cleaned
rescue EncodingError
content = body.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '').encode("utf-8")
end