Skip to content

Instantly share code, notes, and snippets.

View yogthos's full-sized avatar
🤷‍♂️

Dmitri Sotnikov yogthos

🤷‍♂️
View GitHub Profile
@yogthos
yogthos / gist:3411102
Created August 21, 2012 02:59
Metaballs without optimizations
(ns metaballs
(:import
[javax.swing JFrame]
[java.awt Canvas Graphics Color]
java.awt.image.BufferStrategy))
(def SIZE 250)
(defn direction [p v]
(if (or (> p SIZE) (neg? p)) (- v) v))
@yogthos
yogthos / gist:3260456
Created August 4, 2012 23:01
RSS in Clojure
(ns rss
(:use [clojure.xml :only [emit]])
(:import java.util.Date))
(defn format-time [time]
(.format (new java.text.SimpleDateFormat
"EEE, dd MMM yyyy HH:mm:ss ZZZZ") time))
(defmacro tag [id attrs & content]
`{:tag ~id :attrs ~attrs :content [~@content]})
@yogthos
yogthos / gist:3201386
Created July 29, 2012 19:42
Guestbook in Clojure

Install Leiningen and create a project

wget https://raw.github.com/technomancy/leiningen/preview/bin/lein
lein self-install
lein plugin install lein-noir 1.2.1
lein noir new guestbook
cd guestbook
@yogthos
yogthos / model.clj
Created April 16, 2012 02:32
dead simple web app
(ns model
(:require [clojure.java.jdbc :as sql]))
(def db {:classname "org.hsqldb.jdbcDriver"
:subprotocol "hsqldb"
:subname "user.db"
:create true})
(defn db-read [query]
(sql/with-connection db
@yogthos
yogthos / gist:2347762
Created April 10, 2012 01:20
Java object reader
(defn primitive? [o]
(some #{true}
(map
(partial isa? (.getClass o))
[Boolean Character Byte Short Integer Long Float Double String])))
(defn read-object [o]
(when o
(cond
@yogthos
yogthos / gist:2322780
Created April 6, 2012 20:41
simple Noir app
(ns small-site.server
(:require [noir.server :as server]
[noir.content.pages :as pages]
[clj-http.client :as client])
(:use noir.core
hiccup.core
hiccup.page-helpers))
(def code (slurp "src/small_site/server.clj"))
(def hilite-url "http://hilite.me/api")
@yogthos
yogthos / gist:1042889
Created June 23, 2011 16:17
Scala solutions
object Matmul {
def matgen(n: Integer): Array[Array[Double]] = {
var a = new Array[Array[Double]](n, n)
val tmp = 1. / n / n
Range(0, n) map ((i) =>
Range(0, n) map ((j) =>
a(i)(j) = tmp * (i - j) * (i + j)))
return a
}
@yogthos
yogthos / gist:1019750
Created June 10, 2011 20:51
Playing with actors
package main
import scala.util.Random
import scala.collection.immutable.HashMap
import java.awt._
import javax.swing._
import scala.actors._
import scala.actors.Actor._
package main
import java.awt.Graphics
import java.awt.Dimension
import javax.swing.JFrame
import java.awt.Color
import java.awt.Canvas
object Metaball extends Canvas {
val WIDTH = 600
@yogthos
yogthos / gist:898782
Created April 1, 2011 20:22
backprapagation neural net
(ns nn)
(defstruct network :ai :ah :ao :wi :wo :ci :co)
(defn rand-in-range [a b]
(+ (* (- b a) (rand)) a))
(defn make-matrix
([i j] (make-matrix i j 0.0))
([i j fill] (repeat i (repeat j fill))))