Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
ifesdjeen / apply_to_values.clj
Created May 1, 2013 20:16
Apply to values (into hash)
(defn- apply-to-values [m f]
"Applies function f to all values in map m"
(into {} (for [[k v] m]
[k (f v)])))
@ifesdjeen
ifesdjeen / multimethods.clj
Created May 1, 2013 20:16
Clojure Multimethods
(defmulti even-odd
(fn [i]
(if (= 0 (mod i 2))
:even
:odd)))
(defmethod even-odd :even
[i]
(println "Even " i))
@ifesdjeen
ifesdjeen / with_tmp_file.clj
Created May 1, 2013 20:14
Do something within temporary directory
(defmacro with-temp-file
[f-sym & body]
`(let [prefix# (.toString (UUID/randomUUID))
postfix# (.toString (UUID/randomUUID))
~f-sym (java.io.File/createTempFile prefix# postfix#)]
(try
(do ~@body)
(finally
(.delete ~f-sym)))))
@ifesdjeen
ifesdjeen / pprint.clj
Created May 1, 2013 20:00
Pretty-print object methods
(require '[clojure.reflect :as r])
(use '[clojure.pprint :only [print-table]])
(print-table (:members (r/reflect"foo")))
@ifesdjeen
ifesdjeen / fn.clj
Last active December 16, 2015 21:09
Always think of Clojure functions, when you pass them around, as of values, not references. Whenever you change the root, previous function (one that you have already passed around), won't change. Only future calls will yield new value.
;; Declare a function
(defn fun1 [] (println 1))
;; And a hash that would capture that function
(def h {:key fun1})
;; => {:key #<user$fun1 user$fun1@5e540696>}
;; Now, check out the value of the key
(:key h)
;; => #<user$fun1 user$fun1@5e540696>
@ifesdjeen
ifesdjeen / AppDelegate.h
Last active December 16, 2015 06:29
How secure is your operating system? On Mac Os X all your keystrokes can be logged with a utility written by Objective C first-timer without any concerns.
#import <Cocoa/Cocoa.h>
static id monitorKeyDown;
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@end

Because we're meeting in different places, it's hard sometimes to satisfy the rider of all the speakers. When bands are making performance, they have a list of things concert organizers should have in order for concert to be successfull and on a good level.

Don't get surprised that it's easier to hook up MacBook with MDP than your Lenovo laptop. It just is.

Neither one of mentioned points is criticizing or trying to fix an ability to speak in public. Instead, all the points are purely technical. No matter how well you can speak, slides that people can't see, inability to use your laptop, or an outage during live-coding session may ruin your talk.

After seeing common patterns, we've decided to make that one:

Checklist for speakers

@ifesdjeen
ifesdjeen / shunting_yard.clj
Created November 25, 2012 19:35
Check wether it's easier or harder to read the code that way
;;
;; Leaving defaccumulator/defcompound details aside, when you see following lines, is it clear what's going on?
;; Or is it easier to read a straightforward loop, without dispatcher-based magic?
;;
;; As for me, advantage is that rules are completely decouple from each other. It's very easy to understand and
;; debug parts of the processing, rather than try to figure out how the complete algorithm works at once.
;; When reading algorithm description, you see clear definition of steps and rules, although when you see
;; the implementation it's all combined into one humongous function, that's doing everything, and dispatch rules
;; are wowed, which makes it even more complex.
;;
(ns clojurewerkz.cassaforte.thrift.column
(:use [clojurewerkz.support.string :only [to-byte-buffer]]
[clojurewerkz.cassaforte.bytes :only [encode]])
(:import [org.apache.cassandra.thrift Column]))
(defn ^Column build-column
"Converts clojure map to column"
([^String key ^String value]
(build-column to-byte-buffer key value (System/currentTimeMillis)))
@ifesdjeen
ifesdjeen / get_in.rb
Created August 14, 2012 09:21
Clojure get_in in ruby
# Returns value from hash based on the path
#
# @param hash [Hash] - hash to retrieve values from
# @param path [Array] - non-empty array representing recursive path
#
# @returns [Object] - an object located within an array on the given path
#
# Examples:
#
# get_in({:a => {:b => {:c => 2}}}, [:a, :b, :c]) # => 2