Skip to content

Instantly share code, notes, and snippets.

Avatar

thegitfather thegitfather

View GitHub Profile
@thegitfather
thegitfather / sum-reduce.js
Created Sep 10, 2019
use reduce() to calc sum of some property in object[]
View sum-reduce.js
calcSum = (items, prop) => {
return items.reduce((a, b) => a + b[prop], 0);
}
let foo = [{price: 1}, {price: 2}, {price: 3}];
calcSum(foo, 'price'); // 6
View angular.io.cheat.sheet.md

ANGULAR (2+) CHEATSHEET

NG MODULES

import { NgModule } from '@angular/core';

@NgModule({
  declarations: ...,
  imports: ...,
@thegitfather
thegitfather / twitch-auto-fullscreen.user.js
Last active Dec 7, 2020
Twitch Auto Fullscreen (tampermonkey)
View twitch-auto-fullscreen.user.js
// ==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 / parameter-url.js
Created Mar 18, 2019
function to return url parameters as a string
View parameter-url.js
_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 + '&';
}
});
View .gitignore
### 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
assign exit code of a sub shell command to a variable
View alive.sh
ALIVE=$(ping -c 3 www.example.com &>/dev/null ; echo $?)
@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active Apr 10, 2021
Vanilla JavaScript Quick Reference / Cheatsheet
View vanilla-js-cheatsheet.md
View http-status-codes.js
var httpStatusCodes = {
// 1xx Informational
// Request received, continuing process.[2]
// This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line. Since HTTP/1.0 did not define any 1xx status codes, servers must not send a 1xx response to an HTTP/1.0 client except under experimental conditions.
'100': 'Continue', //This means that the server has received the request headers, and that the client should proceed to send the request body (in the case of a request for which a body needs to be sent; for example, a POST request). If the request body is large, sending it to a server when a request has already been rejected based upon inappropriate headers is inefficient. To have a server check if the request could be accepted based on the request's headers alone, a client must send Expect: 100-continue as a header in its initial request[2] and check if a 100 Continue status code is received in response be
View index.html
<!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;
@thegitfather
thegitfather / singleton.js
Last active Feb 21, 2016
singleton pattern
View singleton.js
/*
* 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