Skip to content

Instantly share code, notes, and snippets.

pj pjmp

Block or report user

Report or block pjmp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pjmp
pjmp / demo.js
Created Feb 7, 2018
Working with promises
View demo.js
const promises = [
() =>
new Promise(resolve =>
setTimeout(() => {
resolve(console.log(1));
}, Math.floor(Math.random() * 2000) + 1000)
),
() =>
new Promise(resolve =>
@pjmp
pjmp / not-uuid.js
Last active Dec 23, 2017
basic non-uuid uuid generator without going crazy!
View not-uuid.js
// with map
[...Array(5)].map((elm, idx) => {
switch(idx) {
case 0:
return Math.random().toString(36).slice(2, 8)
case 4:
return Math.random().toString(36).slice(2, 14)
default:
return Math.random().toString(36).slice(2, 6)
}
@pjmp
pjmp / dimmer.js
Last active May 31, 2017
Dim any website
View dimmer.js
$('<div id="dim_overlay">')
.css({
'background-color': 'rgba(0, 0, 0, 0.5)', // change the last value to adjust the brightness.
'min-height': '100%',
'min-width': '100%',
'position': 'fixed',
'pointer-events': 'none', // keeps website's functionality intact
'z-index': 999
})
.appendTo(document.body);
@pjmp
pjmp / ListCookies.js
Created Mar 10, 2017
List out cookies
View ListCookies.js
function ListCookies() {
var o = {};
var c = document.cookie.split(' ')
for (var i=0; i<c.length; i++) {
o[c[i].split('=')[0]] = c[i].split('=')[1];
}
return o
}
console.log(ListCookies())
@pjmp
pjmp / Solutions.md
Created Oct 12, 2016
Solutions to CodeWars' "Kata".
View Solutions.md
@pjmp
pjmp / revrot.js
Last active Oct 12, 2016
Reverse or rotate given string.
View revrot.js
function revrot(str, sz) {
/**
* If string (str), size (sz) or size is greater than string's
* length, return empty string.
*/
if (sz === 0 || str.length === 0 || sz > str.length) {
return ''
}
@pjmp
pjmp / validate.js
Last active Oct 12, 2016
Implementation of The Luhn Algorithm
View validate.js
/*
Implementation of The Luhn Algorithm (https://en.wikipedia.org/wiki/Luhn_algorithm)
*/
function validate(n) {
/**
* Check if the given number is of valid type
*/
if (!n || typeof n !== 'number') {
@pjmp
pjmp / tiny_hacks.md
Last active Feb 14, 2017
Tiny everyday hacks i found useful.
View tiny_hacks.md

Better Git Blame ??

Credits: @andrewray
URL: http://blog.andrewray.me/

git log -p -M --follow --stat -- /path/to/file/name

Better Git Log

@pjmp
pjmp / coffeescript_to_javascript.js
Last active Aug 5, 2016
CoffeScript official examples in ES6
View coffeescript_to_javascript.js
// CoffeeScript
square = (x) -> x * x
cube = (x) -> square(x) * x
fill = (container, liquid = "coffee") ->
"Filling the #{container} with #{liquid}..."
// ES6
let square = (x) => x*x
let cube = (x) => square(x)*x
let fill = (container, liquid = null) => `Filling the ${container} with ${liquid}...`
You can’t perform that action at this time.