Skip to content

Instantly share code, notes, and snippets.

View thegitfather's full-sized avatar

thegitfather thegitfather

View GitHub Profile
@thegitfather
thegitfather / parameter-url.js
Created March 18, 2019 14:49
function to return url parameters as a string
_computeSearchUrlParameters(freeTextSearch, originFilter, destinationFilter, quotationStatusFilter) {
const argNames = ['freeTextSearch', 'originFilter', 'destinationFilter', 'quotationStatusFilter'];
let result = '?';
[].forEach.call(arguments, (arg, index) => {
if (arg && arg.length) {
result += argNames[index] + '=' + arg + '&';
}
});
@thegitfather
thegitfather / sum-reduce.js
Created September 10, 2019 09:51
use reduce() to calc sum of some property in object[]
calcSum = (items, prop) => {
return items.reduce((a, b) => a + b[prop], 0);
}
let foo = [{price: 1}, {price: 2}, {price: 3}];
calcSum(foo, 'price'); // 6
@thegitfather
thegitfather / twitch-auto-fullscreen.user.js
Last active December 7, 2020 12:50
Twitch Auto Fullscreen (tampermonkey)
// ==UserScript==
// @name Twitch Auto Fullscreen
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Enter fullscreen after a countdown (ESC to cancel)
// @author You
// @include https://www.twitch.tv/*
// @include https://twitch.tv/*
// @require https://cdnjs.cloudflare.com/ajax/libs/umbrella/3.1.0/umbrella.min.js
// @grant GM_addStyle
@thegitfather
thegitfather / singleton.js
Last active July 13, 2021 14:09
singleton pattern
/*
* http://blog.mgechev.com/2014/04/16/singleton-in-javascript/
*
* - It instantiates only a single object
* - Its safe it keeps the reference to the singleton inside a variable, which
* lives inside a lexical closure and is not accessible by the outside world
* - It allows you to initialize the singleton with some arguments. The module
* pattern, which wraps the singleton is not aware of the initialization
* arguments it simply forwards the call with apply
* - You can use the instanceof operator
@thegitfather
thegitfather / jQuery.wrapRegExp.js
Last active July 13, 2021 15:50
wrap a new element around some RegExp
(function($) {
'use strict';
$.fn.wrapRegExp = function(options) {
// defaults
var settings = $.extend({
regExp: /([\s\S]*)/,
wrapper: '<div style="border:1px solid red;" />'
}, options);
@thegitfather
thegitfather / favicon.html
Created January 30, 2016 11:55
favicon_yinyang.ico (inline, base64)
<link href="data:image/x-icon;base64,AAABAAEAEBAQAAEABAAoAQAAFgAAACgAAAAQAAAAIAAAAAEABAAAAAAAgAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAABQMAAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAREQAAAAAAEREREQAAAAEiIREREAAAEiIiERERAAASESIhEREAASIRIiERERABIiIiEREREAEiIiEREREQASIiIRIhERAAEiIhEiERAAASIiEREREAAAEiIhEREAAAABEiIREAAAAAABERAAAAAAAAAAAAAAD//wAA/D8AAPAPAADgBwAAwAMAAMADAACAAQAAgAEAAIABAACAAQAAwAMAAMADAADgBwAA8A8AAPw/AAD//wAA" rel="icon" type="image/x-icon">
@thegitfather
thegitfather / load_replace_css_js.user.js
Last active July 13, 2021 15:52
load/replace css/js
// ==UserScript==
// @name load_replace_css_js
// @namespace https://gist.github.com/search?q=thegitfather+UserScript
// @author thegitfather
// @version 0.11
// @description load/replace css/js
// @updateURL https://gist.github.com/thegitfather/679c9bc76e9b058790e3/raw/load_replace_css_js.user.js
// @downloadURL https://gist.github.com/thegitfather/679c9bc76e9b058790e3/raw/load_replace_css_js.user.js
// @include http://127.0.0.1/*
// @grant none
@thegitfather
thegitfather / zzz_ascii
Last active July 13, 2021 15:54
zzz_ascii
__________________
/\ ______________ \
/::\ \ZZZZZZZZZZZZ/\ \
/:/\.\ \ /:/\:\ \
/:/Z/\:\ \ /:/Z/\:\ \
/:/Z/__\:\ \____/:/Z/ \:\ \
/:/Z/____\:\ \___\/Z/ \:\ \
\:\ \ZZZZZ\:\ \ZZ/\ \ \:\ \
\:\ \ \:\ \ \:\ \ \:\ \
\:\ \ \:\ \_\;\_\_____\;\ \
@thegitfather
thegitfather / debounce.js
Created May 9, 2015 02:26
js: debounce function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
.container {
display: flex;
flex-flow: row wrap;