Skip to content

Instantly share code, notes, and snippets.

@dsevero
dsevero / rans.py
Last active September 17, 2024 21:00
Asymmetric Numeral Systems (ANS) codec in pure Python
def push(state, symbol, cdf_func, prec):
cdf_low, cdf_high = cdf_func(symbol)
freq = cdf_high - cdf_low
return prec*(state // freq) + (state % freq) + cdf_low
def pop(state, icdf_func, cdf_func, prec):
cdf_value = state % prec
symbol, cdf_low, cdf_high = icdf_func(cdf_value)
freq = cdf_high - cdf_low
return symbol, freq*(state // prec) + cdf_value - cdf_low
@adamterlson
adamterlson / Propsal.md
Last active October 24, 2021 16:59
Lightning talk proposal for the Reactive 2016 Conference: Reconceptualizing react applications as a function

Lightning talk proposal for the Reactive 2016 Conference. Here's a handy retweet link

If you want to hear this talk, or if you just want to support me, please star ⭐ the Gist!

When I started writing React apps, I approached components as if they were “just the V in MVC!” Seriously, we’ve all heard it.

I have found this to be an inferior way of thinking about and building React applications. It makes people treat React as a drop-in replacement for something like a Backbone or Angular 1.x View. In other words, people treat it like a glorified template system with partials and don’t harness the power of its functional paradigms.

This talk is about a functional way to write and conceptualize entire React applications.

@aras-p
aras-p / preprocessor_fun.h
Last active September 8, 2024 07:43
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,