Skip to content

Instantly share code, notes, and snippets.

View piotrlewandowski's full-sized avatar

Piotr Lewandowski piotrlewandowski

View GitHub Profile
@piotrlewandowski
piotrlewandowski / string.hashcode.js
Created November 13, 2019 09:11 — forked from hyamamoto/ string.hashcode.js
JavaScript Implementation of String.hashCode() .
/**
* Returns a hash code for a string.
* (Compatible to Java's String.hashCode())
*
* The hash code for a string object is computed as
* s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1]
* using number arithmetic, where s[i] is the i th character
* of the given string, n is the length of the string,
* and ^ indicates exponentiation.
* (The hash value of the empty string is zero.)
@piotrlewandowski
piotrlewandowski / git-tag-delete-local-and-remote.sh
Created November 5, 2019 15:49 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@piotrlewandowski
piotrlewandowski / index.js
Created October 24, 2019 15:11 — forked from timneutkens/index.js
Clear console/terminal in node.js the right way
const readline = require('readline')
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
@piotrlewandowski
piotrlewandowski / gist:566410258746b86e2e323bf670f37171
Created October 14, 2019 09:35 — forked from whoisryosuke/gist:5b0d54926c997a6620945d780958ea74
Javascript / ES6 - Uppercase first letter of each word (2 ways) -- via: https://stackoverflow.com/a/4878800
function toTitleCase(str) {
return str.replace(/\w\S*/g, function(txt){
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
});
}
// or in ES6:
var text = "foo bar loo zoo moo";
const ucfirst = text => text.toLowerCase()
@piotrlewandowski
piotrlewandowski / vcs.js
Created October 8, 2019 12:45
Visual Code Studio Sync
// test
@piotrlewandowski
piotrlewandowski / latest-checkouts.sh
Created September 3, 2019 11:47 — forked from phalkunz/latest-checkouts.sh
Get latest git checkout
history | grep -e "\d\+\s\+git checkout [^-.]\+" | awk '{ print $NF }' | tail -n 10
/**
* This is based on https://getbootstrap.com/docs/4.1/utilities/spacing/
*/
$directioMap: (
top: t,
right: r,
left: l,
bottom: b
);
@piotrlewandowski
piotrlewandowski / express-passport-local.md
Created September 3, 2019 11:46 — forked from phalkunz/express-passport-local.md
Setup local (username/password) authentication in express.js (using passport.js)

Setup the project folder

    mkdir passport-local
    npm init
    # Use default values for npm init prompts

Install required packages

@piotrlewandowski
piotrlewandowski / git_submodules.md
Created August 30, 2019 12:35 — forked from gitaarik/git_submodules.md
Git Submodules basic explanation

Git Submodules basic explanation

Why submodules?

In Git you can add a submodule to a repository. This is basically a repository embedded in your main repository. This can be very useful. A couple of advantages of using submodules:

  • You can separate the code into different repositories.

Download Audio from YouTube

-i - ignore errors

-c - continue

-t - use video title as file name

--extract-audio - extract audio track