Skip to content

Instantly share code, notes, and snippets.

View stefanbirkner's full-sized avatar

Stefan Birkner stefanbirkner

View GitHub Profile
stefanbirkner /
Created June 1, 2011 19:12
Replace blocks in files, which are identified by a start and an end token.
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class ReplaceBlocks {
cat sb | xargs sed -i 's/0, 1, 3, 2/0, 1, 3/g'
cat sb | xargs sed -i 's/0, 1, 2/0, 1, 3/g'
stefanbirkner /
Created June 22, 2011 14:41
Add a new line at the beginning of a text file
#adds the line 'the new first line' at the beginning of file 'filename'
sed -i '1 i\the new first line' filename
stefanbirkner / easyMock2Mockito
Created July 20, 2011 15:38
Convert tests from EasyMock to Mockito
fgrep -Rl "EasyMock" testsrc | fgrep -v ".svn" | while read item
sed -i 's/org.easymock.EasyMock.createNiceMock/org.mockito.Mockito.mock/g' $item
sed -i 's/org.easymock.EasyMock.createMock/org.mockito.Mockito.mock/g' $item
sed -i 's/org.easymock.EasyMock.expect/org.mockito.Mockito.when/g' $item
sed -i 's/org.easymock.EasyMock/org.mockito.Mockito/g' $item
sed -i 's/EasyMock/Mockito/g' $item
sed -i 's/createNiceMock/mock/g' $item
sed -i 's/createMock/mock/g' $item
stefanbirkner /
Created October 4, 2011 21:51
Replace links with simple text
grep -Rl "a href=" dirname | while read item
sed -i 's/<a href=".*">\(.*\)<\/a>/\1/' $item
stefanbirkner / numberOfDuplicates.sql
Created January 11, 2012 10:29
list duplicate rows with the number of duplicates
-- replace myfield1, myfield2 and mytable with appropriate names
select COUNT(*) AS num, myfield1, myfield2 from mytable group by myfield1, myfield2 HAVING COUNT(*) > 1;
stefanbirkner / intellijidea.desktop
Created March 2, 2012 09:50
Desktop file for Intellij Idea
[Desktop Entry]
Name=IntelliJ IDEA
Comment=IntelliJ Integrated Development Environment
stefanbirkner /
Created March 13, 2012 10:19
IntelliJ Idea Template for a JUnit4 test.
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import static org.junit.rules.ExpectedException.none;
public class ${NAME} {
public final ExpectedException thrown = none();
stefanbirkner / twitterspring.jsp
Created April 17, 2012 22:19
Twitter Bootstrap meets Spring Form Tag library
<form:errors path="a" cssClass="alert alert-error" element="div"/>
<form:errors path="*" cssClass="alert alert-error" element="div" delimiter='</div><div class="alert alert-error">'/>
stefanbirkner /
Created April 18, 2012 15:48
Playdeb builds a debian package of the play framework.
# playdeb builds a debian package of the play framework. playdeb downloads
# the playframework by itself. You run it by
# <version> <maintainer>
# Example:
# 1.2.3 "Denny Colt <d.colt@eisner.qcg>"
# The script has been tested with version 1.2.3.
if [ -z $1 ]