Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Karsten Lang klang

🏠
Working from home
View GitHub Profile
@klang
klang / hardlink-deps.sh
Created Sep 26, 2010
changes physical files in lib and lib/dev to be hardlinks back to the maven repository living in ~/.m2 .. to reduce disk space used in a setting where _a lot_ of Clojure projects using Leiningen is tried in a limited disk space setting.
View hardlink-deps.sh
@klang
klang / compress_jpg.clj
Created Feb 20, 2011
change compression level without losing the metadata of a jpg file
View compress_jpg.clj
(ns sandbox.compress-jpg
(meta {:description "change compression level without losing the metadata of a jpg file"
:url "http://blog.carsoncheng.ca/2011/02/how-to-change-jpeg-compression-in.html"})
(:require clojure.java.io)
(:import [javax.imageio IIOImage ImageIO]
[javax.imageio.plugins.jpeg JPEGImageWriteParam]))
(defn compress-jpg [inputFile outputFile compressionQuality]
(let [image-reader (.next (ImageIO/getImageReadersByFormatName "jpg"))
image-writer (.next (ImageIO/getImageWritersByFormatName "jpg"))]
View fibos.clj
(defn fibos []
(map first (iterate (fn [[a b]] [b (+ a b)]) [0 1])))
@klang
klang / slime-override-mode
Created May 22, 2011
Slime-override-mode to fix paredit-(open|close)-(round|square|curly) and move the keys
View slime-override-mode
;; http://github.com/briancarper/dotfiles/raw/master/.emacs
;; {} are not handled correctly by paredit in the repl,
;; but these lines fixes it
(defvar slime-override-map (make-keymap))
(define-minor-mode slime-override-mode
"Fix SLIME REPL keybindings"
nil " SLIME-override" slime-override-map)
(define-key slime-override-map (kbd "<C-return>") 'paredit-newline)
(define-key slime-override-map (kbd "{") 'paredit-open-curly)
@klang
klang / scope.php
Created Jun 1, 2011
wierd scope rules in php
View scope.php
<?php
function test() {
global $data;
var_dump($data);
}
test();
$data = array(1,2,3);
?>
View one_liners.clj
(ns one-lineres)
;; 1. Multiple Each Item in a List by 2
(map #(* 2 %) (range 1 11))
;; 2. Sum a List of Numbers
(reduce + (range 1 1001))
;; 3. Verify if Exists in a String
(def words #{"scala" "akka" "play framework" "sbt" "typesafe"})
@klang
klang / foo.html
Created Jan 10, 2012
html array send to php action
View foo.html
<html>
<header>
<script type="text/javascript">
function btnClick(aBtn) {
with (aBtn.form) {
event.value = aBtn.name;
submit();
}
}
</script>
@klang
klang / toggle-related-files.el
Created Jun 1, 2012
Quick and dirty way to define a toggle between related files in emacs
View toggle-related-files.el
@klang
klang / git-dropbox.sh
Created Sep 15, 2012
git repository on dropbox
View git-dropbox.sh
export DROPBOX=~/Dropbox/repos
export newRepo=project-name
export NAME=$(git config --global --get user.name)
cd ~/projects/$newRepo
git init
git add .
git commit -m 'initial'
HERE=$(pwd)
@klang
klang / mother.pl
Created Dec 21, 2012
A simple little script to observe selected users activity on the system. When conducting training sessions, it's sometimes necessary to have your mother watching over you ..
View mother.pl
#!/usr/bin/perl
@users = ( 'klang' );
my $procs = qx/ps -ef/;
#my $login = qx/last/;
foreach my $user (@users) {
while ($procs =~ m/^ *(\w*).+ .:.. (.+)$/gm) {
my $usr = $1;
my $proc = $2;