Skip to content

Instantly share code, notes, and snippets.

;; Fibers: cooperative, event-driven user-space threads.
;;;; Copyright (C) 2016,2021 Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 3 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;; Lambkin, a garbage-collected heap suitable for microcontrollers.
;; Copyright (C) 2015 Andy Wingo <wingo@igalia.com>.
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@wingo
wingo / gist:d1800650a72e1062c3ee
Created January 29, 2015 09:17
luajit randomness not repeatable
#!/usr/bin/env luajit
-- -*- lua -*-
function equals(expected, actual)
if type(expected) ~= type(actual) then return false end
if type(expected) == 'table' then
for k, v in pairs(expected) do
if not equals(v, actual[k]) then return false end
end
for k, _ in pairs(actual) do
@wingo
wingo / gist:ca53c62937324dade1f9
Created September 2, 2014 13:59
portrange 0-6000, disabling CSE and caching runtime functions in outer scope
return (function()
local cast = ffi.cast
local band = bit.band
local lshift = bit.lshift
local rshift = bit.rshift
local bswap = bit.bswap
return function(P,length)
if not (length >= 34) then return false end
do
if not (cast("uint16_t*", P+12)[0] == 8) then goto L3 end
<style type="text/css">
background { background: #ffffff; color: #000000; }
pre.ljdump {
font-size: 10pt;
background: #f0f4ff;
color: #000000;
border: 1px solid #bfcfff;
padding: 0.5em;
margin-left: 2em;
margin-right: 2em;
@wingo
wingo / gist:5f820a5fadfd327af09c
Last active August 29, 2015 14:03
tcp port 80
return function(P,length)
if not 24 <= length then return false end
local v1 = P:u16(12)
if not v1 == 2048 then goto L2 end
local v2 = P:u8(23)
if not v2 == 6 then return false end
if v2 == 6 then goto L4 end
if v2 == 17 then goto L4 end
if not v2 == 132 then return false end
::L4::
// Assuming that for-of and proxies are available, this function will detect the
// version of for-of being used, and bind the std_iterator object.
//
// The return value will be one of:
//
// * 'old-spidermonkey' for currently deployed spidermonkey. This code will call
// y.iterator() on "for (x of y) ...", then call "next" on that iterator to yield
// values until next() throws StopIteration. When control exits the loop,
// .close() is called on the iterator.
//