Skip to content

Instantly share code, notes, and snippets.

(defmacro letp [expr bindings & body]
(let [parted
(partition 3 bindings)
true-bindings
(vec (apply concat
(map #(take 2 %) parted)))
false-bindings
(vec (apply concat
(map #(list (first %) (last %)) parted)))]
(defn dynamic-record [base-name field-names & init-values]
(let [klass (eval `(defrecord ~(gensym base-name) ~(vec field-names)))
ctor (first (.getConstructors klass))
vals (take (count field-names)
(concat init-values (repeat nil)))]
(.newInstance ctor (into-array Object vals))))
(dynamic-record "MyRecord" '(foo bar) :foo)
;; -> #:user.MyRecord14544{:foo :foo, :bar nil}
(ns fxtrial.core
(:import javax.script.ScriptEngineManager
com.sun.javafx.api.JavaFXScriptEngine))
(def engine (.getEngineByName (ScriptEngineManager.) "javafx"))
(defn wrap-fxfn [fxfn]
(let [invoke
(first (filter #(= (.getName %) "invoke")
import org.jfxtras.lang.XBind;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.HBox;
import javafx.scene.control.*;
function run():Void {
try {
;; the project file
(defproject lein-javafx "0.1.0"
:dependencies [[javafxc "1.3.1"]]
:hooks [leiningen.hooks.lein-javafx-hooks])
;; the javafxc task file
(ns leiningen.javafxc
module A where
import Data.HList.CommonMain
data A = A deriving (Show)
ls = hCons "hi" $ hCons A $ hNil
upls = hUpdateAtType "bye" ls
@polypus74
polypus74 / dptc.nim
Last active March 7, 2018 22:34
default params with type classes
let i: int64 = 0
let j: float64 = 1.1
proc g(x: distinct SomeNumber = 1, y: distinct SomeNumber = 1.1) = discard
g(i,j) # OK
g(j,i) # Error
# I have tried other combinations without use of distinct. Not sure
# why the compiler complains about this, seems it should be ok?
@polypus74
polypus74 / newsbt
Last active March 20, 2018 00:50
Create new sbt project with git & ensime setup
#!/usr/bin/bash
DEFAULT_TEMPLATE="sbt/scala-seed.g8"
function err {
echo "error: $1, exiting."
exit 1
}
if [[ -z "$1" ]]
@polypus74
polypus74 / atomic_enum.rs
Created July 3, 2018 14:38
atomic enum in rust
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
pub enum RunFlagState {
Running = 0,
Paused = 1,
Cancelled = 2,
}
// TODO: is there some mechanism to automate this (nightly)?