Skip to content

Instantly share code, notes, and snippets.

View danthegoodman1's full-sized avatar

Dan Goodman danthegoodman1

View GitHub Profile
@danthegoodman1
danthegoodman1 / int-hex-ofchar.sql
Created September 8, 2023 18:21
Get int and hex of characters above ascii in clickhouse
select ascii('🍊'), ascii('a'), bin('🍊'), bin('a'), reinterpretAsInt64(reverse(unbin(bin('🍊')))) as tan, reinterpretAsInt64(reverse(unbin(bin('a')))) as a, hex(a)
@danthegoodman1
danthegoodman1 / ch-rolling-ndr.sql
Last active September 6, 2023 16:55
ClickHouse rolling net dollar retention
-- Rolling ndr
with tbl as (
-- fake table
select c1 as usr, c2 as price, c3 as d from VALUES (
('a', 10, toDate('2023-08-09'))
, ('a', 10, toDate('2023-08-10'))
, ('a', 8, toDate('2023-08-11'))
, ('a', 11, toDate('2023-08-12'))
, ('a', 12, toDate('2023-08-13'))
, ('b', 10, toDate('2023-08-09'))
@danthegoodman1
danthegoodman1 / ch-ndr.sql
Last active September 6, 2023 16:54
ClickHouse net dollar retention
with tbl as (
-- fake table
select c1 as usr, c2 as price, c3 as d from VALUES (
('a', 10, toDate('2023-08-09'))
, ('a', 10, toDate('2023-08-10'))
, ('a', 8, toDate('2023-08-11'))
, ('a', 11, toDate('2023-08-12'))
, ('a', 12, toDate('2023-08-13'))
, ('b', 10, toDate('2023-08-09'))
, ('b', 10, toDate('2023-08-10'))
@danthegoodman1
danthegoodman1 / authy_backup.js
Last active February 2, 2023 15:14
Authy backup fix
// QRious v4.0.2 | (C) 2017 Alasdair Mercer | GPL v3 License Based on jsqrencode | (C) 2010 tz@execpc.com | GPL v3 License
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t.QRious=e()}(this,function(){"use strict";function t(t,e){var n;return"function"==typeof Object.create?n=Object.create(t):(s.prototype=t,n=new s,s.prototype=null),e&&i(!0,n,e),n}function e(e,n,s,r){var o=this;return"string"!=typeof e&&(r=s,s=n,n=e,e=null),"function"!=typeof n&&(r=s,s=n,n=function(){return o.apply(this,arguments)}),i(!1,n,o,r),n.prototype=t(o.prototype,s),n.prototype.constructor=n,n.class_=e||o.class_,n.super_=o,n}function i(t,e,i){for(var n,s,a=0,h=(i=o.call(arguments,2)).length;a<h;a++){s=i[a];for(n in s)t&&!r.call(s,n)||(e[n]=s[n])}}function n(){}var s=function(){},r=Object.prototype.hasOwnProperty,o=Array.prototype.slice,a=e;n.class_="Nevis",n.super_=Object,n.extend=a;var h=n,f=h.extend(function(t,e,i){this.qrious=t,this.element=e,this
curl \
-H "Authorization: Bearer <TOKEN>" \
-X POST "https://api.us-east.tinybird.co/v0/datasources" \
-d "schema=timestamp DateTime64(3) \`json:$.timestamp\`, _metadata_bundledIds Array(Nullable(String)) \`json:$._metadata.bundledIds[:]\`,
_metadata_bundled Array(Nullable(String)) \`json:$._metadata.bundled[:]\`, _metadata_unbundled Array(Nullable(String))
\`json:$._metadata.unbundled[:]\`, anonymousId Nullable(String) \`json:$.anonymousId\`, channel Nullable(String) \`json:$.channel\`, context
Nullable(String) \`json:$.context\`, messageId Nullable(String) \`json:$.messageId\`, originalTimestamp Nullable(DateTime64(3))
\`json:$.originalTimestamp\`, projectId Nullable(String) \`json:$.projectId\`, receivedAt Nullable(DateTime64(3)) \`json:$.receivedAt\`, sentAt
Nullable(DateTime64(3)) \`json:$.sentAt\`, type Nullable(String) \`json:$.type\`, userId Nullable(String) \`json:$.userId\`, version Nullable(Int16)
\`json:$.version\`, properties Nullable(String) CODEC(ZSTD) \`json:$.properties\`, name Nullable
@danthegoodman1
danthegoodman1 / harmless.sh
Created March 9, 2021 01:46
Harmless pranks for someone's .bashrc, .bash_profile, .zshrc, etc.
alias rm="find . && rm"
alias cd="sleep 1 && cd"
alias ls="sleep 1 && ls"
export PROMPT_COMMAND="cd"
@danthegoodman1
danthegoodman1 / speed.js
Last active June 1, 2020 18:52
In order and In Sync (high performance) JS
// Immediate execution, for of with indexes, in order
const r = ["a",2,3,4,5]
const t = (i) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(`hi ${i}`)
}, 1000 * i)
})
}
@danthegoodman1
danthegoodman1 / index.js
Last active October 2, 2019 18:25
Project 1 code snippets
const Compute = require('@google-cloud/compute')
const compute = new Compute({
projectId: '[PROJECT NAME]',
keyFilename: './keyFile.json'
})
const zone = compute.zone('us-east1-b')
const config = {
http: true,
https: true,
@danthegoodman1
danthegoodman1 / entropy.js
Created July 14, 2019 00:09
Calculates shannon entropy in node.js
let raw = fs.readFileSync('./wannacrydump')
// console.log(raw)
let freqList = []
console.log(`Bytes: ${raw.length}`)
const getEntropy = (bytes) => {
for (let i = 0; i < 255; i++) {
let ctr = 0
for (byte of bytes) {
@danthegoodman1
danthegoodman1 / gifFrames.py
Last active March 7, 2019 14:53
Exgtract RGB values of each frame from a gif
from PIL import Image
from PIL import GifImagePlugin
im = Image.open('./tenor.gif')
im.seek(0) # changes the frame we are on
# print(im.tell()) # Tells us what frame we are on
p = im.getpalette()
conv = im.convert('RGB')
# print(conv) # converted frame to rgb