Skip to content

Instantly share code, notes, and snippets.

View introspect.clj
(ns introspect
(:require [clindex.api :as clindex]
[clindex.forms-facts.core :as forms-facts]
[clindex.utils :as clindex-utils]
[datascript.core :as d]
[clojure.pprint :as pprint]
[clojure.walk :as w]
[clojure.java.io :as io]
[clojure.string :as str]))
@mharju
mharju / gist:4094920
Created Nov 17, 2012
method to transform number strings to finnish
View gist:4094920
# -*- coding: utf-8
numbers = (u'nolla',u'yksi',u'kaksi',u'kolme',u'neljä',u'viisi',u'kuusi',u'seitsemän',u'kahdeksan',u'yhdeksän',u'kymmenen')
suffixes = ((u'toista',u'kymmentä'), (u'sata',u'sataa'))
exponents = ((u'',u''), (u'tuhat',u'tuhatta'), (u'miljoona','miljoonaa'))
def ones(n, s):
if s == 0 or n == 1:
return u''
return numbers[s]
View raymarch_test.glsl
float udBox( vec3 p, vec3 b ) {
return length(max(abs(p)-b,0.0));
}
float sdTorus( vec3 p, vec2 t )
{
vec2 q = vec2(length(p.xz)-t.x,p.y);
return length(q)-t.y;
}
@mharju
mharju / gist:3805082
Created Sep 29, 2012
Unknown pleasures album cover visualization for Processing. This is the version in http://www.youtube.com/watch?v=nYOh_laT4_Q
View gist:3805082
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer player;
AudioInput input;
FFT fft;
View Background.pde
void setup() {
size(1100, 600);
}
enum Axis { X, Y };
void setGradient(int x, int y, float w, float h, color c1, color c2, Axis axis ) {
noFill();
View circles.pde
class Circle {
PVector center;
float radius;
public Boolean intersects(ArrayList<Circle> circles) {
for(Circle other : circles) {
if(this.center.dist(other.center) <= (other.radius + this.radius)) {
return true;
}
@mharju
mharju / read-numbers.py
Created Jul 20, 2016
Helper script to read a bunch of 4 number codes from the user.
View read-numbers.py
import sys
import argparse
import tty
import termios
def getch():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
View spec.clj
; How to accomplish this so that the generator works as well?
(ns voting.core
(:require [clojure.spec :as s]
[clojure.spec.gen :as gen]))
(defn valid-card? [s]
(-> (loop [n 0 s (sort s)]
(if (empty? s) n
(when (= (inc n) (first s)) (recur (inc n) (next s)))))
(integer?)))
View satnav.core.clj
(ns satnav.core
(:require [clojure.string :as string]))
; Helpers
(def radius-earth 6371.0)
(defn degrees [rad] (* rad (/ 180.0 Math/PI)))
(defn radians [deg] (* deg (/ Math/PI 180.0)))
(defn normalize-lat [lat] (mod (+ (* 0.5 Math/PI) lat) (* 2 Math/PI)))
(defn normalize-lon [lon] (mod (+ Math/PI lon) (* 2 Math/PI)))
(defn hav [a] (/ (- 1 (Math/cos a)) 2))
@mharju
mharju / ecom.js
Created Jan 13, 2014
Ecom solution
View ecom.js
function calculate(o){return _.foldl(o,function(a,b){a[b.vat]=b.price+(a[b.vat]||0);return a},{})}