Skip to content

Instantly share code, notes, and snippets.

View remvee's full-sized avatar

Remco van 't Veer remvee

  • 52°N, 5°E
View GitHub Profile
XDEF schrofer
schrofer
DCB.L 32,0 onzin
DCB.L 32,0 spatie
DCB.L 32*15,0
DC.L %00000000000000000000000000000000
DC.L %00000000000000000000000000000000
(ns #^{:author "Remco van 't Veer"
:doc
"Basic validation framework for maps. The constructed validator
functions take two arguments the before- and after state of the map.
They return a map of errors where keys are, typically, keys of the
input map and values are lists of keyworded errors or maps of keyword
errors to some relevant argument. For example:
((validator (not-blank :nr)
(ns remvee.metric.levenshtein
(:use [clojure.test]))
;; From: http://en.wikipedia.org/wiki/Levenshtein_distance
;;
;; int LevenshteinDistance(char s[1..m], char t[1..n])
;; {
;; // for all i and j, d[i,j] will hold the Levenshtein distance between
;; // the first i characters of s and the first j characters of t;
;; // note that d has (m+1)x(n+1) values
(ns pom
[:use clojure.test]
[:import java.util.Calendar java.util.Date java.util.TimeZone])
;; /*
;; * Phase of the Moon. Calculates the current phase of the moon.
;; * Based on routines from `Practical Astronomy with Your Calculator',
;; * by Duffett-Smith. Comments give the section from the book that
;; * particular piece of code was adapted from.
;; *
(ns roman [:use clojure.test])
(def num-to-dig {1 "I", 4 "IV", 5 "V", 9 "IX"
10 "X", 40 "XL", 50 "L", 90 "XC"
100 "C", 400 "CD", 500 "D", 900 "CM"
1000 "M"})
(def dig-to-num (into {} (map (fn [[k v]] [v k]) num-to-dig)))
(defn encode
@remvee
remvee / time.cljs
Last active June 25, 2022 00:34
Calculate week number in clojurescript
(defn week-number
"Week number according to the ISO-8601 standard, weeks starting on
Monday. The first week of the year is the week that contains that
year's first Thursday (='First 4-day week'). The highest week number
in a year is either 52 or 53."
[ts]
(let [year (.getFullYear ts)
month (.getMonth ts)
date (.getDate ts)
day (.getDay ts)
@remvee
remvee / image.cljs
Last active August 29, 2015 14:19
Draw image on a canvas with the given EXIF orientation
(defn draw-image [canvas img orientation]
(let [ctx (.getContext canvas "2d")
[width height] (.-width img) (.-height img)]
(case orientation
(1 nil) ; left top
(do
(set! (.-width canvas) width)
(set! (.-height canvas) height)
(.drawImage ctx img 0 0 width height))
@remvee
remvee / app.cljs
Last active August 29, 2015 14:13
Detect on screen keyboard
(defn detect-keyboard-on-screen!
"Try to detect keyboard going on and off screen and toggle class on
the element when applicable."
[el class]
(let [former-height (atom (.-innerHeight js/window))]
(.addEventListener
js/window "resize"
#(let [focus (.-activeElement js/document)
height (.-innerHeight js/window)]
(gclasses/enable el class
#!/usr/bin/env ruby
require 'base64'
require 'tempfile'
min, max = ARGV.map{|v| v.to_i}
raise "#{__FILE__} MIN MAX" unless min && max && min > 0 && min < max
MESSAGES = ["rechtop zitten!", "schouders naar achteren!", "stapelen!", "water drinken!"]
@remvee
remvee / i18n.rb
Last active August 29, 2015 14:02
Rake tasks to find missing translations by comparing available yml files.
namespace :i18n do
task en_bork: :environment do
I18n.locale = :en
en = I18n.t(".").except(:faker)
chef = replace_values!(en) do |val|
`echo #{val.inspect} | chef`.chomp.sub(/\s*Bork Bork Bork!/m, "")
end
File.open(Rails.root + "config/locales/en-bork.yml", "w") do |fd|