Skip to content

Instantly share code, notes, and snippets.

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

Karsten Lang klang

🏠
Working from home
View GitHub Profile
@klang
klang / F.sql
Last active August 29, 2015 13:56
code text added to database with f.sql and extracted with dump_source.sql, resulting in F.sql (notice uppercase) .. Seen from a versioning system (git) perspective, most of the lines in the original source have changed. The lines containing "begin" and "end;" are the only ones that are unchanged. Git's model state that, if the SHA-1 of the conte…
CREATE OR REPLACE FUNCTION "ORACLEGIT"."F" return varchar as
begin
return
'Hello world';
end;
#!/bin/sh
# a quick & dirty script to create a TinyCore initrd (for Core >= 4.2)
H=$( pwd )
M=$( mount | grep iso9660 | head -1 | awk '{print $3}' )
[ -z "$M" ] && echo "can not find mounted CD-ROM" && exit 1
D=$( mktemp -d )
@klang
klang / post-receive
Created March 25, 2014 07:32
hook to automatically deploy an app, when pushes to a repository is made. The script has to be placed in .git/hooks/post-receive and made executable. Script taken from: http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/
#!/bin/sh
# blog post: http://www.sitepoint.com/one-click-app-deployment-server-side-git-hooks/
## store the arguments given to the script
read oldrev newrev refname
## Where to store the log information about the updates
LOGFILE=./post-receive.log
# The deployed directory (the running site)
DEPLOYDIR=/var/www/html/simpleapp

Git attributes for .docx diffing

docx2txt

Download and install the docx2txt converter from http://docx2txt.sourceforge.net/

wget -O doc2txt.tar.gz http://docx2txt.cvs.sourceforge.net/viewvc/docx2txt/?view=tar
tar zxf docx2txt.tar.gz
cd docx2txt/docx2txt/

sudo make

@klang
klang / strange_python.py
Created September 9, 2014 06:36
Python oddities
# array
>>> [1]
[1]
>>> [1,]
[1]
# hash
>>> {'a':1}
{'a': 1}
>>> {'a':1,}
@klang
klang / cloudformation-vpc-from-scratch.json
Created April 19, 2015 18:40
A CloudFormation test template to create a VPC with a public subnet and spin up a internet connected instance inside of it.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Building a VPC from scratch with CloudFormation",
"Mappings": {
"SubnetConfig": {
"VPC": { "CIDR": "10.0.0.0/16" },
"Public": { "CIDR": "10.0.0.0/24" }
},
"RegionMap" : {
@klang
klang / GitSha1.java
Created July 14, 2015 09:37
git hash
import org.apache.commons.codec.digest.DigestUtils;
public class GitSha1 {
public static String githash(String aString){
return DigestUtils.sha1Hex("blob " + aString.length() + "\0" + aString);
}
public static void main(String[] args) {
@klang
klang / pi-clojure101.clj
Created April 30, 2010 21:08
Estimating PI with the Gregory-Leibniz series for clojure101
;; 1
;; the nth element of the series
(defn pi-series [n]
(/ (* 4 (Math/pow -1 n)) (inc (* 2 n))))
;; lazy sequence giving the individual terms
(def pi1 (map #(pi-series %) (iterate inc 0)))
;; basically the same, but will use fractions (slower, but nice to look at)
(def pi2 (map #(/ (* 4 (expt -1 %)) (+ (* 2 %) 1)) (iterate inc 0)))
@klang
klang / clojure-font-lock-setup.el
Created June 1, 2010 18:47 — forked from michalmarczyk/clojure-font-lock-setup.el
adding paredit-mode to the repl
;;; all code in this function lifted from the clojure-mode function
;;; from clojure-mode.el
(defun clojure-font-lock-setup ()
(interactive)
(set (make-local-variable 'lisp-indent-function)
'clojure-indent-function)
(set (make-local-variable 'lisp-doc-string-elt-property)
'clojure-doc-string-elt)
(set (make-local-variable 'font-lock-multiline) t)
@klang
klang / daft.clj
Created August 1, 2010 12:58
The song 'Around the World' by Daft Punk has a deeply repetitive nature, unfortunately the lyrics is oftent stated wrong. The song has 4 verses consisting of 8, 16, 28 and 20 double repetitions of the phrase 'Around the world'. All in all, the song has 72
(ns daft
(meta {:description "The song 'Around the World' by Daft Punk has a deeply repetitive nature, unfortunately the lyrics is oftent stated wrong.
The song has 4 verses consisting of 8, 16, 28 and 20 double repetitions of the phrase 'Around the world'.
All in all, the song has 72 double repetitions or 144 repetitions of the iconic phrase."}))
(def lyrics (repeat "Around the world, around the world"))
(defn sing [lyrics]
(reduce str
(interleave