Skip to content

Instantly share code, notes, and snippets.

View borkdude's full-sized avatar

Michiel Borkent borkdude

View GitHub Profile
@borkdude
borkdude / Factors
Created May 23, 2010 18:44
Euler Problem 5 in Clojure
(defn prime? [n]
(cond (= n 2) true
(= n 3) true
:else
(not-any? #(zero? (mod n %))(range (int (Math/sqrt n)) n))))
(def my-primes (filter prime? (iterate inc 2)))
(defn update-or-insert [m k f d]
(if (contains? m k)
(defn force-set [n]
(if (set? n) n
(conj #{} n)))
(merge-with (fn [r l] (conj (force-set r) l)) {:a 1 :b 2} {:a 1 :b 3})
=> {:a #{1}, :b #{2 3}}
(defn siever2 [to-sieve sieved end]
(if (empty? to-sieve) sieved
(let [f (first to-sieve)
r (rest to-sieve)]
(if (> f (Math/sqrt end))
(into sieved to-sieve)
(siever2 (remove #(zero? (mod % f)) r)
(conj sieved f)
end)))))
(dotrace [siever2] (siever2 (range 2 32) [] 31))
public class ButtonOperator extends Button {
/*public ButtonOperator(final CalculatorController controller,
final AbstractOperator op) {
super(op.label);
this.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
controller.processOperator(op);
(defroutes handler
(GET "/" []
(html
(doctype :xhtml-strict)
(xhtml-tag "en"
[:head
[:meta {:http-equiv "Content-type"
:content "text/html; charset=utf-8"}]
[:title "adder"]
[:link {:href "/adder.css" :rel "stylesheet" :type "text/css"}]]
(defroutes handler
(GET "/" []
(html
(doctype :xhtml-strict)
(xhtml-tag "en"
[:head
[:meta {:http-equiv "Content-type"
:content "text/html; charset=utf-8"}]
[:title "test"]]
[:body "\u05d2"]))))
(defn guard [pred & args]
(if (apply pred args) args nil))
(def guard-> (partial guard >))
(guard-> 6 5) ; => (6 5)
(guard-> 5 6) ; => nil
D:\Mijn documenten\My Dropbox\dev\clojure-projects\hebrewajax>git push heroku ma
ster
Counting objects: 32, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (22/22), done.
Writing objects: 100% (32/32), 35.64 KiB, done.
Total 32 (delta 5), reused 0 (delta 0)
-----> Heroku receiving push
-----> Clojure app detected
@borkdude
borkdude / gist:1027851
Created June 15, 2011 19:14
Round Robin Tournament Scheduling Algoritme in Clojure
;; Dit programma maakt gebruik van het Round Robin Tournament Scheduling Algoritme
;; Zoals beschreven op http://en.wikipedia.org/wiki/Round-robin_tournament
;; Eerst volgen er wat losse fragmenten Clojure-code om het een en ander toe te lichten
;; De eigenlijke oplossing bestaat uit de functies turn-around en solutions
(def students (shuffle (range 100))) ; students is een lijst van de getallen 0 t/m 99, geshuffeld
(def first-half (take (/ (count students) 2) students)) ; de eerste helft van de lijst studenten
(def second-half (reverse (drop (/ (count students) 2) students))) ; de tweede helft
;;eventueel ook te schrijven met behulp van de threading macro -> als:
(def second-half (-> (count students) (/ 2) (drop students) reverse))
@borkdude
borkdude / core.clj
Created October 14, 2011 15:54
twitter-api test script
(ns twitter-api-test.followers-minus-friends
(:use
[twitter.api.restful :only [show-followers show-friends lookup-users]]
[clojure.set :only [difference]])
(:require [clojure.string :as string]))
(defn vector-to-comma-separated [vector]
(string/join "," vector))
(defn userinfos [idset]