Skip to content

Instantly share code, notes, and snippets.

@RhodiumToad
RhodiumToad / ryu.lua
Created June 22, 2023 01:29
Translation of Ryu float-to-string algorithm into Lua
--
--[[
ryu.d2string(d) -- convert float number d to shortest-exact string
As this code stands, it will produce output only in exponential
notation (e.g. "1e+00" rather than "1"). IEEE format is required.
It is an error to pass in an integer rather than a float.
akren:~ % guile3 -q
GNU Guile 3.0.7
scheme@(guile-user)> (load "tst.scm")
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/andrew/tst.scm
WARNING: (gentst): `foo' imported from both (gentst1) and (gentst2)
;;; compiled /home/andrew/.cache/guile/ccache/3.0-LE-8-4.5/home/andrew/tst.scm.go
#<<generic> foo (1)>ice-9/boot-9.scm:1685:16: In procedure raise-exception:
(define-module (gentst)
#:use-module (oop goops)
#:use-module (gentst1)
#:use-module (gentst2)
#:export (test)
#:re-export (foo)
#:duplicates (merge-generics))
@RhodiumToad
RhodiumToad / census2020.sql
Created May 7, 2021 19:44
2020 US census apportionment
--
create table states_orig
(
state text primary key,
pop integer not null,
reps integer,
change integer
);
comment on table states_orig is 'Original data from census.gov';
/*
* vectorized (requires SSSE3) implementation of binary to decimal conversion.
* This was mainly an intellectual exercise, any performance gain over methods
* that do 2-digit conversions with lookup table are not worth the effort.
*
* Currently works with clang but can be adapted to gcc.
*/
#include <stdint.h>
#include <stdbool.h>
-- this role will own all the objects
create role appowner;
create schema app authorization appowner;
-- this is the admin group, which grants the admins the ability to
-- adopt the owner role for admin tasks. The noinherit means that the
-- admins don't get any other permissions from the owner.
create role appadmin noinherit in role appowner;
-- this role will own all the objects
create role appowner;
create schema app authorization appowner;
-- this is the admin group, which grants the admins the ability to
-- adopt the owner role for admin tasks. The noinherit means that the
-- admins don't get any other permissions from the owner.
create role appadmin noinherit in role appowner;
-- do this stuff as postgres
\c - postgres
-- this role will own all the objects
create role appowner;
create schema app authorization appowner;
-- this is the admin group, which grants the admins the ability to
-- adopt the owner role for admin tasks. The noinherit means that the
-- admins don't get any other permissions from the owner.
--- src/lua.c.orig 2018-07-19 19:12:54 UTC
+++ src/lua.c
@@ -73,6 +73,9 @@ static void print_usage (const char *bad
" -l name require library 'name' into global 'name'\n"
" -v show version information\n"
" -E ignore environment variables\n"
+#if defined(LUA_USE_READLINE_DL)
+ " -N disable command-line editing\n"
+#endif
" -- stop handling options\n"
function dcopy(orig_t)
if type(orig_t) ~= "table" then return orig_t end
--[[
Recurse with memoization; t is always a table, if it's a table
previously seen then return the memoized copy, otherwise make
a new empty table and copy
--]]
local memot = {}
local function dcopy_rec(t)
local nt = memot[t]