Skip to content

Instantly share code, notes, and snippets.

View bsa7's full-sized avatar

Belevskij Sergeij bsa7

View GitHub Profile
@bsa7
bsa7 / redis_on_rails.rb
Last active August 29, 2015 14:01
Redis+Rails essential
#connect to redis database (place at config/initializers/redis.rb)
$redis = Redis.new(host: 'localhost', port: 6379, db: 1)
#read hash values from json file:
ru_json = File.read("ru-RU.json")
en_json = File.read("en.json")
cn_json = File.read("zh-CN.json")
ar_json = File.read("ar-EG.json")
#Set hash value in db:
@bsa7
bsa7 / inject.rb
Created June 10, 2014 02:42
Ruby inject
n=10
(1..n).inject(:*) || 1
## 1 ######### 2 #### 3
#1. this is a enum object
#2. Do an operation (*) with accumulated result and next element - 1..3: res = 1 * 2 * 3
#3. this is a foolprof - if an enum object is nil, result alway be the 1
@bsa7
bsa7 / links.markdown
Last active August 29, 2015 14:02
mail in rails
@bsa7
bsa7 / mailman.rb
Created June 12, 2014 12:39
ruby - mailman init
#!/usr/bin/env ruby
require 'colorize'
require 'rubygems'
require 'bundler/setup'
require 'mailman'
Mailman.config.maildir = 'Mail'
Mailman.config.poll_interval = 5
Mailman.config.logger = Logger.new('log/mailman.log')
@bsa7
bsa7 / hint.markdown
Created June 16, 2014 14:52
tightvnc-jviewer.jar - exit fullscreen
  1. close viewer
  2. in registry key \Software\JavaSoft\Prefs\com\glavsoft\viewer\connections/History\0 delete value ui...
  3. run viewer again
@bsa7
bsa7 / hint.markdown
Last active August 29, 2015 14:02
xenserver: detect vnc port of vm

select your vm:

xe vm-list

detect id of dom of its vm:

xe vm-param-list uuid=8e2dd6ac-4883-0e6e-5cce-afbf214fa916 | grep dom-id

read vnc port by that dom_id:

@bsa7
bsa7 / hint.markdown
Last active August 29, 2015 14:02
bash echo color
@bsa7
bsa7 / command
Created June 22, 2014 15:28
unicorn start
unicorn -c config/unicorn.rb
@bsa7
bsa7 / tar_and_untar.markdown
Last active August 29, 2015 14:02
tar && untar directory

tar: tar -zcvf archive_name.tar.gz dir_name

untar: tar -zxvf file.tar.gz

@bsa7
bsa7 / trick.markdown
Last active August 29, 2015 14:02
git change file in index locally

example, if you want to change gitignore, but only in your local repo, do next:

git update-index --assume-unchanged .gitignore