Skip to content

Instantly share code, notes, and snippets.

@begin29
begin29 / ruby_mini_test.sh
Created May 9, 2017 10:37
mini test commands
# run specific test
ruby my_test -n test_my_test
@begin29
begin29 / i3_settings.sh
Last active May 17, 2017 10:20
i3 related settings
# linux symbols
http://panmental.de/symbols/info.htm
#shows special keys matching(alt, ctrl, win)
xmodmap
# for windows, setup diff windows on start
https://faq.i3wm.org/question/243/how-do-i-use-an-exclude-regex-in-i3-config/%3C/p%3E.html
# back workspace to external monitor
@begin29
begin29 / passenger_rails.rb
Created March 2, 2017 09:16
passenger commands
# always restart code like in development
touch tmp/always_restart.txt
# restart only once
touch tmp/restart.txt
@begin29
begin29 / remove_untracked.sh
Created February 9, 2017 08:14
git remove untraked files
# show files that will be removed
git clean -n
# remove files
git clean -f
#To remove directories, run
git clean -f -d #or git clean -fd
#To remove ignored files, run
git clean -f -X #or git clean -fX
#To remove ignored and non-ignored files, run
git clean -f -x #or git clean -fx
@begin29
begin29 / figure_task_from_denys.rb
Created February 7, 2017 19:54
figure task from Denys
class Figure
attr_reader :radius
def initialize(color,radius)
@color = color
@radius = radius
raise "first argument needs to be a string" unless color.class == String
raise "second argument needs to be a fixnum" unless radius.class == Fixnum
end
@begin29
begin29 / remote_access_via_vnc.sh
Created January 8, 2017 11:39
remote access to linux via vnc
http://www.junauza.com/2010/04/remote-control-your-linux-desktop-using.html
# if auth error 18 happends
# need to allow plain auth for clients
gsettings set org.gnome.Vino require-encryption false
@begin29
begin29 / grep_useful.sh
Last active February 24, 2017 08:10
grep useful functions
# search `pattern name` recursivelly from current folder
# only in css files
grep --include=\*.css -rnw ./ -e "pattern name"
# search word error
grep -i error /var/log/kern.log
@begin29
begin29 / indexes.rb
Created December 23, 2016 16:57
indexes, when should add index
# show indexes
show INDEXES from table_name
when I should add index?
#when selectivity is big
selectivity = count of variations/all rows * 100%
#selectivity for sex column is low: sel_of_sex = 2(male, female)/10000 *100 = 0.02%
#http://www.programmerinterview.com/index.php/database-sql/selectivity-in-sql-databases/
@begin29
begin29 / get_request_via_ruby.rb
Created December 23, 2016 09:42
sample of get request via ruby
require 'net/http'
str = "https://some_cool_url"
uri = URI.parse(str)
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
http.use_ssl = true
response = http.request(request)
p response.body
@begin29
begin29 / simple_benchmark.rb
Created December 23, 2016 09:36
simple benchmark 2 ruby methods
require 'benchmark'
iterations = 100_000
Benchmark.bm(27) do |bm|
bm.report('finding in hash') do
iterations.times do
arr.find{|h| h['start_date'] == '2018'}
end
end