Skip to content

Instantly share code, notes, and snippets.

@disco0
disco0 / iter.fnl
Last active November 2, 2021 08:02 — forked from leo60228/iter.fnl
; vim:set ft=fnl:
(fn filter-map [pred iter inv start-control]
(var control start-control)
(fn filter-map-inter []
(let [(new-control value) (iter inv control)]
(set control new-control)
(if (= value nil)
nil
; else
(macros
{:list-map
(fn list-map [mapper tgt]
(when (not (list? tgt)) (error (.. "Invalid form: " (tostring tgt) " is not a list")))
(let [new-list (list)]
(each [i v (ipairs tgt)]
(table.insert new-list (mapper v i tgt)))
new-list))
:list-map-recursive
@disco0
disco0 / class.fnl
Created June 9, 2021 06:32
Class script for Lua, includes inheritance (macro) (DO NOT USE PLEASE THIS SUCKS)
;; this, https://gist.github.com/nikneym/b7422a73c91d632e95ad34a813aad105
;; but stuffed in a Fennel macro.
(macro class [mother]
`(let [o# {}
mother# (or ,mother nil)]
(tset o# :__index o#)
(when mother#
(tset o# :super mother#)
(each [k# v# (pairs mother#)]
; lie and say it's clojure for highlighting
; vim: ft=clojure
; this is a hack that won't be necessary if/when we add `get-option` to the macro environment
(local meta-enabled (-> _SCOPE.specials.doc
(pcall (list (sym :doc) (sym :doc)) _SCOPE _CHUNK)))
(fn meta/when-enabled [...]
"Execute body in an implicit `do` when metadata is enabled. Otherwise,
contents are excluded from compiled output."
@disco0
disco0 / lpeg-in-fennel.fnl
Created June 8, 2021 18:05 — forked from sogaiu/lpeg-in-fennel.fnl
lpeg in fennel
>> (local lpeg (require :lpeg))
nil
>> (local equalcount (lpeg.P {1 "S"
.. "S" (+ (* "a" (lpeg.V "B")) (* "b" (lpeg.V "A")) "")
.. "A" (+ (* "a" (lpeg.V "S")) (* "b" (lpeg.V "A") (lpeg.V "A")))
.. "B" (+ (* "b" (lpeg.V "S")) (* "a" (lpeg.V "B") (lpeg.V "B")))}))
nil
>> (lpeg.match equalcount "aabb")
5
>> (lpeg.match equalcount "baabba")
@disco0
disco0 / README.md
Created May 28, 2021 04:22 — forked from acutmore/README.md
Emulating a 4-Bit Virtual Machine in (TypeScript\JavaScript) (just Types no Script)

A compile-time 4-Bit Virtual Machine implemented in TypeScript's type system. Capable of running a sample 'FizzBuzz' program.

Syntax emits zero JavaScript.

type RESULT = VM<
  [
    ["push", N_1],         // 1
    ["push", False],       // 2
 ["peek", _], // 3
@disco0
disco0 / Logger.ts
Created May 27, 2021 11:41 — forked from arabold/Logger.ts
Simple, opinionated Logger for use with Node.js and Web Browsers
/**
* Simple, opinionated Logger for use with Node.js and Web Browsers with no
* additional dependencies.
*
* The logger supports and auto-detects the following environments:
* - Node.js (with and without JSDOM)
* = Browser
* - Electron
* - React Native - Logs to console or browser window depending on whether a debugger is connected
* - Unit Test & CI/CD - Logs are disabled by default
@disco0
disco0 / tree.ts
Created May 27, 2021 07:15 — forked from albovieira/tree.ts
tree in ts
import { Func } from 'mocha';
//Ref: https://code.tutsplus.com/articles/data-structures-with-javascript-tree--cms-23393
class NodeTree {
readonly name: string;
readonly value: any;
private parent: string | null;
private children: NodeTree[];
@disco0
disco0 / AutoComplete.lua
Created May 24, 2021 06:34 — forked from Lexikos/AutoComplete.lua
Improved auto-complete for SciTE
-- AutoComplete v0.8 by Lexikos
--[[
Tested on SciTE4AutoHotkey 3.0.06.01; may also work on SciTE 3.1.0 or later.
To use this script with SciTE4AutoHotkey:
- Place this file in your SciTE user settings folder.
- Add the following to UserLuaScript.lua:
dofile(props['SciteUserHome'].."/AutoComplete.lua")
- Restart SciTE.
]]
@disco0
disco0 / scut.styl
Created May 16, 2021 10:54 — forked from armornick/scut.styl
Translation of Scut to Stylus (https://davidtheclark.github.io/scut/)
/*
* Scut, a collection of Sass utilities
* to ease and improve our implementations of common style-code patterns.
* v1.1.2
* Docs at http://davidtheclark.github.io/scut
*
* Translated for Stylus by armornick
*/
scut-clearfix() {