Skip to content

Instantly share code, notes, and snippets.

View mhseiden's full-sized avatar
🏗️

Max Seiden mhseiden

🏗️
View GitHub Profile
@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);
});
@mhseiden
mhseiden / .block
Last active February 22, 2017 18:55
OK Earthquakes IX
license: mit
@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 / 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