Skip to content

Instantly share code, notes, and snippets.

Avatar

Eric Doughty-Papassideris ddlsmurf

View GitHub Profile
View cli_histogram.ex
defmodule CLIHistogram do
defp block_index_from_fractional(blocks, fractional) when fractional >= 0 and fractional <= 1, do:
round(fractional * (tuple_size(blocks) - 1))
defp block_index_from_fractional(_blocks, fractional) when fractional < 0, do: 0
defp block_index_from_fractional(blocks, fractional) when fractional > 1, do: tuple_size(blocks) - 1
defp block_from_fractional(blocks, fractional), do: elem(blocks, block_index_from_fractional(blocks, fractional))
defp repeat_string(str, count) when count <= 0, do: str
defp repeat_string(str, count), do: String.pad_leading("", count, str)
@ddlsmurf
ddlsmurf / ssh_sign.exs
Last active Feb 6, 2022
SSH private key file and signature file reader
View ssh_sign.exs
defmodule T do
def read_ssh_sig(filename) do
{:ok, raw_sig} = File.read(filename)
raw_sig = String.replace(raw_sig, ~r/.*-----BEGIN SSH SIGNATURE-----\n/s, "")
raw_sig = String.replace(raw_sig, ~r/\n-----END SSH SIGNATURE-----.*/s, "")
Base.decode64(raw_sig, ignore: :whitespace)
end
defp shift_string(<<len::unsigned-integer-32, str::binary-size(len), rest::binary>>), do: { str, rest }
defp parse_ssh_sig_body(sig_body) do
# ssh_sig_magic = 'SSHSIG'
@ddlsmurf
ddlsmurf / index.html
Last active Dec 25, 2021
Calculates more interesting dates to celebrate if your existence duration is the main variable
View index.html
<html>
<head>
<title>Birthdates ! </title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.34/moment-timezone-with-data.js" integrity="sha512-oqSECbLRRAy3Sq2tJ0RmzbqXHprFS+n7WapvpI1t0V7CtV4vghscIQ8MYoQo6tp4MrJmih4SlOaYuCkPRi3j6A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<!-- Select 2 -->
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
</head>
@ddlsmurf
ddlsmurf / philips_hue_tap_notes.md
Last active Sep 19, 2022
Philips Hue Tap notes
View philips_hue_tap_notes.md

I had issues with my tap switch, it would stop working. Here are my notes from the disassembly.

Internally a PTM215Z.

Join (or re-join) procedure

This sometimes is required even if nothing changed, not sure why.

  • Set the hub to scan for sensors (POST api/${user}/sensors) - This could be optional if the channel was changed. Try skipping this first, if that doesn't work, retry without skipping this.
  • Press and hold button for your channel (see table below) for at least 7 seconds.
@ddlsmurf
ddlsmurf / index.html
Last active Dec 21, 2021
Watchy BLE OTA client #watchy #tool
View index.html
<html>
<head>
<style>
.dragging {
background-color: rgb(236, 135, 135);
}
</style>
</head>
<body>
<h1>Watchy BLE firmware upload client</h1>
@ddlsmurf
ddlsmurf / wifi_update_client.c
Last active Aug 7, 2021
ESP32 https OTA #watchy #esp32
View wifi_update_client.c
#include <wifi_update_client.h>
#include <esp_log.h>
#include <esp32-hal.h>
#include <esp_https_ota.h>
static const char *LOG_TAG = "wifi_update_client";
const char *url = "https://raw.githubusercontent.com/sqfmi/Watchy/master/examples/WatchFaces/7_SEG/7_SEG.bin";
@ddlsmurf
ddlsmurf / pretty_json.coffee
Last active May 22, 2021
This is a very hastily cobbled together JSON prettifyer that doesn't bug me about input validity as long as unambiguous. Also it warns about a few validity issues (not all). #tool
View pretty_json.coffee
{ Transform } = require('stream')
EOL = "\n"
Utils =
spaces: (num) -> if num <= 0 then '' else (new Array(num + 1)).join(" ")
ljust: (str, len) -> str + Utils.spaces(len - str.length)
streamToString: (stream, cb) ->
len = 0
buffer = []
stream
.on('end', -> cb(null, Buffer.concat(buffer, len)))
@ddlsmurf
ddlsmurf / type.coffee
Last active May 22, 2021
More exhaustive version of typeof #snippet_js
View type.coffee
toString = Object::toString
hasOwnProperty = Object::hasOwnProperty
propertyIsEnumerable = Object::propertyIsEnumerable
toStringTags = date: '[object Date]'
Utils =
### @return `undefined|null|boolean|string|symbol|number|NaN|array|arguments|date|object|function` ###
type: (val) ->
switch type = typeof val
when 'undefined', 'string', 'boolean', 'symbol'
return type
@ddlsmurf
ddlsmurf / this_in_javascript.md
Last active May 22, 2021
what's `this` in javascript #tutorial
View this_in_javascript.md

this

Function declarations

There are two (mostly) equivalent ways to define a function:

function Add(a, b) { return a + b };

var Add = function(a, b) { return a + b };
View gist:3490e61ff090c36ec4ea
toString = Object::toString
hasOwnProperty = Object::hasOwnProperty
propertyIsEnumerable = Object::propertyIsEnumerable
### @return `undefined|null|boolean|string|symbol|number|NaN|array|arguments|date|object|function` ###
(val) ->
switch type = typeof val
when 'undefined', 'string', 'boolean', 'symbol'
return type
when 'number'
return (if Number.isNaN(val) || (val in [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY]) then 'NaN' else type)