Skip to content

Instantly share code, notes, and snippets.

View lionsole's full-sized avatar
🚗
I may be slow to respond.

lionsole lionsole

🚗
I may be slow to respond.
View GitHub Profile
@lionsole
lionsole / stars.js
Created June 21, 2018 06:29
starts slice
"★★★★★☆☆☆☆☆".slice(5 - CUSTOMER_SATISFACTION, 10 - CUSTOMER_SATISFACTION)
// Create HTTP error
function createError(status, message) {
var err = new Error(message);
err.status = status;
return err;
}
@lionsole
lionsole / deterministic-math-random.js
Created January 30, 2018 02:37 — forked from mathiasbynens/deterministic-math-random.js
Here’s a 100% deterministic (predictable) alternative to `Math.random`. Useful when benchmarking.
// Here’s a 100% deterministic alternative to `Math.random`. Google’s V8 and
// Octane benchmark suites use this to ensure predictable results.
Math.random = (function() {
var seed = 0x2F6E2B1;
return function() {
// Robert Jenkins’ 32 bit integer hash function
seed = ((seed + 0x7ED55D16) + (seed << 12)) & 0xFFFFFFFF;
seed = ((seed ^ 0xC761C23C) ^ (seed >>> 19)) & 0xFFFFFFFF;
seed = ((seed + 0x165667B1) + (seed << 5)) & 0xFFFFFFFF;
@lionsole
lionsole / baseConverter.js
Created January 30, 2018 02:11 — forked from faisalman/baseConverter.js
Convert From/To Binary/Decimal/Hexadecimal in JavaScript
/**
* Convert From/To Binary/Decimal/Hexadecimal in JavaScript
* https://gist.github.com/faisalman
*
* Copyright 2012-2015, Faisalman <fyzlman@gmail.com>
* Licensed under The MIT License
* http://www.opensource.org/licenses/mit-license
*/
(function(){
@lionsole
lionsole / in_viewport.js
Created June 30, 2017 05:44 — forked from jjmu15/in_viewport.js
check if element is in viewport - vanilla JS. Use by adding a “scroll” event listener to the window and then calling isInViewport().
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
@lionsole
lionsole / .js
Created June 27, 2017 02:10
js snippets to check
`use this for which condition`
{}.hasOwnProperty.call(pathParts, part))
vertifyId(id) {
if(id){
var a = id;
var b = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
var c = 0;
a = a.split('');
var d = a.pop().toLowerCase();
a.forEach(function(one, index) {
c += one * b[index]
});
@lionsole
lionsole / debounce.js
Created June 5, 2017 04:31
js debounce
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
curry = f => a => b => f(a, b)
uncurry = f => (a, b) => f(a)(b)
papply = (f, a) => b => f(a, b)
curryedMultiply = (n) => (m) => n * m
curryedMultiply(3)(4) === 12 // true
multiply = (n, m) => curryedMultiply(n)(m)
multiply(3, 4) === 12 // true