Skip to content

Instantly share code, notes, and snippets.

(defn n-map
"mapping function f on coll xs, using up to n concurrent evaluations.
returns an atom containing unordered results immidietly."
[n f xs]
(let [agents (cycle (map (fn [_] (agent nil)) (range n)))
r (atom [])]
(dorun
(map (fn [a v]
(send-off a
(fn [_ new] (swap! r conj (f new)))
(ns client-test
(:use [lamina.core]
[aleph.tcp]
[aleph.netty.core]
[gloss.core]
[gloss.io])
(:gen-class))
(def chopped-codec
(finite-frame
@shlomiv
shlomiv / banner_maker.clj
Created February 18, 2015 11:44
example writing antialiased text and an image on top of an existing image
(ns banner-maker.core
(:require [clojure.java.io :refer [as-url input-stream as-file file resource]])
(:import [java.awt Font RenderingHints])
(:gen-class))
(defn register-font [font]
(let [f (Font/createFont Font/TRUETYPE_FONT (input-stream font))]
(.registerFont (java.awt.GraphicsEnvironment/getLocalGraphicsEnvironment) f)
f))
(defn mapper-map [this ^Text key ^ArchiveReader warc-value ^MapContext context]
(let [i (.iterator warc-value)]
(loop []
(when (.hasNext i)
(let [^ArchiveRecord l (.next i)]
(println "got " (.available l))
(recur)))))
@shlomiv
shlomiv / count-clj-sloc.sh
Last active March 15, 2016 02:36 — forked from andrewvc/count-clj-sloc.sh
Counting SLOC in clojure is pretty easy since the syntax is so simple.
# Count SLOC
export SLF=`mktemp -t cljslocXXXX`; find src test -name "*.clj" | xargs egrep -v "(^[[:space:]]*$|^[[:space:]]*;)" | cut -d: -f1 > $SLF && echo "Files"; uniq -c $SLF; echo "Total" `cat $SLF | wc -l`; rm $SLF
// Split an rdd according to its partition number
def splitByPartition[T:ClassTag](rdd: RDD[T], hotPartitions:Int): (RDD[T], RDD[T]) = {
val splits = rdd.mapPartitions { iter =>
val partId = TaskContext.get.partitionId
val left = if (partId < hotPartitions) iter else empty
val right = if (partId >= hotPartitions) iter else empty
Seq(left, right).iterator
}
val left = splits.mapPartitions { iter => iter.next().toIterator}
@shlomiv
shlomiv / com.apple.spaces
Created August 17, 2016 23:45
defaults read com.apple.spaces
> defaults read com.apple.spaces
{
SpacesDisplayConfiguration = {
"Management Data" = {
"Management Mode" = 1;
Monitors = (
{
"Current Space" = {
id64 = 4;
type = 0;
@shlomiv
shlomiv / make-perf.sh
Last active December 6, 2016 23:52
A script for automatically downloading source, building and installing perf for ubuntu linux kernels. Useful if your kernel version does not have the required pacakages (linux-tools and linux-cloud-tools) available on ppa,
#!/bin/sh
# Author: Shlomi Vaknin
# Automatically build and install perf for ubuntu linux kernels.
# Useful if your kernel version does not have the required pacakages (linux-tools and linux-cloud-tools) available on ppa,
SCRIPT=$(readlink -f "$0")
BASEDIR=$(dirname "$SCRIPT")
echo "Automatic perf build and install script. \n"
@shlomiv
shlomiv / install-perf-on-ec2.sh
Last active December 9, 2016 22:27
Often in an aws emr cluster I will want to check what exactly is going on.. here is a little script that automates installing perf in any cluster node.
#!/bin/sh
# Author: Shlomi Vaknin
# Install perf with java flamegraphs on amazon ec2 instances
# let yarn using be able to sudo
sudo -s
echo "yarn ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
# install required packages
@shlomiv
shlomiv / shlomi-blender.py
Created January 11, 2017 23:14
My blender for video editing user profile.
import bpy
import os
def kmi_props_setattr(kmi_props, attr, value):
try:
setattr(kmi_props, attr, value)
except AttributeError:
print("Warning: property '%s' not found in keymap item '%s'" %
(attr, kmi_props.__class__.__name__))
except Exception as e: