Skip to content

Instantly share code, notes, and snippets.

View mhseiden's full-sized avatar
🏗️

Max Seiden mhseiden

🏗️
View GitHub Profile
@mhseiden
mhseiden / percent_of_totals_snowflake.sql
Created April 18, 2022 20:41
A few different SQL approaches for calculating a percent of total.
-- A percent of total calculation using a joined, aggregated subquery
select state
, county
, 100 * population / state_population as pct_state_population
from census
join (select state, sum(population) state_population from census group by 1) using (state)
;
-- A percent of total calculation using a windowed aggregate
select state
@mhseiden
mhseiden / compact_string.rs
Created June 5, 2017 05:43
A basic and incomplete implementation of a compact string.
use std::{fmt, mem, slice, str};
use std::ops::Deref;
const HEAP_STRING_FLAG: u8 = 1u8 << 7;
const MAX_INLINE_LENGTH: usize = 15;
#[repr(packed)]
#[derive(Default)]
pub struct CompactString {
@mhseiden
mhseiden / .block
Last active February 22, 2017 18:55
OK Earthquakes IX
license: mit
@mhseiden
mhseiden / sort.js
Last active November 3, 2016 23:21
O(n) sorting of whole numbers with setTimeout
function sort(i,c) {
var o = [], r = i.length;
i.forEach(function(v) {
setTimeout(function() {
o.push(v);
if(0 === --r) {
c(o);
}
}, v);
});
### Keybase proof
I hereby claim:
* I am mhseiden on github.
* I am mhs (https://keybase.io/mhs) on keybase.
* I have a public key whose fingerprint is EA16 953E 006D 61B9 B6AC 8A3A 1B5A EC10 D7A9 50E4
To claim this, I am signing this object:
function renderAudioData(canvas, data) {
// Grab handy variables with local names
var height = canvas.height;
var width = canvas.width;
var length = data.length;
var stepSize = width / length;
// Helper functions to make the index selection logic more readable further down
var xCoord = function(idx) { return stepSize * idx; };
var xNext = function(idx) { return xCoord(idx + 1); };
@mhseiden
mhseiden / download_decode_downsample.js
Last active March 23, 2021 09:19
Downloading, Decoding, and Downsampling an Audio File with the WebAudio API
/**
* In this gist, assume that we're using Chrome, and the following variables are in scope and have already been assigned to the following:
*
* var url = "http://upload.wikimedia.org/wikipedia/commons/b/be/Toccata_et_Fugue_BWV565.ogg";
* var webaudio = new webkitAudioContext();
* var renderCallback = function renderCallback(data) { return "render!"; } // a function which will render the given audio data on a canvas
*/
// Fetch the data with an AJAX request
var xhr = new XMLHttpRequest();
@mhseiden
mhseiden / TypedObject.js
Created May 1, 2013 19:27
Version 1 a "typed object" implementation.
/**
Copyright (c) 2012 - Max Seiden <140dbs@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
/**
* NOTE - I haven't compiled this, so there may be small errors.
* However, the concepts shown are correct.
*/
// In the *.h file
class MyClass;
class MyClass {
public:
@mhseiden
mhseiden / gist:4027452
Created November 6, 2012 20:52
Simple Shell Injection
# Not an immediate vector
touch ‘safe_file.txt$(echo “Shell Injection” > safe_file.txt)’
# Quite unsafe
touch “bad_file.txt$(echo “Shell Injection” > bad_file.txt)”