Skip to content

Instantly share code, notes, and snippets.

(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))))
@nikolaplejic
nikolaplejic / core.clj
Created September 2, 2010 17:54
File upload example in Compojure
(ns fileupload.core
(:use [net.cgrand.enlive-html
:only [deftemplate defsnippet content clone-for
nth-of-type first-child do-> set-attr sniptest at emit*]]
[compojure.core]
[ring.adapter.jetty])
(:require (compojure [route :as route])
(ring.util [response :as response])
(ring.middleware [multipart-params :as mp])
(clojure.contrib [duck-streams :as ds]))
@Chouser
Chouser / avoid-force-print.clj
Created September 21, 2010 13:38
Avoid forcing lazy seqs when printing
; 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])
@mislav
mislav / pagination.md
Created October 12, 2010 17:20
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@astanin
astanin / .XCompose
Created October 29, 2010 09:29
My Compose key configuration
include "/usr/share/X11/locale/en_US.UTF-8/Compose"
# Punctuation
# знаки препинания, необходимые в русском, которых нет в en_US.UTF-8/Compose
<Multi_key> <period> <minus> : "…" U2026 # HORIZONTAL ELLIPSIS, многоточие
<Multi_key> <period> <space> : "…" U2026 # HORIZONTAL ELLIPSIS, многоточие
<Multi_key> <?> <!> : "⁈" U2048 # QUESTION EXCLAMATION, ?!
<Multi_key> <period> <colon> : "…" # ELLIPSIS
# №: набирается в русской раскладке без ухищрений,
# Josiah Carlson - Programming Challange from Erann Gat:
# http://www.flownet.com/ron/papers/lisp-java/
# Given a list of words and a list of phone numbers, find all the ways that
# each phone number can be expressed as a list of words.
from collections import defaultdict
import sys
MAPPING = {'e':0, 'j':1, 'n':1, 'q':1, 'r':2, 'w':2, 'x':2, 'd':3, 's':3,
'y':3, 'f':4, 't':4, 'a':5, 'm':5, 'c':6, 'i':6, 'v':6, 'b':7, 'k':7,
@hypernumbers
hypernumbers / New Years Resolution - Learn eLisp For Emacs
Created December 24, 2010 23:38
Why not learn eLisp for Emacs in 2011?
Interested in learning eLisp for Emacs, ever thought you should?
I wanted to learn eLisp but there are no decent beginners' book - so I decided to write one - and by decent I mean super-basic starting assuming you know nothing at all.
It is my 'official' side-project; something to work on when I am bored or blocked in my main work.
You can see how much progress I have made here:
http://learn-elisp-for-emacs.org/
The book will get written quicker if other people muck in.
@fogus
fogus / emagic.clj
Created January 7, 2011 18:22
how to make your own forms indent properly in emacs with clojure-mode
(defn pumpkin [op & args]
(apply op args))
(pumpkin +
1
2
3)
;; in emacs do:
;; M-x eval-expression
@isaacs
isaacs / callbacksarehard.js
Created January 12, 2011 02:29
let's go shopping!
// before
mainWindow.menu("File", function(err, file) {
if(err) throw err;
file.openMenu(function(err, menu) {
if(err) throw err;
menu.item("Open", function(err, item) {
if(err) throw err;
item.click(function(err) {
if(err) throw err;
mainWindow.getChild(type('Window'), function(err, dialog) {
@zaius
zaius / background.sh
Created January 16, 2011 23:29
How to redirect a running process output to a file and log out
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)