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.
{"edges":[1,1,6,5,3984,2340,5,3985,2574,1,4,199968,1,5,199980,1,1,12,1,2,18,1,3,24,1,4,30,1,5,36,1,6,42,1,7,48,1,8,54,1,9,60,1,10,66,1,11,72,1,12,78,1,13,84,1,14,90,1,15,96,1,16,102,1,1,3708,1,2,1830,1,3,3714,1,4,3720,1,5,3726,1,6,3732,1,7,1776,1,8,3738,1,9,3744,1,10,3750,1,11,3756,1,12,3762,1,13,3768,1,14,3774,1,15,3780,1,16,3786,1,17,3792,1,18,3798,1,19,3804,1,20,3810,1,21,3816,1,22,3822,1,23,3828,1,24,3834,1,25,3840,1,26,3846,1,27,3852,1,28,3858,1,29,3864,1,30,3870,1,31,3876,1,32,3882,1,33,3888,1,34,3894,1,35,1698,1,36,3900,1,37,3906,1,38,3912,1,39,3918,1,40,3924,1,41,3930,1,42,3936,1,43,3942,1,44,3948,1,45,3954,1,46,3960,1,47,3966,1,48,3972,1,49,3978,1,50,3984,1,51,3990,1,52,3996,1,53,4002,1,54,4008,1,55,4014,1,56,4020,1,57,4026,1,58,4032,1,59,4038,1,60,4044,1,61,4050,1,62,4056,1,63,4062,1,64,4068,1,65,4074,1,66,4080,1,67,4086,1,68,4092,1,69,4098,1,70,4104,1,71,4110,1,72,4116,1,73,4122,1,74,4128,1,75,4134,1,76,4140,1,77,4146,1,78,4152,1,79,4158,1,80,4164,1,81,4170,1,82,4176,1,83,4182,1,84,4188,1,85,4194,1
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()+"," : "-")