Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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");