Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Karsten Lang klang

🏠
Working from home
View GitHub Profile
@klang
klang / F.sql
Last active Aug 29, 2015
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…
View F.sql
CREATE OR REPLACE FUNCTION "ORACLEGIT"."F" return varchar as
begin
return
'Hello world';
end;
View cr_tc-initrd.sh
#!/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 Mar 25, 2014
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/
View post-receive
#!/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
View wordx-gitattributes.md

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

View strange_python.py
# array
>>> [1]
[1]
>>> [1,]
[1]
# hash
>>> {'a':1}
{'a': 1}
>>> {'a':1,}
@klang
klang / cloudformation-vpc-from-scratch.json
Created Apr 19, 2015
A CloudFormation test template to create a VPC with a public subnet and spin up a internet connected instance inside of it.
View cloudformation-vpc-from-scratch.json
{
"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" : {
View GitSha1.java
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 Apr 30, 2010
Estimating PI with the Gregory-Leibniz series for clojure101
View pi-clojure101.clj
;; 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)))
View clojure-font-lock-setup.el
;;; 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 Aug 1, 2010
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
View daft.clj
(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