Skip to content

Instantly share code, notes, and snippets.

View madstap's full-sized avatar

Aleksander Madland Stapnes madstap

View GitHub Profile
@sinclairtarget
sinclairtarget / bernoulli.c
Created August 17, 2018 20:22
Lovelace's Note G Program in C
#include <stdio.h>
/*
* Calculates what Ada Lovelace labeled "B7", which today we would call the 8th
* Bernoulli number.
*/
int main(int argc, char* argv[])
{
// ------------------------------------------------------------------------
// Data
@borkdude
borkdude / as_some.clj
Last active June 25, 2018 19:07
as-some-> macro
(defmacro as-some->
"Hybrid of as-> and some->."
[expr name & forms]
(let [steps (map (fn [step] `(if (nil? ~name) nil (-> ~name ~step)))
forms)]
`(let [~name ~expr
~@(interleave (repeat name) (butlast steps))]
~(if (empty? forms)
name
(last steps)))))
@stuarthalloway
stuarthalloway / missing_keys_specs.clj
Created October 14, 2017 11:44
I think it would be a mistake to introduce temporal coupling to prevent typos.
;; I think it would be a mistake to introduce temporal coupling to prevent typos.
;; The example program below lets you identify "missing" keys specs at
;; the time and place of your choosing, and then handle them as you
;; deem appropriate, without imposing those decisions on other
;; users of spec.
(require '[clojure.spec.alpha :as s]
'[clojure.set :as set])
import React, { PropTypes, Component } from 'react'
import styles from './../styles/Collapse.scss'
class Collapse extends Component {
static propTypes = {
open: PropTypes.bool,
className: PropTypes.string,
}
@rwilson
rwilson / code.clj
Created March 21, 2016 23:09
Multiple methods in multimethod match dispatch value
;; Happens sometimes when clojure.pprint/simple-dispatch or clojure.pprint/print-method
;; or whatnot don't have a stated preference for an object type that matches multiple
;; dispatch values. Here's a way around that.
;; Define a type that will match multiple dispatch values (IDeref & IPersistentMap)
user> (defrecord Foo [bar]
clojure.lang.IDeref
(deref [this]
(if bar
this
@gja
gja / core.clj
Last active August 15, 2022 16:25
Building a lein uberjar without any compilation
(ns simplequest.core)
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
Android Emulator usage: emulator [options] [-qemu args]
options:
-sysdir <dir> search for system disk images in <dir>
-system <file> read initial system image from <file>
-datadir <dir> write user data into <dir>
-kernel <file> use specific emulated kernel
-ramdisk <file> ramdisk image (default <system>/ramdisk.img
-image <file> obsolete, use -system <file> instead
-initdata <file> same as '-init-data <file>'
-data <file> data image (default <datadir>/userdata-qemu.img
@stathissideris
stathissideris / tree-seq-extra.clj
Last active July 2, 2023 11:33
Like Clojure's tree-seq, but with depth info for each node or the full path (recursive - blow up the stack for deep trees)
(defn tree-seq-depth
"Returns a lazy sequence of vectors of the nodes in a tree and their
depth as [node depth], via a depth-first walk. branch? must be a fn
of one arg that returns true if passed a node that can have
children (but may not). children must be a fn of one arg that
returns a sequence of the children. Will only be called on nodes for
which branch? returns true. Root is the root node of the tree."
[branch? children root]
(let [walk (fn walk [depth node]
(lazy-seq
@ptaoussanis
ptaoussanis / transducers.clj
Last active December 17, 2021 13:54
Quick recap/commentary: Clojure transducers
(comment ; Fun with transducers, v2
;; Still haven't found a brief + approachable overview of Clojure 1.7's new
;; transducers in the particular way I would have preferred myself - so here goes:
;;;; Definitions
;; Looking at the `reduce` docstring, we can define a 'reducing-fn' as:
(fn reducing-fn ([]) ([accumulation next-input])) -> new-accumulation
;; (The `[]` arity is actually optional; it's only used when calling
;; `reduce` w/o an init-accumulator).