Skip to content

Instantly share code, notes, and snippets.

@litvil
litvil / gist:84662a0a4e50bee5a13f1626990ecc3c
Created March 27, 2017 02:04 — forked from bds/gist:2207826
Convert files from .scss to .sass
sass-convert -F scss -T sass application_styles.css.scss application_styles.css.sass
Git Tips & Tricks
Add your best Git tricks here!
Share the love!
The "I can never remember that alias I set" Trick
[alias]
aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /' | sort
AES is a block-level algorithm. So when data encrypted it is padded. So you can calculate the length of the result string using this formula:
1
16 × (trunc(string_length / 16) + 1)
So if your address field structure is = VARCHAR(100) ; //100 length of varchar
Then before your encryption it should be converted
= 16 * (trunc(100/ 16) + 1)
= 16 * (6.25 + 1)
= 16 * 7.25
= 116
@litvil
litvil / gist:32c5e3bd113fc198e536f27891d8f82c
Last active December 15, 2016 15:11
GIT: list all brunches sorted by age
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@litvil
litvil / center-in-div.scss
Created August 17, 2016 14:46
center content horizontaly and verticaly
.cnt-top{
display: table;
height: 100%;
width: 100%;
text-align: center;
.cnt-middle{
display: table-cell;
vertical-align: middle;
.cnt-inner{
margin-left: auto;
@litvil
litvil / deploy.rake
Created May 10, 2016 15:01 — forked from amejiarosario/deploy.rake
Rakefile to deploy and rollback to Heroku in two different environments (staging and production) for the same app, tail logs, ps, and more!
# rake deploy # Push app to heroku:production, migrate, restarts and tail logs
# rake deploy:production # Push app to production, migrate, restarts, tag and tail logs
# rake deploy:production:config # production config
# rake deploy:production:console # production console
# rake deploy:production:logs # production logs
# rake deploy:production:ps # production ps
# rake deploy:production:releases # production releases
# rake deploy:staging # Push app to staging, migrate, restarts, tag and tail logs
# rake deploy:staging:config # staging config
# rake deploy:staging:console # staging console
@litvil
litvil / stub_request.rb
Created April 25, 2016 22:28
Stub external request with Rspec
stub_request(:get, /some_host:9999/).with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).to_return(status: 200, body: "stubbed response", headers: {})
@litvil
litvil / lear_all_postgresql_tables.rb
Created March 12, 2016 18:27
Clear all tables script postgresql
def trancate
conn = ActiveRecord::Base.connection
tables = conn.execute("SELECT * FROM pg_catalog.pg_tables WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema' AND tablename != 'schema_migrations'").map { |r|
r['tablename']
}
p 'Trancate '+tables.join(',').to_s
tables.each { |t|
conn.execute("TRUNCATE #{t}")
}
end
@litvil
litvil / anagram.rb
Created January 23, 2016 21:15
Creates regullar exp for anagram
def anagram(input)
lookaheadPart = ''
matchingPart = '^'
positiveLookaheadPrefix='(?='
positiveLookaheadSuffix=')'
letters = input.to_s.split('')
inputCharacterFrequencyMap = letters.reduce(Hash.new(0)) { |a, b| a[b] += 1; a }
inputCharacterFrequencyMap.each do |letter, freq|
lookaheadPart += positiveLookaheadPrefix;