Skip to content

Instantly share code, notes, and snippets.

View lynxor's full-sized avatar

Dawid lynxor

  • private
  • South Africa
View GitHub Profile
@lynxor
lynxor / qsort_challenge.clj
Last active February 25, 2016 07:29
quicksort_challenge
(def sseq ["many" "functional" "languages" "are" "tied" "to" "mathematical" "calculation" "tools"])
(def iseq [1 7 2 5 20 13 2 1] )
(defn drop-nth [n l]
(concat (subvec l 0 n) (subvec l (+ n 1) (count l))))
(defn qsort [l]
(if (<= (count l) 1) l
(let [ pivot-pos (quot (count l) 2)
pivot (nth l pivot-pos)
var _ = require("underscore"),
async = require("async");
var l = _.range(20),
batch_size = 5,
batches = _.map(_.range(l.length / batch_size), function(i){
return l.slice(i*batch_size, i*batch_size + batch_size);
});
async.eachSeries(batches, function(batch, callback){
@lynxor
lynxor / gist:ae1234815ce72ceb2b03
Created September 19, 2014 07:43
Search replace for removing String (" blabla " + ) quotes
^(\s*)"([^"]*)"\s*\+
$1$2
@lynxor
lynxor / hanoi.js
Created March 28, 2014 21:24
Towers of hanoi
var _ = require("underscore");
function hanoi(numPieces) {
var stacks = [ _.range(1, numPieces + 1).reverse(), [], [] ];
function findOtherStackNo(one, two) {
return _.without([0, 1, 2], one, two)[0];
}
@lynxor
lynxor / sort.clj
Created May 9, 2013 13:19
Quicksort and mergesort
;quicksort
(defn remove* [n l]
(concat (subvec l 0 n) (subvec l (+ n 1) (count l))))
(defn qsort [l]
(if (<= (count l) 1)
l
(let [ length (count l)
pivot-pos (quot length 2)
pivot (nth l pivot-pos )
@lynxor
lynxor / binary_search_tree.clj
Last active December 17, 2015 03:59
binary search tree
(defn tconj [v t]
(cond (nil? t)
{:value v :left nil :right nil}
(< v (:value t))
{:value (:value t) :left (tconj v (:left t)) :right (:right t) }
(> v (:value t))
{:value (:value t) :left (:left t) :right (tconj v (:right t) ) }
:else t ;no dupes
))
@lynxor
lynxor / mcio.sh
Created November 22, 2012 10:34
mvn build with notifs
mvn clean install -DskipTests=true -Dpmd.skip=true -Dcobertura.skip=true -T 1.0C
if [ $? -eq 0 ]; then
notify-send "Build Success" -i /home/dawid/build_status/success.jpg
else
notify-send "Build Failure" -i /home/dawid/build_status/failure.jpg
fi
@lynxor
lynxor / reminder.sh
Created November 19, 2012 15:13
Quick reminder
sleep 3m; xmessage -nearmouse "Your tea is ready"
@lynxor
lynxor / findclass.sh
Created August 15, 2012 11:09
Search for classes/files in jars
#!/bin/bash
#Search for classes/files in jars
SEARCH_DIR=$1
SEARCH_PHRASE=$2
if [ -d $SEARCH_DIR ]; then
echo "Searching in $SEARCH_DIR ..."
else
echo "Please provide a directory to search as the first argument"
@lynxor
lynxor / dbref_dereference.js
Created May 2, 2012 13:23
Mongo DBRefs: dereferencing an array or just a single item
DBRef.fetch = function(obj, refname, callback){
if(_.isArray(obj[refname])){
if(obj[refname].length){
var ids = _.pluck(obj[refname], "oid");
db.collection(obj[refname][0].namespace).find({_id: {$in : ids}}, function(err, objs){
obj[refname] = objs;
callback(null,obj);
});
} else {
obj[refname] = [];