Skip to content

Instantly share code, notes, and snippets.

View sseletskyy's full-sized avatar
🍊
FP mood

Sergiy Seletskyy sseletskyy

🍊
FP mood
View GitHub Profile
@sseletskyy
sseletskyy / index.js
Last active September 21, 2016 10:09
quick performance test of the function in js
var testF = function(func, args){
var counter = 100000, i = counter, startTimer, endTimer;
startTimer = performance.now();
for(;i>0;i--) {
func.apply(null, args);
}
endTimer = performance.now();
return (endTimer - startTimer) / counter;
}
@sseletskyy
sseletskyy / local_storage.js
Created September 5, 2016 07:35
How to find the size of localStorage
// Execute this snippet in Chrome console
var _lsTotal=0,_xLen,_x;for(_x in localStorage){_xLen= ((localStorage[_x].length + _x.length)* 2);_lsTotal+=_xLen; console.log(_x.substr(0,50)+" = "+ (_xLen/1024).toFixed(2)+" KB")};console.log("Total = " + (_lsTotal / 1024).toFixed(2) + " KB");
// or add this text in the field 'location' of a bookmark for convenient usage
javascript: var x, xLen, log=[],total=0;for (x in localStorage){xLen = ((localStorage[x].length * 2 + x.length * 2)/1024); log.push(x.substr(0,30) + " = " + xLen.toFixed(2) + " KB"); total+= xLen}; if (total > 1024){log.unshift("Total = " + (total/1024).toFixed(2)+ " MB");}else{log.unshift("Total = " + total.toFixed(2)+ " KB");}; alert(log.join("\n"));
//P.S. Snippets are updated according to request in the comment. Now the calculation includes the length of the key itself. Each length is multiplied by 2 because the char in javascript stores as UTF-16 (occupies 2 bytes)
@sseletskyy
sseletskyy / tmux-cheatsheet.markdown
Created July 25, 2016 10:20 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
describe ArticlesController do
describe "inactive article" do
let(:article) { double(:article, active?: false, id: 1) }
before(:each) do
allow(Article).to receive(:find) { article }
end
@sseletskyy
sseletskyy / deploy.rake
Last active December 15, 2015 21:40 — forked from jphenow/deploy.rake
improved heroku deploy rake task
#Deploy and rollback on Heroku in staging, production, dev and test environments
require 'tempfile'
# for capturing error in 'git push'
def capture_stderr
stderr = $stderr.dup
Tempfile.open 'stderr-redirect' do |temp|
$stderr.reopen temp.path, 'w+'
yield if block_given?
# Deploy and rollback script for Heroku on staging and/or production
# Modified from: https://gist.github.com/njvitto/362873
namespace :deploy do
PRODUCTION_APP = 'YOUR_PRODUCTION_APP_NAME_ON_HEROKU'
STAGING_APP = 'YOUR_STAGING_APP_NAME_ON_HEROKU'
desc 'Deploy to Staging on Heroku'
task :staging => ['deploy:set_staging_app', 'deploy:push', 'deploy:restart', 'deploy:tag']
desc 'Deploy to Production on Heroku'
@sseletskyy
sseletskyy / erb2slim
Created February 8, 2014 07:50
how to convert html to slim
>gem install html2slim
in case of using .rbenv don't forget to set path in bash_profile
>> PATH=${PATH}:~/.rbenv/versions/2.0.0-p353/bin/
>for file in app/views/devise/**/*.erb; do erb2slim $file ${file%erb}slim && rm $file; done
@sseletskyy
sseletskyy / notes
Created December 23, 2013 12:36
Subdomains
lvh.me - subdomain.lvh.me
@sseletskyy
sseletskyy / update_sequences.sql
Created December 4, 2013 14:28
UPDATE ALL SEQUENCES
--This is a handy PostreSQL script to fix sequences for all tables at once
SELECT 'SELECT SETVAL(' ||quote_literal(quote_ident(S.relname))|| ', MAX(' ||quote_ident(C.attname)|| ') ) FROM ' ||quote_ident(T.relname)|| ';'
FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C
WHERE S.relkind = 'S'
AND S.oid = D.objid
AND D.refobjid = T.oid
AND D.refobjid = C.attrelid
AND D.refobjsubid = C.attnum
ORDER BY S.relname;