Skip to content

Instantly share code, notes, and snippets.

@dkordik
dkordik / seizure.js
Created January 19, 2012 22:34
Seizure.js - experiment in doing more UI manipulation in JS than a "stop script?" limit would allow
//concept from http://www.sitepoint.com/multi-threading-javascript/
var $visibleElements = $(":visible");
var random255 = function () {
return Math.floor(Math.random()*255);
}
var randomColor = function () {
return "rgb(" + random255() + "," + random255() + "," + random255() + ")";
}
@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 / Terminal.sublime-settings
Created May 2, 2012 15:36
Sublime Text 2 Terminal config with Console2/cygwin/bash to open a terminal in the current directory
{
"terminal": "C:/Program Files/Console2/Console.exe",
// In Console2 "Shell" section, have just "bash" with no args in a profile called "Terminal"
"parameters": ["-t", "Terminal", "-r", "/bin/xhere /bin/bash.exe", "`%CWD%`"]
}
@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
#!/bin/sh
#
# This script will make WinMerge your default tool for diff and merge.
# It must run inside git bash (on Windows)
#
# If your WinMerge is in other place then this one, please edit
WINMERGE_SCRIPT="~/winmerge-merge.sh"
@dkordik
dkordik / Terminal.sublime-settings
Created May 3, 2012 18:02
Sublime Text 2 Terminal config with mintty/cygwin/bash to open a terminal in the current directory
{
"terminal": "C:/cygwin/bin/mintty.exe",
"parameters": ["/bin/env", "CHERE_INVOKING=1", "/bin/xhere", "/bin/bash", "`%CWD%`"]
}
@dkordik
dkordik / addCommasToNumber.js
Created September 6, 2011 21:37
Add comma separators to numbers
function addCommasToNumber(n) {
return n.toString().split('').reverse().join('').match(/(.{1,3})/g).join(',').split('').reverse().join('');
}
@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'