Skip to content

Instantly share code, notes, and snippets.

(defn fibonacci-loop [n]
(loop [iter 0 fibs '()]
(cond
(= iter n) (reverse fibs)
(= iter 0) (recur (inc iter) (conj fibs 1))
(= iter 1) (recur (inc iter) (conj fibs 1))
:else (recur (inc iter) (conj fibs (reduce + (take 2 fibs))))
)))
// Shall be executed with -Dfile.encoding=UTF-16 to construct correct String instance
public class LigatureTest {
public static void main(String[] args) {
byte[] baffle = "ba\uFB00le".getBytes(Charset.forName("UTF-16"));
System.out.println(new String(baffle).toUpperCase());
}
}
@martinhynar
martinhynar / scanDigitalCameraImages.sh
Last active December 30, 2015 22:58
For those lucky ones that have screwed their hard drives and recovered gigabytes of randomly named photos with PhotoRec. This script takes input folder and output folder and moves all files that have EXIF tag File Source with value Digital Camera. This serves as first step on a long journey of walking through and watching all the recovered image…
#!/bin/bash
if [ ! -d $1 ]; then
echo $1 " must be directory"
exit
fi
if [ ! -d $2 ]; then
echo $2 " must be directory"
exit
fi
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
(add-to-list 'load-path "~/.emacs.d/scripts")
(add-to-list 'load-path "~/.emacs.d/git-libs/es-lib")
(defvar my-packages '(cider
ZSH=$HOME/.oh-my-zsh
ZSH_THEME="fishy"
DISABLE_CORRECTION="true"
COMPLETION_WAITING_DOTS="true"
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
plugins=(jira git-fast history-substring-search completion history emacs oh-my-settings oh-my-company)
# PATHS
WORKBENCH=~/Workbench
PATH=~/bin:${PATH}
JAVA_HOME=/usr/java/latest/
PATH=${JAVA_HOME}:${PATH}
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
@martinhynar
martinhynar / jps.py
Last active August 29, 2015 14:04
Java's jps in Python using Twitter Commons
import os
import glob
import twitter.common.java.perfdata as twc
if __name__ == '__main__':
pattern = os.path.join('/tmp', 'hsperfdata_*', '*')
for path in glob.glob(pattern):
root, pid = os.path.split(path)
dirname = os.path.basename(root)
import multiprocessing
import time
import os
class PMonitor(multiprocessing.Process):
def __init__(self, process_id):
super(PMonitor, self).__init__()
self.process_id = str(process_id)
self.semaphore = multiprocessing.Event()
@martinhynar
martinhynar / gist:d149019d11e76f05da12
Last active February 22, 2023 12:55
ElasticSearch: Updating nested document in array

Given the document

curl -XPUT 'localhost:9200/test/me/here' -d '{
  "top" : [
    { "searchkey" : "change"},
    { "searchkey" : "keep"}
  ]
}'
@martinhynar
martinhynar / ES_Update.md
Last active August 29, 2015 14:08
Update existing document in ES?

Have existing document already in ES

{
  "service" : "A",
  "timestamp" : "2014-06-06T12:12:59.456+00:00"
}

and want to update it to get this