Skip to content

Instantly share code, notes, and snippets.

import XMonad
import Data.Monoid
import System.Exit
import XMonad.Actions.SpawnOn
import XMonad.Util.EZConfig
import XMonad.Hooks.DynamicLog
import qualified XMonad.StackSet as W
import qualified Data.Map as M
{- successively select elements from xs and remove one in each result list -}
import List
removeEach :: [a] -> [[a]]
removeEach xs =
zipWith (++) (List.inits xs) (tail (List.tails xs))
alternate :: (Num a) => [a] -> [a]
alternate = zipWith id (cycle [id, negate])
class String
alias_method(:orig_concat, :concat)
def concat(value)
orig_concat value.force_encoding(Encoding::UTF_8)
end
end
(import '(java.awt Frame)
'(java.awt.event WindowListener WindowAdapter)
'(javax.media.opengl GLCanvas GLEventListener GL)
'(com.sun.opengl.util Animator ))
(def gear1 (ref nil))
(def gear2 (ref nil))
(def gear3 (ref nil))
(def angle (ref 0.0))
(import '(java.awt Color Dimension)
'(javax.swing JPanel JFrame Timer JOptionPane)
'(java.awt.event ActionListener KeyListener))
(use '[clojure.contrib.import-static]
'[clojure.contrib.seq-utils :only (includes?)])
(import-static java.awt.event.KeyEvent VK_LEFT VK_RIGHT VK_UP VK_DOWN)()
()
;; ^_^
(defproject tests "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/clojure-contrib "1.2.0"]
[org.clojars.automata/rosado.processing "1.1.0"]]
:dev-dependencies [[swank-clojure "1.3.0"]])
(defn map-ext [f x & xs]
(let [colls (cons x xs)
res (apply map f colls)
next (filter not-empty (map #(drop (count res) %) colls))]
(if (empty? next) res
(lazy-seq (concat res (apply map-ext f next))))))
@lenstr
lenstr / elevator.clj
Created April 28, 2012 00:01
Elevators
(defn elevator [commands]
(letfn [(ff-open [[cmd & rest]]
#(case cmd
:close (ff-closed rest)
:done true
false))
(ff-closed [[cmd & rest]]
#(case cmd
:open (ff-open rest)
:up (sf-closed rest)
@lenstr
lenstr / comp.hs
Created April 29, 2012 09:51
comp
-- LeNsTR
module Main where
comp :: (a -> a -> Bool) -> [a] -> Bool
comp f = comp' where
comp' (x:[]) = True
comp' (x:y:[]) = x `f` y
comp' (x:y:(h:t)) | x `f` y = comp' (y:h:t)
| otherwise = False
@lenstr
lenstr / core.clj
Created November 12, 2012 03:50
game-of-life
(ns game-of-life.core
(:require [clojure.string :as str]
[clojure.core.reducers :as r]))
(comment
" Rules
The universe of the Game of Life is an infinite two-dimensional orthogonal
grid of square cells, each of which is in one of two possible states,
alive or dead. Every cell interacts with its eight neighbours,