Skip to content

Instantly share code, notes, and snippets.

View ponzao's full-sized avatar

Vesa Marttila ponzao

  • Helsinki, Finland
View GitHub Profile
(reduce ; Kootaan yks mappi sanoista.
(partial merge-with +) ; Kahdessa mapissa olevien avainten arvot summataan.
(map ; Suorittaa alla olevan funktion kaikille tiedostoille ({"foo" 1} {"baz" 10}).
#(frequencies ; Frequencies palauttaa mapin esiintymistä {"foo" 1, "bar" 4}.
(re-seq #"\w+" (slurp %))) ; Lukee tiedoston ja luo sekvenssin sanoista.
files)) ; Lista tiedostoista.
(deftest div-has-content-foo?
(is
(= (html [:div "foo"])
"<div>foo</div>")))
function dispatch(t)
return function(k)
if t[k] then t[k]() end
end
end
local dispatcher = dispatch({ f = function()
print("f")
end,
g = function()
(def person {:name "Vesa Marttila"
:address {:street "Pursimiehenkatu 21"}})
(update-in person
[:address]
merge {:postal-code "00150" :city "Helsinki"})
; -> {:name "Vesa Marttila", :address {:city "Helsinki", :postal-code "00150", :street "Pursimiehenkatu 13"}}
(-> (query #(SQLQueryImpl.
connection
(Configuration. templates)
%))
(from :actors)
(where (equal? :name "George Clooney")
(equal? :age 49))
(list :name :age))))))
type ID = Long
type Code = String
class User(val id: ID,
val name: String,
val friends: List[User])
class UserDto(val code: Code,
val name: String,
val friends: List[UserDto]) {
@ponzao
ponzao / rss-reader.clj
Created February 20, 2011 23:06
An RSS reader ported from Scala http://www.virtuousprogrammer.com/?p=159.
(ns rss-reader
(:import [java.io FileReader
BufferedReader])
(:require [clojure.xml :as xml]
[clojure.zip :as zip])
(:use [clojure.contrib.zip-filter.xml]
[hiccup.core]))
(defn print-feeds [feeds]
(doseq [[channel articles] feeds]
@ponzao
ponzao / LinkBuilder.scala
Created March 14, 2011 19:18
Inspired by https://gist.github.com/869408. Forking didn't seem to work :(
import scala.collection.mutable.MultiMap
import java.net.URLEncoder
import scala.collection.mutable.{Set => MSet, HashMap, MultiMap}
class LinkBuilder(path: String) {
val attributes = new HashMap[String, MSet[String]] with MultiMap[String, String]
override def toString(): String
= path +
"?" +
@ponzao
ponzao / index_of_any.clj
Created March 24, 2011 10:18
Explicit looping solution for the StringUtils.indexOfAny -problem.
(defn index-of-any [coll pred]
(loop [index 0
items coll]
(when (not (empty? items))
(if (pred (first items))
index
(recur (inc index) (rest items))))))
(index-of-any "foobar" #{\c \d \b}) ; -> 3