Skip to content

Instantly share code, notes, and snippets.

View shawndumas's full-sized avatar

Shawn Dumas shawndumas

  • UX Engineer
  • Menlo Park, CA
View GitHub Profile
@shawndumas
shawndumas / checkType.js
Last active July 11, 2020 13:41
Type Checking in JavaScript
function checkType (obj, typ) {
typ = ((typ && typ.toLowerCase()) || false);
var objTyp = Object
.prototype
.toString
.call(obj)
.replace('[object ', '')
.replace(']', '')
.toLowerCase();
typeof({}); // => "object"
typeof(1); // => "number"
typeof(""); // => "string"
typeof(function () {}); // => "function"
typeof(undefined); // => "undefined"
typeof(true); // => "boolean"
typeof(new Date()); // => "object"
typeof([]); // => "object"
typeof(null); // => "object"
typeof(window); // => "object"
typeof(new String()); // => "object"
Object.prototype.toString.call([]); // => "[object Array]"
window.open(
'data:text/csv;charset=utf-8,' +
encodeURIComponent(' \
one,two,three \n\
1,2,3 \n\
4,5,6 \n\
')
);
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://addepar.github.io/ember-table/stylesheets/bootstrap.css">
<link rel="stylesheet" href="http://addepar.github.io/ember-table/stylesheets/font-awesome.css">
<link rel="stylesheet" href="http://addepar.github.io/ember-table/stylesheets/styles.css">
<link rel="stylesheet" href="http://addepar.github.io/ember-table/stylesheets/table-base.css">
<script src="http://addepar.github.io/ember-table/javascripts/lib/modernizr-2.6.1.min.js"></script>
@shawndumas
shawndumas / misc.sh
Last active December 26, 2015 17:49
A bunch of CLI miscellany
# current tty's PIDs
ps -fu `whoami` | grep 'pts/`tty | cut -d/ -f4`'
# capture ip traffic
ngrep -q -d any -W none ip
# mitm proxy
socat -v TCP-LISTEN:<port>,fork TCP:localhost:<port>
# reverse tunnel
@shawndumas
shawndumas / explain
Last active December 27, 2015 18:49
Explain
#!/bin/bash
#brew install gnu-sed
#ln -s /usr/local/bin/gsed /usr/local/bin/sed
URL=$(echo "http://explainshell.com/explain?cmd=$1+${@:2}" | sed -e 's/ /+/g')
curl -s "$URL" | sed -n '/<pre/,/<\/pre>/p' | sed -n '/<pre/,/<\/pre>/p' | sed -s 's/<[^>]*>//g' | \
sed -e 's/^ *//g;s/ *$//g' | grep '.' | cat
@shawndumas
shawndumas / th.sh
Last active November 30, 2023 12:50
toggle AppleShowAllFiles
#!/bin/bash
#
# toggle AppleShowAllFiles
#
current_value=$(defaults read com.apple.finder AppleShowAllFiles)
if [ $current_value = "TRUE" ]
then
defaults write com.apple.finder AppleShowAllFiles FALSE
else
@shawndumas
shawndumas / obsession.sh
Last active January 2, 2016 12:49
hn leaders
lynx -dump -nonumbers -nolist https://news.ycombinator.com/leaders | head -14 | tail