Skip to content

Instantly share code, notes, and snippets.

View NPException's full-sized avatar
🐈

Dirk Wetzel NPException

🐈
View GitHub Profile
@NPException
NPException / lua_amendments.lua
Last active October 30, 2023 16:31
Playdate code snippets
-- Tiny snippet to bring a sort-of `require` functionality,
-- where return values of a module (or pdz files in this case)
-- will be cached, and the file only be run once.
-- After `import`ing this file in your main file, you can use `require` similar to how you would in basic Lua.
-- This also adds convenience wrappers around `playdate.file.load()` and `playdate.file.run()`,
-- to pose as `loadfile()` and `dofile()` respectively.
local pd <const> = playdate
@NPException
NPException / caffeine-wrapper.clj
Last active May 9, 2022 05:56
Clojure snippets
(ns caffeine-wrapper.core
(:require [com.stuartsierra.component :as component])
(:import [com.github.benmanes.caffeine.cache Cache Caffeine]
[java.util.concurrent TimeUnit]
[clojure.lang ITransientMap]
[com.codahale.metrics MetricSet Gauge]))
(defn store
"Stores an element for the given key in the Caffeine cache.
@NPException
NPException / allergie_sort.clj
Last active October 19, 2021 09:41
Futtermittel-Allergie IgE-IgG Sortierung
(ns allergie-sort
(:require [clojure.string :as str]))
(def ^:private categories
'{Weizen :Pflanze
Soja :Pflanze
Reis :Pflanze
Mais :Pflanze
Gerste :Pflanze
Kartoffel :Pflanze
(defn ^:private encase-single-op
"Puts a single matching target operation in parentheses"
[expression target-op?]
;; no need to do something if it's already a simple expression
(if (= 3 (count expression))
expression
(loop [prev []
[a op b & more] expression]
(cond
(target-op? op)
@NPException
NPException / ants.clj
Created April 25, 2020 05:31 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
@NPException
NPException / clojureFor.java
Last active January 27, 2020 19:10
implementation of the "infer" method from nipafx' Twitch stream
private Stream<TypedRelation> infer() {
// Clojure's "for" macro works essentially just like this nested loop,
// except that the resulting stream/sequence is lazily generated.
Builder<TypedRelation> relations = Stream.builder();
for (Article a1 : articles) {
for (Article a2 :articles) {
@NPException
NPException / shockyCheatsheet.md
Last active August 1, 2017 08:48
Shocky cheatsheet

Shocky cheatsheet

This is a collection of placeholders to use within factoids for the bot Shocky on EsperNet IRC. They were collected by manually checking this list for used placeholders and testing them on EsperNet.

Factoid placeholders

Placeholder Description
%arg{idx}[-[to_idx]] examples: %arg0%, %arg1-3%, %arg4-% - prints out the provided argument with index idx. A range of arguments to be printed can also be given by appending a "-" to the index. If no to_idx is provided, all following arguments will be printed out.
%bot% the name of the bot
%chan% current channel
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
public interface INode {
/**
* @return node identifier
*/
public String getIdent();
@NPException
NPException / StatefulRandom.java
Created August 28, 2015 07:35
Stateful Random
import java.lang.reflect.Field;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
/**
* @author NPException
*
* @date 28.08.2015
*
*/