Skip to content

Instantly share code, notes, and snippets.

@barsbek
barsbek / redis_server.sh
Created Oct 7, 2018
daemonize redis-server
View redis_server.sh
redis-server --daemonize yes
@barsbek
barsbek / gist:322e4ab16a8386f1df94ce3fbc02037d
Created Jul 25, 2018
windows: restore dump into postgresql
View gist:322e4ab16a8386f1df94ce3fbc02037d
psql.exe -U postgres -d balloon_development -f D:\temp\db.dump
@barsbek
barsbek / check_multiple.js
Created Jun 10, 2018
check multiple checkboxes while shift key pressed
View check_multiple.js
const checkboxes = document.querySelectorAll('input[type="checkbox"]');
checkboxes.forEach(c => c.addEventListener('click', handleCheck));
let lastChecked = null;
function handleCheck(e) {
let inBetween = false;
if(e.shiftKey && this !== lastChecked) {
checkboxes.forEach(c => {
@barsbek
barsbek / config.bat
Created Jun 9, 2018
change default wsl to ubuntu
View config.bat
// run the command in windows cmd
wslconfig /s Ubuntu
// to show list of installed subsystems
wslconfig /l
@barsbek
barsbek / scale_site.js
Created Jun 6, 2018
scale desktop version depending on device width
View scale_site.js
if( true ) {
var ww = ( $(window).width() < window.screen.width ) ? $(window).width() : window.screen.width; //get proper width
var mw = 1024;
var ratio = ww / mw;
if( ww < mw){
$('#viewport').attr('content', 'initial-scale=' + ratio + ', maximum-scale=' + ratio + ', minimum-scale=' + ratio + ', user-scalable=yes, width=' + ww);
}else{
$('#viewport').attr('content', 'initial-scale=1.0, maximum-scale=2, minimum-scale=1.0, user-scalable=yes, width=' + ww);
}
}
View non_capturing.rb
# regexp
# to create non-capturing group use:
(?:)
# (?:b) matches b without capturing it
@barsbek
barsbek / swiper_carousel.js
Created Apr 21, 2018
bootstrap: add swiper to carousel
View swiper_carousel.js
@barsbek
barsbek / backup.sh
Created Mar 28, 2018
linux: backup device
View backup.sh
# windows 10 goes into hibernation on shutdown. Turn it off in battery settings to make disks C & D writable
dd if=/dev/sdX bs=4K status=progress| gzip -c > /path/to/backup.img.gz
View efficient_divisors.rb
def list_squared(m, n)
divs_hash = {}
(m..n).reduce([]) do |result, i|
sum = 1
divs = [1]
for k in (2..i/2)
if (i % k).zero?
current = (i/k)
if divs_hash.has_key?(current.to_s)
divs_hash[current.to_s].each do |c|
You can’t perform that action at this time.