Skip to content

Instantly share code, notes, and snippets.

View AdamTReineke's full-sized avatar

Adam Reineke AdamTReineke

View GitHub Profile
@AdamTReineke
AdamTReineke / timeOfUsePricing.sql
Created December 1, 2023 07:41
Compute my time of use pricing based on electric usage captured in Home Assistant.
SELECT
month,
printf("%.2f", kWh) AS kWh,
printf("%.2f", costTimeOfUse) AS costToU,
printf("%.2f", CASE
WHEN kWh > 800 THEN 800*0.118889 + (kWh-800) * 0.138306
ELSE kWh * 0.118889
END) AS costNow
FROM (
SELECT
@AdamTReineke
AdamTReineke / index.js
Last active November 14, 2019 04:00
Sorting my wedding photos into B&W vs Color folders
var Jimp = require('jimp');
var fs = require('fs');
function isGrayFn(img, idx) {
return img.bitmap.data[idx] == img.bitmap.data[idx + 1]
&& img.bitmap.data[idx] == img.bitmap.data[idx + 2];
}
fs.readdir("D:\\HQWeddingPhotos", (err, files) => {
const process = (path) => {
<?xml version="1.0" encoding="UTF-8"?>
<INVENTORY>
<ITEM>
<ITEMTYPE>P</ITEMTYPE>
<ITEMID>2436</ITEMID>
<COLOR>5</COLOR>
<MAXPRICE>-1.0000</MAXPRICE>
<MINQTY>1</MINQTY>
<CONDITION>X</CONDITION>
<NOTIFY>N</NOTIFY>
@AdamTReineke
AdamTReineke / a.heapsnapshot
Created May 4, 2015 22:41
Heap snapshot gathered via ChromeDriver that won't import into Chrome's dev tools
This file has been truncated, but you can view the full file.
return browser.sleep(1)
.then(function() {
return browser.setWindowSize(500,500);
})
.then(function() {
return browser.sleep(5000);
})
.then(function() {
return browser.setWindowSize(500, 800);
})
@AdamTReineke
AdamTReineke / gist:58c4696fb0bc07bd5247
Created September 25, 2014 01:42
Instrument addEventListener to provide async callstacks for Internet Explorer 11's developer tools
Element.prototype._addEventListener = Element.prototype.addEventListener;
Element.prototype.addEventListener = function () {
var opID = Debug.msTraceAsyncOperationStarting("Element.prototype.addEventListener");
var eventThis = this;
// Replace the user's function with a version wrapped with the async instrumentation calls
arguments[1] = (function (userFunc) {
return function instrumentAddEventListener() {
// We call that the async op completed instantly because the async op was the click
// event that started this call.
Debug.msTraceAsyncOperationCompleted(opID, Debug.MS_ASYNC_OP_STATUS_SUCCESS);
@AdamTReineke
AdamTReineke / Instrument appendChild
Created September 25, 2014 01:28
Instrument appendChild to build an array of paths from the root to the added child.
var nodeCollection = [];
var nodeGetNodeName = function (node) {
if (node.parentElement) {
return nodeGetNodeName(node.parentElement) + " > " + node.nodeName;
}
return node.nodeName;
}
Node.prototype._appendChild = Node.prototype.appendChild;
@AdamTReineke
AdamTReineke / gist:1107198
Created July 26, 2011 16:42
Color the rows of an HTML table with alternating classes, row and altRow. (jQuery)
/**
* Color the table rows by adding row and altRow classes to the table.
* Note: ignores any table rows with the class hidden.
* @param id The id of the table
*/
function colorTableRows(id) {
var rows = $("table#" + id + " > tbody > tr").not("tr.hidden").removeClass("altRow row");
rows.filter(":odd").addClass("altRow");
rows.filter(":even").addClass("row");
}
@AdamTReineke
AdamTReineke / gist:1095961
Created July 20, 2011 21:18
Sort all definition lists (DL) on a page alphabetically
// jQuery code to sort all definition lists on a page alphabetically, assuming terms and definitions alternate. Place in $(document).ready(function(){ });
$("dl").each(function() {
$(this).children("dt").sort(function(a, b){
return a.innerHTML.toUpperCase() > b.innerHTML.toUpperCase() ? 1 : -1;
}).each(function() {
var dd = $(this).next("dd");
$(this).appendTo($(this).parent());
dd.appendTo(dd.parent());
})
@AdamTReineke
AdamTReineke / gist:922992
Created April 16, 2011 09:02
ugly ToString
public String toString()
{
return "Tile [" + getColumn() + "," + getRow()
+ "] - Neighbors ["
+ ((neighbors[0] != null) ? neighbors[0].getColumn()+"x"+neighbors[0].getRow()+"," : "-")
+ ((neighbors[1] != null) ? neighbors[1].getColumn()+"x"+neighbors[1].getRow()+"," : "-")
+ ((neighbors[2] != null) ? neighbors[2].getColumn()+"x"+neighbors[2].getRow()+"," : "-")
+ ((neighbors[3] != null) ? neighbors[3].getColumn()+"x"+neighbors[3].getRow()+"," : "-")
+ ((neighbors[4] != null) ? neighbors[4].getColumn()+"x"+neighbors[4].getRow()+"," : "-")