Skip to content

Instantly share code, notes, and snippets.

Michał Marczyk michalmarczyk

Block or report user

Report or block michalmarczyk

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
View vertigo_binary_search.clj
(ns bar.baz
(:require [vertigo.core :as vc]
[vertigo.structs :as vs]))
;;
;; based off of work by Michał Marczyk
;; http://stackoverflow.com/questions/8949837/binary-search-in-clojure-implementation-performance
;;
(set! *warn-on-reflection* true)
View reducticons.clj
; discussed here https://groups.google.com/d/msg/clojure-dev/cWzMS_qqgcM/7IAhzMKzVigJ
; nested reduced
=> (transduce (comp (take 1)) conj [:a])
[:a]
=> (transduce (comp (take 1) (take 1)) conj [:a])
#<Reduced@65979031: [:a]>
=> (transduce (comp (take 1) (take 1) (take 1)) conj [:a])
#<Reduced@fcbc8d1: #<Reduced@60bea99a: [:a]>>
=> (transduce (comp (take 1) (take 1) (take 1) (take 1)) conj [:a])
@laurentpetit
laurentpetit / mutabots.clj
Last active Aug 29, 2015 — forked from cgrand/mutabots.clj
Reimplementation of transducers, in terms of processing functions instead of reducing functions. WIP.
View mutabots.clj
(ns mutabots
"Reimplementation of transducers, in terms of processing functions instead
of reducing functions.
tl;dr: reducing-fn based transducers are a special case, influenced by reducers,
of processing-fn based transducers.
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing
concept of reducing functions.
To sum it up, a transducer has currently the signature :
View gist:4891dafdd31f0dcbc727
; passes
(let [{:keys [bar foo]
:or {foo 1
bar (inc foo)}} {}]
(assert (= foo 1))
(assert (= bar 2)))
; does not compile
(let [{:keys [foo bar]
:or {foo 1
View foo.clj
(defn sig [x]
(:sig (meta (resolve x))))
(defmulti type-of (comp type first list))
(defmethod type-of :function [thing & _] (sig thing))
(defmethod type-of java.util.List [expr & a]
(conj (map #(type-of % (first a)) (rest expr))
View life.clj
;; xercise 1 - Cellular Automaton - Cellular automata are fun and fairly easy to implement.
;; In this exercise you will build Conway's Game of Life in Clojure with a Swing GUI.
;; Kudos For Oregu (author).
(ns life
(:import (javax.swing JFrame JPanel JButton JTextArea JLabel SwingUtilities JScrollPane WindowConstants)
(java.awt Graphics BorderLayout FlowLayout Color Dimension)
(java.awt.event MouseListener ActionListener MouseEvent MouseAdapter))
(:use [clojure.contrib.seq-utils :only (flatten)]))
@chrisschreiner
chrisschreiner / color-utils.clj
Created Jul 11, 2010
Color utilities for CSS
View color-utils.clj
(import 'java.awt.Color)
(def *default-color-fraction* 0.2)
(def *default-blend-fraction* 0.5)
(defn- format-hex [c]
(str "#" (format "%02x%02x%02x"
(.getRed c)
(.getGreen c)
View gist:479867
(ns http-client
(:import [org.mortbay.jetty.client HttpClient ContentExchange]
[java.io ByteArrayInputStream]))
(defn request
"Takes a request conforming to the Ring specification and sends it to
the server. Returns a Ring response."
[req]
(let [{:keys [scheme server-name server-port uri query-string content-type headers character-encoding request-method body]} req
client (HttpClient.)
View gist:492566
(defmacro nth->
"Fast lookup into nested vectors. Indices must be ints"
[coll [id & idx]]
(let [coll (with-meta coll {:tag Indexed})]
(if (seq idx)
`(nth-> (.nth ~coll ~id) ~idx)
`(.nth ~coll ~id))))
@Chouser
Chouser / avoid-force-print.clj
Created Sep 21, 2010
Avoid forcing lazy seqs when printing
View avoid-force-print.clj
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
; modified by Chris Houser
(require '[clojure.contrib.reflect :as hack])
You can’t perform that action at this time.