Skip to content

Instantly share code, notes, and snippets.

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

Dmitri Sotnikov yogthos

🤷‍♂️
View GitHub Profile
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.ImageObserver;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Mandelbrot extends Canvas implements ImageObserver {
@yogthos
yogthos / gist:506564
Created August 3, 2010 15:36
tetris in Clojure
(ns tetris
(:import
(javax.swing JFrame)
(java.awt Canvas Graphics Color Toolkit)
(java.awt.event ActionListener KeyListener KeyEvent))
(:gen-class))
(def *cols* 10)
(def *rows* 20)
(def *width* 300)
@yogthos
yogthos / gist:509994
Created August 5, 2010 16:44
infix math notation example
(def precedence {* 1, / 1, + 2, - 2})
(defn formula [& exprs]
(let [[x aop y bop z] (take 5 exprs)]
(if aop
(if bop
(if (< (get precedence aop) (get precedence bop))
(recur (into [(aop (formula x) (formula y))] (drop 3 exprs)))
(recur (into [x aop (bop (formula y) (formula z))] (drop 5 exprs))))
(aop (formula x) (formula y)))
(def precedence {mod 0, * 1, / 1, + 2, - 2})
(defn find-split [exprs]
(loop [op-pos 1
items exprs]
(let [[x opa y opb] (take 4 items)]
(if (and opa opb (> (get precedence opa) (get precedence opb)))
(recur
(+ op-pos 2)
(drop 2 items))
@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))))
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: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._
@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: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: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