Skip to content

Instantly share code, notes, and snippets.

View gjoseph's full-sized avatar

Grégory Joseph gjoseph

  • Sydney, Australia
View GitHub Profile
@gjoseph
gjoseph / SplitUtil.java
Created August 17, 2011 11:05
Why are there so many ways of getting a String[] from a comma-separated String in Java, and none of the basic ones really work (split(",") or StringTokenizer) ? I don't know, but this is my ultimate solution at the moment. Are there more cases to cover ?
import java.util.regex.Pattern;
public class SplitUtil {
private static final Pattern COMMA_DELIMITED_SPLIT = Pattern.compile("(\\s*,\\s*)+");
private static final String[] EMPTY = new String[0];
public static String[] commaDelimited(String s) {
if (s == null) {
return EMPTY;
}
@gjoseph
gjoseph / URLUtil.encode
Created August 29, 2011 15:00
And another irked gist, which turned out to be unneeded after all.
/**
* So java.net.URLEncoder#encode(java.lang.String) is deprecated, because it uses the OS' default encoding,
* java.net.URLEncoder#encode(java.lang.String, java.lang.String) takes a second parameter for said encoding,
* while mentioning that "The World Wide Web Consortium Recommendation states that UTF-8 should be used.
* Not doing so may introduce incompatibilites.". (typo not mine).
* Still, we have to choose, read doc, and specify the ourselves, and deal with the uncanny possibility that
* UTF-8 might not be available on a system where we do have a 1.6 JVM.
* Right.
*/
@gjoseph
gjoseph / jackrabbit-acme-prod.xml
Created October 25, 2011 11:06
Jackrabbit configuration file for the "Acme" project discussed at http://dev.magnolia-cms.com/~gjoseph/dont-deploy-magnolia-deploy-your-project
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 1.6//EN" "http://jackrabbit.apache.org/dtd/repository-1.6.dtd">
<Repository>
<FileSystem class="org.apache.jackrabbit.core.fs.local.LocalFileSystem">
<param name="path" value="${rep.home}/repository" />
</FileSystem>
<Security appName="Jackrabbit">
<AccessManager class="org.apache.jackrabbit.core.security.simple.SimpleAccessManager"></AccessManager>
<LoginModule class="org.apache.jackrabbit.core.security.simple.SimpleLoginModule">
<param name="anonymousId" value="anonymous" />
@gjoseph
gjoseph / author.xml
Created October 25, 2011 13:22
Tomcat context file for the author instance of the "Acme" project discussed at http://dev.magnolia-cms.com/~gjoseph/dont-deploy-magnolia-deploy-your-project
<!-- if this was declared in the <Host> configuration, we'd add a path="/author" attribute -->
<Context docBase="/opt/acme-project/wars/acme-project-webapp-1.0-SNAPSHOT.war" debug="0" reloadable="false">
<Parameter name="magnoliaInstance" value="prodAuthor" override="false"/>
<Resource name="jdbc/MagnoliaAcmeDS" auth="Container"
type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
factory="com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
user="acme_magnolia" username="acme_magnolia"
password="secret"
@gjoseph
gjoseph / ROOT.xml
Created October 25, 2011 13:23
Tomcat context file for the public instance of the "Acme" project discussed at http://dev.magnolia-cms.com/~gjoseph/dont-deploy-magnolia-deploy-your-project
<!-- if this was declared in the <Host> configuration, we'd add a path="" attribute -->
<Context path="" docBase="/opt/acme-project/wars/acme-project-webapp-1.0-SNAPSHOT.war" debug="0" reloadable="false">
<Parameter name="magnoliaInstance" value="prodPublic" override="false"/>
<Resource name="jdbc/MagnoliaAcmeDS" auth="Container"
type="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
factory="com.mysql.jdbc.jdbc2.optional.MysqlDataSourceFactory"
driverClassName="com.mysql.jdbc.Driver"
user="acme_magnolia" username="acme_magnolia"
password="secret"
@gjoseph
gjoseph / CanonicalIsWeirdScript
Created January 5, 2012 16:13
Did i just find a bug in @canonical or am i thick ? #groovy
#!/usr/bin/env groovy
import groovy.transform.Canonical
def weird = new CanonicalIsWeird(a: 'first letter', b: 'second letter')
println "a: ${weird.a}"
println "b: ${weird.b}"
assert weird.a == 'first letter'
assert weird.b == 'second letter'
@gjoseph
gjoseph / gist:2312493
Created April 5, 2012 16:55
Can you bots stop hammering my SVN server via ViewVC? You really don't need to index all revisions of all files, kthxbye
# Exclude bots for requests with a query string, with the exception of the view=log query: bots can see the file's latest revision (no query string), or the log.
RewriteCond %{HTTP_USER_AGENT} bot [nocase]
RewriteCond %{QUERY_STRING} !(^view=log$|view=log&log_pagestart=[0-9]+$|^$)
RewriteRule /view/.* - [F,L]
→ git show 82268d8 --name-status
commit 82268d869172883b45124d20bc7588bd3d096e2d
Author: Grégory Joseph <gregory.joseph@magnolia-cms.com>
Date: Mon Aug 18 14:22:47 2014 +0200
QA: Removed unnecessary Object[] creation for methods that take a vararg - mostly log and Method.invoke()
M magnolia-core/src/main/java/info/magnolia/cms/core/MagnoliaAccessManager.java
M magnolia-core/src/main/java/info/magnolia/cms/core/search/QueryResultImpl.java
M magnolia-core/src/main/java/info/magnolia/cms/core/version/CopyUtil.java
#!/bin/bash
pattern=$1
if [ -z $pattern ]; then
echo "Please pass a pattern ! (e.g 'modules')"
exit -3
fi
output=`ssh git@git.magnolia-cms.com expand $pattern`
echo "$output" | grep '^only' > /dev/null
@gjoseph
gjoseph / content
Created September 8, 2014 14:25
git-all
#!/bin/sh
CMD=$@
echo WILL EXECUTE git $CMD
find . -name .git -exec dirname {} \; | while read dir; do
C=`pwd`
cd $dir
#echo "\033[1m`pwd`:\033[0m"
echo "\033[1m$dir:\033[0m"
git $CMD
echo ""