Skip to content

Instantly share code, notes, and snippets.

@dkordik
dkordik / isp-icon.js
Last active March 19, 2023 00:16
xbar/BitBar plugin to show currently connected ISP logo. Just added T-Mobile and Verizon, for starters. But you can see how you could easily add others.
#!/usr/bin/env /usr/local/bin/node
// <xbar.title>Current ISP name</xbar.title>
// <xbar.version>v2.1.7-beta</xbar.version>
// <xbar.author>Dan Kordik</xbar.author>
// <xbar.author.github>dkordik</xbar.author.github>
// <xbar.desc>Displays current ISP name</xbar.desc>
// <xbar.dependencies></xbar.dependencies>
const http = require("http");
@dkordik
dkordik / allDateOutputs.js
Created June 27, 2022 20:50
Show a date using each built-in JavaScript date format
const date = new Date("2022-06-27T00:49:00Z");
// yoinked from https://flaviocopes.com/how-to-list-object-methods-javascript/
const getMethods = (obj) => {
let properties = new Set()
let currentObj = obj
do {
Object.getOwnPropertyNames(currentObj).map(item => properties.add(item))
} while ((currentObj = Object.getPrototypeOf(currentObj)))
return [...properties.keys()].filter(item => typeof obj[item] === 'function')
@dkordik
dkordik / merged-object.groovy
Last active August 7, 2020 23:47
Groovy- merging an object with another existing object without explicitly mapping properties
class BulkResponse {
String subject;
}
bulkResponse = new BulkResponse(subject:'Hi Rohit!')
//--
class ThreadResponse extends BulkResponse {
String campaignName;
}
@dkordik
dkordik / safe-install.sh
Created June 6, 2019 22:30
Safe Install - specify dependencies to install. Verify they don't exist first. Verify they DO exist when we're done.
#!/bin/bash
set -e # exit when a command fails, so we don't continue doing next steps!
function check_exists {
CMD="$1"
# "type" works nicely for checking existence of both shell functions and scripts/bins
if type -t "$CMD" 1> /dev/null 2>/dev/null; then
true
else
false
@dkordik
dkordik / set_git_diff_aliases.sh
Created June 20, 2017 21:36
git diff aliases
#uses showlinenum.awk from: https://github.com/jay/showlinenum (needs gawk, brew install gawk)
alias gd='git diff --color=always | ~/showlinenum.awk color_line_number=90 color_separator=37 | less -r'
alias gds='git diff --staged --color=always | ~/showlinenum.awk color_line_number=90 color_separator=37 | less -r'
@dkordik
dkordik / time_command.sh
Last active March 22, 2017 02:42
Print out the execution time of a specified terminal command, 10 times
# Usage:
# ./time_command.sh "sleep 2"
# (or a command you actually care about timing, in quotes)
COMMAND="$1"
for N in {1..10}
do
printf "$N: "
( time `eval $COMMAND` ) 2>&1 | grep real | awk '{ printf $2 }'

Keybase proof

I hereby claim:

  • I am dkordik on github.
  • I am dkordik (https://keybase.io/dkordik) on keybase.
  • I have a public key ASCAO4KMq8wsMpPZ5vs5rGvZlxNk75PYkdjOGO1nlafjFwo

To claim this, I am signing this object:

<link rel="import" href="../core-scaffold/core-scaffold.html">
<link rel="import" href="../core-header-panel/core-header-panel.html">
<link rel="import" href="../core-menu/core-menu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-field/core-field.html">
<link rel="import" href="../core-icon/core-icon.html">
<link rel="import" href="../core-input/core-input.html">
<link rel="import" href="../core-icons/core-icons.html">
@dkordik
dkordik / fightthefuture.js
Last active December 28, 2015 13:19
Better Meteor async. Man, futures can be confusing! This is how I clean things up a little bit in my actual methods.
var Future = Npm.require('fibers/future'); //npm install fibers
var async = function (callback) { //let's tuck away some of the nastyness in here
var future = new Future();
var returnFunc = function () {
future["return"].apply(future, arguments);
}
callback(returnFunc);
@dkordik
dkordik / bubble_error_events.js
Created October 3, 2013 20:02
Image error events don't bubble, (see http://www.w3.org/TR/DOM-Level-3-Events/#event-type-error ) which can be pretty annoying when you're trying to handle them with any modern event-delegation-y technique. This uses event capturing on supported browsers to trigger a standard bubble-friendly event on the element in question, so you can handle th…
//image error events don't bubble, so we use
// native event capturing, where supported
if (document.addEventListener && !document.bubbleErrors) {
document.addEventListener('error', function (event) {
jQuery(event.target).trigger(event); //bubble it ourselves!
}, true); //true = use event capturing (not bubbling)
document.bubbleErrors = true;
}