Skip to content

Instantly share code, notes, and snippets.

View blizzrdof77's full-sized avatar

Ben Wagner blizzrdof77

View GitHub Profile
@blizzrdof77
blizzrdof77 / json_storage.js
Created September 17, 2018 16:24 — forked from danott/json_storage.js
Override localStorage and sessionStorage's getter and setter function to allow for objects/arrays to be stored as well.
/* json_storage.js
* @danott
* 26 APR 2011
*
* Building on a thread from Stack Overflow, override localStorage and sessionStorage's
* getter and setter functions to allow for storing objects and arrays.
*
* Original thread:
* http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage
*/
@blizzrdof77
blizzrdof77 / TP-Link Smart Plug Web Client Vendor Scripts
Last active August 22, 2018 06:25
TP-Link Smart Plug Web Client
@blizzrdof77
blizzrdof77 / ping.sh
Last active January 17, 2019 21:05
Better `ping` support to allow for mixed domains/hostnames w/ protocals (e.g. `ping 'https://who.is/my/ping/?example=this'`)
# ------------------------------------------
# Better `ping` support to allow for mixed
# domains/hostnames with protocols (e.g. 'http://..')
#
# @1 = host
# -> Example usage:
# ping http://google.com/
# ------------------------------------------
function ping {
local pingdomain="$1"
@blizzrdof77
blizzrdof77 / split-string.sh
Created May 11, 2018 22:10
Split a string simple bash function
#!/bin/bash
# Split a string returning the specified index (or 2nd instance by default)
if [ -z "$1" ] || [ -z "$2" ]; then
echo "Provide split delimiter and string"
else
delim="$1"
string="$2"
if [ -z "$3" ]; then
@blizzrdof77
blizzrdof77 / histdel.sh
Created May 9, 2018 10:04 — forked from josephabrahams/histdel.sh
Delete previous line in .bash_history
#!/bin/sh
hist=$(history | tail -1 | awk '{ print $1 }'); history -d $hist; history -d $(expr $hist - 1); unset hist
@blizzrdof77
blizzrdof77 / paths-ls.sh
Created January 5, 2018 01:41
Bash Function: List out all directories included in $PATH
# -----------------------------------------
# list out all directories included in $PATH
#
# @1 = separator (New line by default)
# -> Example usage:
# paths-ls ' '
# -----------------------------------------
function paths-ls() {
if [ -z "$1" ]; then
local SEP="\n"
@blizzrdof77
blizzrdof77 / count-new-lines
Created January 5, 2018 01:40
Bash Function: Count the number of lines in a string as variable
# -----------------------------------------
# count the number of lines in a string as variable
#
# @1 = string
# -----------------------------------------
function count-new-lines() {
if [ -z "$1" ]; then
echo "Must provide string as variable.."
return
else
@blizzrdof77
blizzrdof77 / trim.sh
Last active January 5, 2018 01:39
Trim a string or variable shell script.
# -----------------------------------------
# Trim string
#
# @1 = string
# -----------------------------------------
function trim () {
local s2 s="$*"
# note the tab character in the expressions of the following two lines when copying
until s2="${s#[ ]}"; [ "$s2" = "$s" ]; do s="$s2"; done
until s2="${s%[ ]}"; [ "$s2" = "$s" ]; do s="$s2"; done
@blizzrdof77
blizzrdof77 / String.prototypeHelpers.js
Last active September 19, 2022 20:02
Javascript String Prototype Helper Methods
/**
* Helper String Methods/Extensions to the JS String Object
*
* @param String search
* @return Bool
*/
/* Easier way to check if a string contains a substring */
String.prototype.contains = String.prototype.contains || function(search) {
return (this.indexOf(search) !== -1);
@blizzrdof77
blizzrdof77 / String.camelCaseToDashed.js
Last active January 4, 2018 19:21 — forked from youssman/regex-camelCase-to-dash.js
Javascript convert camelcase to dash (hyphen)
/**
* Convert camelCase string to lowercase string with dashes (pretty permalink style ;-)
*
* @return String
*/
String.prototype.camelCaseToDashed = function() {
return this.replace( /([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
};