Skip to content

Instantly share code, notes, and snippets.

Sergey Yavnyi blacktaxi

Block or report user

Report or block blacktaxi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blacktaxi
blacktaxi / gist:1575749
Created Jan 7, 2012
Generating random points inside a circle
View gist:1575749
import random
random.seed()
import math
def rnd(_from=0, _to=1): return _from + random.random() * (_to - _from)
def rectangle_random(W=2, H=2):
return (rnd(0, W), rnd(0, H))
@blacktaxi
blacktaxi / ruby-fmt.clj
Created Jan 25, 2012
Ruby-like string interpolation in Clojure
View ruby-fmt.clj
; Ruby has an awesome feature -- string interpolation. Read about it on the internet.
; On the other hand, Clojure only has cumbersome Java string formatting, which can not be
; used without pain after you've tried Ruby.
; So here's this simple macro that basically allows you to do most things you could do
; with Ruby string interpolation in Clojure.
(ns eis.stuff
(:require [clojure.string]))
View interpolate.clj
;;; ENVIRONMENTAL IMPACT STATEMENT
;;;
;;; This program was written on recycled memory.
;;; No cons cells were created.
;;;
(ns interpolate
(:use [clojure.walk :only (postwalk)]))
(defmacro s
@blacktaxi
blacktaxi / main.clj
Created Jan 25, 2012 — forked from lynaghk/main.clj
Cassowary constraint solver in ClojureScript
View main.clj
;;Using the Cassowary constraint solver from ClojureScript
;;This demo shows using multimethods for readable constraint syntax using +, -, and =.
;;Output is a row of circles with random radii spaced so that the space between their boundaries is uniform.
(ns c2.main
;;refer-clojure :exclude is currently broken in ClojureScript master
;;Ticket open: http://dev.clojure.org/jira/browse/CLJS-114
;;Fix applied here: https://github.com/lynaghk/clojurescript/tree/114-refer-clojure-exclude
(:refer-clojure :exclude [+ - =])
@blacktaxi
blacktaxi / bells.clj
Created Jan 25, 2012 — forked from jennifersmith/bells.clj
Cheesy Holiday Music and bell synthesis example
View bells.clj
(ns overtone-xmas.bells
( :use [overtone.live]
[overtone.sc.machinery.defcgen]))
;;http://computermusicresource.com/Simple.bell.tutorial.html
(def dull-partials
[
0.56
@blacktaxi
blacktaxi / haskjure.clj
Created Jan 26, 2012 — forked from djhworld/haskjure.clj
useful haskell functions that I can't seem to find in clojure
View haskjure.clj
(defn group [xs]
"splits its sequence argument into a list of lists of equal, adjacent elements."
(partition-by identity xs))
(defn zip [xs ys]
"makes a list of vector tuples, each tuple containing elements of both sequences occuring at the same position"
(map vector xs ys))
(defn lines [str]
"For a given string, split it into a vector using a newline terminator as a delimiter"
@blacktaxi
blacktaxi / custom-clojure-map.clj
Created Jan 27, 2012 — forked from david-mcneil/custom-clojure-map.clj
Creating a custom Clojure map type
View custom-clojure-map.clj
(ns people
(:use [clojure.string :only (join)]
[clojure.pprint :only (pprint simple-dispatch)]))
;; we can make maps using the special literal form:
{:a 100
:b 200}
(class {:a 100 :b 200})
@blacktaxi
blacktaxi / fsm.clj
Created Jan 27, 2012 — forked from Pet3ris/fsm.clj
Finite State Machine in Clojure core.logic
View fsm.clj
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |
View monad.clj
(ns monad-explore.core
(:use clojure.algo.monads))
(defmacro let?
"Almost the same as let. If you add the :ensure keyword paired with
some predicate as a var in the let form, let? will not continue
unless the predicate evaluates to true. (The predicate will have
access to all bindings above.)"
[bindings & body]
(let [[bind [kwd pred & more]] (split-with (complement #{:ensure}) bindings)]
@blacktaxi
blacktaxi / const-macros.clj
Created Feb 7, 2012
Macros for defining constants in Clojure
View const-macros.clj
(defmacro defconst [const-name const-val]
`(def
~(with-meta const-name
(assoc (meta const-name) :const true))
~const-val))
(defmacro defconsts [bindings]
`(do
~@(map (fn [[const-name const-val]]
`(defconst ~const-name ~const-val))
You can’t perform that action at this time.