Skip to content

Instantly share code, notes, and snippets.

View jjl's full-sized avatar

jjl

View GitHub Profile
@jjl
jjl / no.py
Last active June 13, 2023 08:11
def node_lookup(nodes):
tpl = "pub(crate) unsafe fn {}node_lookup<K: Key>(ptr: {}, key: &K) -> Result<Lookup, LookupError> {{"
"\n\n".join(["".join(tidy(group(
inline(opener),
"let raw = ptr.as_ptr_unchecked() as *mut u8;",
"prefetch_node(raw);",
"let tag = ptr.tag();",
debug("if tag != 0 { debug_assert!((&*raw.cast::<NodeHeader>()).tag == tag); }"),
group(
"match tag {",
# constants
panel-height: 75 # px
large-graph-width: 100 # px
small-graph-width: 25 # px
small-graph-height: 25 # px
sensor-refresh: 100 # milliseconds
sensor-refresh-slow: 1000 # milliseconds
graph-refresh: 500 # milliseconds
# sensor inputs
## Trait tables
An alternative idea I've been playing with recently takes inspiration
from game design, where ECS (entity component system) libraries are
the norm.
Objects normally can be thought of as a set of named fields. In an
ECS, an entity is just an id and it can have any number of
components. A component is the set of named fields traditionally like
module Main (main) where
import Prelude (Unit, ($), pure, unit)
import Data.Maybe (Maybe(..))
import Data.Nullable (toMaybe)
import DOM.Simple (Element)
import DOM.Simple.Document (document)
import DOM.Simple.Console (log)
import Effect (Effect)
import FFI.Simple ((...), args2, delay)
@jjl
jjl / main.cpp
Created September 6, 2016 09:44
boilerplate yay
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int main (int argc, char *argv[]) {
vector<string> args;
for (int i = 0; i < argc; i++) {
args.push_back(string(argv[i]));
boot.user> (wtf? clojure.lang.PersistentVector)
(deftype++ clojure.lang.PersistentVector
:bases [c.l.APersistentVector c.l.IEditableCollection c.l.IKVReduce c.l.IObj c.l.IReduce]
;; methods
(^PersistentVector$Node .access$000 [self j.u.concurrent.atomic.AtomicReference int c.l.PersistentVector$Node])
(^PersistentVector .adopt [self j.l.Object<>])
(^Object<> .arrayFor [self int])
(^ITransientCollection .asTransient [self])
(^PersistentVector$TransientVector .asTransient [self])
(^IPersistentVector .assocN [self int j.l.Object])
(defn reexport [ns sym]
(cond (not (symbol? sym)) (throw (ex-info "reexport takes a symbol!" {}))
(not (namespace sym)) (throw (ex-info "reexport takes a namespaced symbol" {}))
:else
(let [v (resolve sym)]
(intern ns (-> sym name symbol (with-meta (meta v))) @v))))
@jjl
jjl / update-swift-repos.sh
Created December 8, 2015 13:05
Updates all git repos in the current directory. Useful for building swift.
for x in *; do
if [ -d "$x" ]; then
pushd "$x"
if [ -d ".git" ]; then git pull; fi
popd
fi
done
Searching Dist::Zilla::Plugin::Git::NextRelease on cpanmetadb ...
-> FAIL Finding Dist::Zilla::Plugin::Git::NextRelease on cpanmetadb failed.
Searching Dist::Zilla::Plugin::Git::NextRelease () on metacpan ...
--> Working on Dist::Zilla::Plugin::Git::NextRelease
Fetching http://www.cpan.org/authors/id/K/KE/KENTNL/Dist-Zilla-Plugin-Git-NextRe
-> OK
-> FAIL Finding PPIx::Regexp on cpanmetadb failed.
Searching PPIx::Regexp (0.027) on metacpan ...
@jjl
jjl / usage.clj
Last active August 29, 2015 14:17
Midje intermingled tests
(ns my.namespace
(:require [util :refer [dev-prelude]]))
; in dev, import midje
; in live, strip out any code that uses midje
(dev-prelude)
(def always (constantly true))
; tests!
(facts "always"
(always) => true))