Skip to content

Instantly share code, notes, and snippets.

View chrisschreiner's full-sized avatar

Chris Schreiner chrisschreiner

  • Schpaencoder
  • Oslo, Norway, Europe
View GitHub Profile
(defn range-without-zero [from to]
(filter #(not (= 0 %)) (range from to)))
(def my-range (range-without-zero -8 9))
(def t-map-licoresse
(let [r (filter #(not (= 0 %)) (range -8 9))]
(concat (for [x r] [x -1])
(for [x (reverse r)]
[x 1]))))
(use 'clojure.walk)
(defmacro with-iota [& body]
"Provides the local 'iota' which starts at 0 and automatically self-increments"
(let [iota (gensym "whatever-")]
`(let [~iota ~(atom -1)]
~@(map #(postwalk-replace {'iota `(swap! ~iota inc)} %) body))))
(with-iota
(let [a iota
@chrisschreiner
chrisschreiner / recent-file-jump.el
Created April 13, 2010 19:05
Jump to recent file via Ctrl-#
(defvar shortcut-list '(1 2 3 4 5))
(defun unset-numeric-shortcuts (list)
(mapcar
'(lambda (n)
(global-unset-key (read-kbd-macro (format "C-%d" n))))
list))
(unset-numeric-shortcuts shortcut-list)
(defun slime-compilation-finished (result)
(with-struct (slime-compilation-result. notes duration successp) result
(setf slime-last-compilation-result result)
(slime-show-note-counts notes duration successp)
(when slime-highlight-compiler-notes
;(slime-highlight-notes notes)
(growl (format "%s" (second (first notes)))
;(run-hook-with-args 'slime-compilation-finished-hook notes)
)))
(defn inside-byte [v]
(cond
(< v 0) 0
(> v 255) 255
:else v))
(defn darker- [color fraction]
(let [fr (- 1.0 fraction)
red (inside-byte (-> (.getRed color) (* fr) Math/round))
green (inside-byte (-> (.getGreen color) (* fr) Math/round))
@chrisschreiner
chrisschreiner / color-utils.clj
Created July 11, 2010 12:00
Color utilities for CSS
(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)
// log every category
[[L4Logger rootLogger] setLevel:[L4Level all]];
// send log messages to console
L4ConsoleAppender *consoleAppender=[[[L4ConsoleAppender alloc] initTarget:YES withLayout: [L4Layout simpleLayout]] autorelease];
[[L4Logger rootLogger] addAppender: consoleAppender];
L4Logger *theLogger = [L4Logger loggerForClass:[L4FunctionLogger class]];
[theLogger setLevel:[L4Level debug]];
//
log4Info(@"The logging system has been initialized.");
///
- (ConfigureCellBlock)dimmedCell {
return [[^(UITableViewCell *cell) {
cell.backgroundColor = [self colorFor:@"sub.cell.background"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} copy] autorelease];
}
///
- (ConfigureBadgeBlock)standardBadge {
@chrisschreiner
chrisschreiner / gist:db32cde87300c0e76017
Created September 5, 2014 08:40
Writing succinct constraints
import Cocoa
struct Constraint {
typealias T = (attribute: CAConstraintAttribute, relativeTo:String, relatedAttribute: CAConstraintAttribute, offset: CGFloat)
let data: T
func create() -> CAConstraint {
let newConstraint: AnyObject! = CAConstraint.constraintWithAttribute(data.attribute, relativeTo: data.relativeTo, attribute: data.relatedAttribute, offset: data.offset)
return newConstraint as CAConstraint
}
import Cocoa
struct Constraint {
typealias T = (attribute: CAConstraintAttribute, relativeTo:String, relatedAttribute: CAConstraintAttribute, offset: CGFloat)
let data: T
func create() -> CAConstraint {
let newConstraint: AnyObject! = CAConstraint.constraintWithAttribute(data.attribute, relativeTo: data.relativeTo, attribute: data.relatedAttribute, offset: data.offset)
return newConstraint as CAConstraint
}