start new:
tmux
start new with session name:
tmux new -s myname
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; | |
} |
// 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) |
=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 |
#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' |
>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 |
lvh.me - subdomain.lvh.me | |
--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; |