This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import scala.util.Random | |
import scala.collection.immutable.HashMap | |
import java.awt._ | |
import javax.swing._ | |
import scala.actors._ | |
import scala.actors.Actor._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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 | |
OlderNewer