Skip to content

Instantly share code, notes, and snippets.

View thegitfather's full-sized avatar

thegitfather thegitfather

View GitHub Profile
@thegitfather
thegitfather / jquery.randomize.js
Created January 20, 2016 23:12
randomize dom elements
/* Usage:
$('button').click(function() {
$("div.band").randomize("div.member");
});
*/
(function($) {
@thegitfather
thegitfather / totalmem.sh
Last active January 24, 2016 23:06
return the total physical memory usage (in MB) of all process with a given name usage: $ ./totalmem.sh chrome
#!/bin/bash
BASENAME=`basename "$0"`
TOTALMEM=0
if (( "$#" == 1 )); then
while read -r line; do
temp=$(echo "$line" | grep $1 | grep -o -E "[0-9]{2,}")
TOTALMEM=$(( $temp+$TOTALMEM ))
done < <(ps -eo comm,rsz ) # process substitution
@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 / 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 / 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
<!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 / http-status-codes.js
Last active August 21, 2023 06:17
http status codes
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
@thegitfather
thegitfather / vanilla-js-cheatsheet.md
Last active May 6, 2024 14:31
Vanilla JavaScript Quick Reference / Cheatsheet
@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 $?)
### Node ###
# Logs
logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional npm cache directory
.npm