Skip to content

Instantly share code, notes, and snippets.

View unleashy's full-sized avatar

unleashy

  • Rio de Janeiro, Brazil
  • 16:22 (UTC -03:00)
View GitHub Profile
@unleashy
unleashy / hell-is-real.js
Created May 14, 2024 05:10
Julian day → Gregorian calendar in Temporal
function fromJulianDay(jd) {
const Y = 4716;
const J = 1401;
const M = 2;
const N = 12;
const R = 4;
const P = 1461;
const V = 3;
const U = 5;
const S = 153;
@unleashy
unleashy / lexer.rs
Created November 4, 2021 17:53
Literate code for a simple lexer in Rust
#![allow(unused_doc_comments)]
#![allow(dead_code)]
/// let's create a lexer to tokenise a simplistic arithmetic language,
/// with integers, plusses and minuses!
///
/// playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7e0716a957a90c486328c8e775ca268f
///
/// to store the state of our lexer we'll just create a lexer struct:
@unleashy
unleashy / quoted.d
Last active September 29, 2019 23:27
Demonstrates broken D syntax highlighting in d.tmbundle
auto s = q"(")";
auto broken = true;
@unleashy
unleashy / tabhash.d
Created June 9, 2018 22:51
tabulation hashing
import std.stdio;
import std.datetime;
@safe:
private immutable ulong[256][8] tables_;
static this()
{
import std.random : unpredictableSeed;
@unleashy
unleashy / isSpecGenerator.d
Last active October 15, 2017 00:05
generate is-spec
import std.string, std.algorithm, std.range.primitives;
// a | void a()
// a :: b, c, ... | void a(b, c, ...)
// a :: b, c, ... -> r | r a(b, c, ...)
// a -> r | r a()
string generateIsSpec(string typename, string spec)
{
auto buf = "{\nimport std.traits : lvalueOf;\n" ~
"return is(typeof(" ~ typename ~ ".init) == " ~ typename ~ ") &&\n";
@unleashy
unleashy / xsampa.rb
Last active July 9, 2022 02:38
ruby xsampa -> ipa converter
module XSConverter
# noinspection RubyStringKeysInHashInspection
XSAMPA_MAP = {
'b_<' => 'ɓ',
'd`' => 'ɖ',
'd_<' => 'ɗ',
'g_<' => 'ɠ',
'h\\' => 'ɦ',
'j\\' => 'ʝ',
'l`' => 'ɭ',