Skip to content

Instantly share code, notes, and snippets.

View priyatam's full-sized avatar

Priyatam Mudi priyatam

View GitHub Profile
@zahardzhan
zahardzhan / machine.clj
Created February 13, 2010 12:31
Turing machine in Clojure
;;; -*- mode: clojure; coding: utf-8 -*-
;;; author: Roman Zaharov <zahardzhan@gmail.com>
(ns clojure.turing-machine.machine)
(in-ns 'clojure.turing-machine.machine)
(defn convert-rules [rules]
(apply conj [] (for [rule rules :let [[state read jump write move] rule]]
{:state state :read read :jump jump :write write :move move})))
@christian-oudard
christian-oudard / gfm.py
Created June 29, 2010 18:51
Github Flavored Markdown in Python
import re
from hashlib import md5
def gfm(text):
# Extract pre blocks.
extractions = {}
def pre_extraction_callback(matchobj):
digest = md5(matchobj.group(0)).hexdigest()
extractions[digest] = matchobj.group(0)
return "{gfm-extraction-%s}" % digest
@DmitrySoshnikov
DmitrySoshnikov / python-closures.py
Created November 15, 2010 12:03
Understanding Python's closures
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables
@michiakig
michiakig / ants.clj
Created July 19, 2011 22:37
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT 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.
;dimensions of square world
@jokull
jokull / grid.styl
Created December 20, 2011 15:39
Stylus Skeleton responsive grid
// Based on getskeleton.com
@import "nib/clearfix"
@import "nib/reset"
global-reset()
columns = 16
column-width = 57px // Ends up as 1232px layout
gutter-width = 20px
@pelle
pelle / accounts.clj
Created May 8, 2012 14:37
Using database functions in Datomic transactions and annotating transaction history
(use '[datomic.api :only [q db] :as d])
(def uri "datomic:mem://accounts")
;; create database
(d/create-database uri)
;; connect to database
(def conn (d/connect uri))
@cgrand
cgrand / restrict-map.clj
Created May 29, 2012 10:15
Restricting nested maps to keys of interest
;; I could have used a closed dispatch (aka cond) but you may find this version more enjoyable
;; the spec format is the one provided by BG
(defprotocol Selector
(-select [s m]))
(defn select [m selectors-coll]
(reduce conj {} (map #(-select % m) selectors-coll)))
(extend-protocol Selector
@jamesmacaulay
jamesmacaulay / Clojure.sublime-settings
Last active January 18, 2021 19:01
Clojure stuff for Sublime Text 2. Files live in ~/Application Support/Sublime Text 2/Packages/User
// installed Clojure packages:
//
// * BracketHighlighter
// * lispindent
// * SublimeREPL
// * sublime-paredit
{
"word_separators": "/\\()\"',;!@$%^&|+=[]{}`~?",
"paredit_enabled": true,
@jamesmacaulay
jamesmacaulay / profiles.clj
Last active November 15, 2023 01:18
My ~/.lein/profiles.clj at the moment.
{:user {:dependencies [[org.clojure/tools.namespace "0.2.3"]
[spyscope "0.1.3"]
[criterium "0.4.1"]]
:injections [(require '(clojure.tools.namespace repl find))
; try/catch to workaround an issue where `lein repl` outside a project dir
; will not load reader literal definitions correctly:
(try (require 'spyscope.core)
(catch RuntimeException e))]
:plugins [[lein-pprint "1.1.1"]
[lein-beanstalk "0.2.6"]
@Chouser
Chouser / externs_for_cljs.clj
Created June 17, 2013 13:44
Generate an externs.js file for arbitrary JS libraries for use in advanced Google Closure compilation, based on the ClojureScript code that uses the libraries.
(ns n01se.externs-for-cljs
(:require [clojure.java.io :as io]
[cljs.compiler :as comp]
[cljs.analyzer :as ana]))
(defn read-file [file]
(let [eof (Object.)]
(with-open [stream (clojure.lang.LineNumberingPushbackReader. (io/reader file))]
(vec (take-while #(not= % eof)
(repeatedly #(read stream false eof)))))))