Skip to content

Instantly share code, notes, and snippets.

View alexott's full-sized avatar
🏠
Working from home

Alex Ott alexott

🏠
Working from home
View GitHub Profile
@alexott
alexott / repl.bat
Created March 25, 2010 07:59 — forked from liebke/repl.bat
@echo off
setLocal EnableDelayedExpansion
set CLASSPATH="
for /R ./lib %%a in (*.jar) do (
set CLASSPATH=!CLASSPATH!;%%a
)
set CLASSPATH=!CLASSPATH!"
set CLASSPATH=%CLASSPATH%;src;test;config;data
echo CLASSPATH=%CLASSPATH%
java -Xmx1G -cp %CLASSPATH% jline.ConsoleRunner clojure.main -i run.clj -r
@alexott
alexott / comp_ns_find.clj
Created April 20, 2010 11:50
Module to find all Clojure modules in compiled .jar-files (listed in Classpath)
(ns comp-ns-find
(:require [clojure.contrib.seq :as seq]
[clojure.contrib.classpath :as cp]
[clojure.contrib.jar :as jar])
(:import (java.util.jar JarFile)))
(defn find-compiled-modules
"Performs search for clojure namespaces in .jar files"
[]
(map symbol
;; use of defrecords for https://jukkaz.wordpress.com/2010/08/26/age-discrimination-with-clojure/
(defrecord Person [name age])
(def persons1
[(Person. "Boris" 40)
(Person. "Betty" 32)
(Person. "Bambi" 17)])
(let [[minors majors] (separate #(<= (:age %) 18) persons1)]
(println minors)
(defn calc-occuriences-trans [^String text]
(let [res (reduce (fn [m ^Character c]
(let [ch (Character/toUpperCase c)]
(assoc! m ch (+ 1 (m ch 0))))) (transient {}) text)]
(persistent! res)))
;; (calc-occuriences-trans (slurp "/home/ott/tmp/1/dict" :encoding "ISO-8859-1")) => 1.5-2 sec
(defn calc-occuriences [^String text]
(let [tmap (map (fn [^Character ch] (hash-map (Character/toUpperCase ch) 1)) text)]
(apply merge-with + tmap)))
(defun string-join-accum (joiner strings accum)
(cond ((not strings) accum)
((not (cdr strings)) (concat accum (car strings)))
(t (string-join-accum joiner (cdr strings)
(concat accum (car strings) joiner)))))
(defun string-join (joiner strings)
(string-join-accum joiner strings ""))
(defun invoke-bash (command)
@alexott
alexott / ctest2junix.xsl
Created April 11, 2012 11:09
XSL stylesheet to transform CTest results into JUnit format to import into Jenkins
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/Site">
<testsuite>
<xsl:variable name="BuildName"><xsl:value-of select="@BuildName"/></xsl:variable>
<xsl:variable name="BuildStamp"><xsl:value-of select="@BuildStamp"/></xsl:variable>
<xsl:variable name="Name"><xsl:value-of select="@Name"/></xsl:variable>
<xsl:variable name="Generator"><xsl:value-of select="@Generator"/></xsl:variable>
<xsl:variable name="CompilerName"><xsl:value-of select="@CompilerName"/></xsl:variable>
@alexott
alexott / hbr_clj.clj
Created May 13, 2012 09:10
Example of web-service for hashing
(ns hbr-clj
(:use compojure.core ring.middleware.reload clojure.data.json)
(:require [compojure.route :as route])
(:import [org.apache.commons.codec.digest DigestUtils]))
(defroutes my-routes
(GET "/md5/:what" [what] (json-str {:what what :hash (DigestUtils/md5Hex what)}))
(route/not-found "<h1>Page not found</h1>"))
(def app (-> #'my-routes
@alexott
alexott / test.clj
Created August 13, 2012 12:20
Example to reproduce thread leak in ring-core (when parsing multipart uploads)
(ns rtest.core
(:gen-class)
(:use [ring.middleware params multipart-params keyword-params]
ring.adapter.jetty
)
)
(defn handler [request]
{:status 200
@alexott
alexott / minimial-cedet-config.el
Created October 22, 2012 07:30
Working configuration for CEDET from bzr & GNU Emacs (with working C++ & Java name completion)
;;; minimial-cedet-config.el --- Working configuration for CEDET from bzr
;; Copyright (C) Alex Ott
;;
;; Author: Alex Ott <alexott@gmail.com>
;; Keywords: cedet, C++, Java
;; Requirements: CEDET from bzr (http://cedet.sourceforge.net/bzr-repo.shtml)
;; Do checkout of fresh CEDET, and use this config (don't forget to change path below)
@alexott
alexott / cedet-1.1-startup.el
Created October 28, 2012 13:42
Working configuration for CEDET 1.1 & below (only separate releases, not included into GNU Emacs)
;;; cedet-1.1-startup.el --- Working configuration for CEDET 1.1 & below
;; Copyright (C) Alex Ott
;;
;; Author: Alex Ott <alexott@gmail.com>
;; Keywords: CEDET 1.1,
;; Requirements: CEDET 1.1 or below
(load-file "~/tmp/cedet-1.1/common/cedet.el")
(require 'semantic-decorate-include)