Skip to content

Instantly share code, notes, and snippets.

View shospodarets's full-sized avatar

Serg Hospodarets shospodarets

View GitHub Profile
@shospodarets
shospodarets / Chrome headless Puppeteer- capture DOM element screenshot using
Last active January 17, 2023 18:52
Chrome headless Puppeteer- capture DOM element screenshot using
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Adjustments particular to this page to ensure we hit desktop breakpoint.
page.setViewport({width: 1000, height: 600, deviceScaleFactor: 1});
await page.goto('https://www.chromestatus.com/samples', {waitUntil: 'networkidle'});
@shospodarets
shospodarets / remove-merged-branches-to-the-current.sh
Last active May 2, 2017 11:15
Remove Git branches, which are merged to the current one (+ ability to exclude some of them)
#!/usr/bin/env bash
# based on https://gist.github.com/schacon/942899
# list
git branch -r --merged | grep origin | grep -v '>' | grep -v master\* | grep -v release-\* | xargs -L1
# delete
git branch -r --merged | grep origin | grep -v '>' | grep -v master\* | grep -v release-\* | xargs -L1 | awk '{sub(/origin\//,"");print}' | xargs git push origin --delete
@shospodarets
shospodarets / .htaccess
Created February 15, 2017 16:29 — forked from darcyliu/.htaccess
Apache GZIP compression and Expires headers
# BEGIN GZIP
# http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
<IfModule mod_deflate.c>
# Enabling Compression
SetOutputFilter DEFLATE
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
@shospodarets
shospodarets / gist:f300a5f804f62e37392864ce2f0b733c
Created December 28, 2016 23:34
Push failed: Failed with error: unable to access 'https://github.com/USERNAME/REPO.git/': The requested URL returned error: 403
https://help.github.com/articles/changing-a-remote-s-url/
$ vim .git/config
change:
https://github.com/USERNAME/OTHERREPOSITORY.git
to:
git@github.com:USERNAME/OTHERREPOSITORY.git
@shospodarets
shospodarets / killProcessByPort.js
Created December 18, 2016 16:28
Script takes the port as a param and tries to find and kill a process which is listening the port, e.g. `node killProcessByPort.js 8080`
#!/usr/bin/env node
/**
* Script takes the port as a param and tries to find and kill a process
* which is listening the port
*
* Example of the script usage:
* node SCRIPT %PORT_NUMBER%
*/
@shospodarets
shospodarets / delete-local-branches-except-the-current.sh
Last active May 2, 2017 11:16
Delete all the local Git branches except the current one
#!/usr/bin/env bash
git branch | grep -v (git rev-parse --abbrev-ref HEAD) | xargs git branch -D
@shospodarets
shospodarets / clearport.sh
Last active August 5, 2016 14:04
Script to kill all the processes which established connection to the port.Usage: './checkport.sh 35729' (clear the livereload port)
#!/usr/bin/env bash
function terminate {
echo ':'$1
lsof -P | grep ':'$1 | awk '{print $2}' | xargs kill -9
}
terminate $1
@shospodarets
shospodarets / Find unused SCSS variables
Last active December 28, 2017 14:24
Script finds all SCSS variables (e.g. $some_variable-NAME1) which are used in code only once (e.g. declaration or using variable from some framework). Tested on MAC and Linux.
#!/usr/bin/env bash
# HOW TO USE
# Save code to file
# Run as "SCRIPT_FILE_NAME SASS_DIRECTORY"
# e.g "./find_unused_variables.sh ./sass"
VAR_NAME_CHARS='A-Za-z0-9_-'
find "$1" -type f -name "*.scss" -exec grep -o "\$[$VAR_NAME_CHARS]*" {} ';' | sort | uniq -u
@shospodarets
shospodarets / Native JavaScript promises API
Last active September 26, 2016 12:47
Description of the native JavaScript promises API with examples
// Current browser support for native promises: http://kangax.github.io/compat-table/es6/#Promise
// Article: http://www.html5rocks.com/en/tutorials/es6/promises/
// Polyfills:
// https://github.com/getify/native-promise-only
// https://github.com/jakearchibald/es6-promise
/*------------------------------ GET PROMISE ------------------------------*/
// N.B.: Promises pass only first argument to resolve/reject callbacks, others are ignored
function doSomething(){
return new Promise(function(resolve, reject) {