Skip to content

Instantly share code, notes, and snippets.

View thegitfather's full-sized avatar

thegitfather thegitfather

View GitHub Profile
@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 / 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 / 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 / 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 / jquery.plugin.boilerplate.js
Created April 27, 2015 11:54
jQuery Plugin Boilerplate
// jQuery Plugin Boilerplate
// A boilerplate for jumpstarting jQuery plugins development
// version 1.1, May 14th, 2011
// by Stefan Gabos
// remember to change every instance of "pluginName" to the name of your plugin!
(function($) {
// here we go!
$.pluginName = function(element, options) {
@thegitfather
thegitfather / examples.md
Last active July 16, 2017 00:28
markdown elements

An exhibit of Markdown

This note demonstrates some of what [Markdown][1] is capable of doing.

Note: Feel free to play with this page. Unlike regular notes, this doesn't automatically save itself.

Basic formatting

Paragraphs can be written like so. A paragraph is the basic block of Markdown. A paragraph is what text will turn into when there is no reason it should become anything else.

### Node ###
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional npm cache directory
.npm
@thegitfather
thegitfather / alive.sh
Created May 7, 2017 16:22
assign exit code of a sub shell command to a variable
ALIVE=$(ping -c 3 www.example.com &>/dev/null ; echo $?)
@thegitfather
thegitfather / reset.css
Last active May 12, 2016 15:46
reset.scss
html, body, body div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, figure, footer, header, menu, nav, section, time, mark, audio, video, details, summary {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font-weight: normal;
vertical-align: baseline;
background: transparent;
}
@thegitfather
thegitfather / index_html5.html
Last active February 18, 2016 12:44
Simple HTML5 skeleton
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Simple HTML5 skeleton</title>
<link href="http://joinpoint.org/saebl/favicon_yinyang.ico" rel="icon" type="image/x-icon">
<link rel="stylesheet" type="text/css" media="screen" href="main.css">
<link rel="stylesheet" type="text/css" media="(max-width: 599px)" href="size-s.css">
<!-- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> -->