Skip to content

Instantly share code, notes, and snippets.

View struberg's full-sized avatar

Mark Struberg struberg

  • Vienna
View GitHub Profile
<script type="text/javascript">
function getFullUrl(url) {
var urlparts = url.split(/&amp;|\?/g);
var urlpath = urlparts[0];
if (urlpath.indexOf('://') &lt; 0) {
if (urlpath[0]== '/') {
return urlpath;
}
else {
var startpathloc = window.location.pathname.lastIndexOf('/');
package org.apache.maven.shared.utils.io;
import java.io.File;
/**
* <p>Visitor pattern for the DirectoryScanner. A ScanConductor controls the scanning process.</p>
*
* <p>Create an instance and pass it to {@link org.apache.maven.shared.utils.io.DirectoryScanner#scan(ScanConductor)}.
* You will get notified about every visited directory and file. You can use the {@link ScanAction}
* to control what should happen next.</p>
@struberg
struberg / gist:4268128
Created December 12, 2012 14:26
set the speed of your CPU to a fixed frequency. This makes benchmarkes much more reproducible.
#!/bin/sh
if [ "$1" = "ondemand" ]; then
echo "setting cpu governer ONDEMAND"
for f in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
do
echo ondemand> "$f"
done
exit
else
@struberg
struberg / selfinterception
Created October 15, 2014 10:06
self interception in CDI
@ApplicationScoped
public class CountryService {
private @Inject Cache<String, Country> cache;
private @Inject CountryService self;
public Country getByIsoA3(String isoA3) {
@FacesConverter(forClass = String.class)
public class StringConverter implements Converter{
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
if (component instanceof HtmlInputText || component instanceof HtmlInputTextarea) {
return (value != null) ? StringUtils.trimToNull(value) : null;
}
return value;
}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<dependencies>
<dependency>
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
<version>${juel.version}</version>
</dependency>
@struberg
struberg / Test.java
Created September 21, 2016 12:40
Java bytecode coercion with Java9 and the --release option
import java.util.concurrent.ConcurrentHashMap;
public class Test {
public static void main(String[] args) {
ConcurrentHashMap<String, String> map = new ConcurrentHashMap<>();
map.put("A", "B");
map.keySet();
}
@struberg
struberg / getrelease.sh
Created September 27, 2016 08:03
Shell script to propagate the Apache OpenWebBeans dist area after the VOTE succeeded
#!/bin/sh
# shell script to propagate the Apache OpenWebBeans dist area
cd $1
curl -O https://repository.apache.org/content/groups/public/org/apache/openwebbeans/openwebbeans-distribution/${1}/openwebbeans-distribution-${1}-binary.tar.gz
curl -O https://repository.apache.org/content/groups/public/org/apache/openwebbeans/openwebbeans-distribution/${1}/openwebbeans-distribution-${1}-binary.tar.gz.asc
curl -O https://repository.apache.org/content/groups/public/org/apache/openwebbeans/openwebbeans-distribution/${1}/openwebbeans-distribution-${1}-binary.tar.gz.md5
curl -O https://repository.apache.org/content/groups/public/org/apache/openwebbeans/openwebbeans-distribution/${1}/openwebbeans-distribution-${1}-binary.tar.gz.sha1
curl -O https://repository.apache.org/content/groups/public/org/apache/openwebbeans/openwebbeans-distribution/${1}/openwebbeans-distribution-${1}-binary.zip
@RequestScoped
@Named("conversation")
public class ConversationWrapper {
private @Inject Conversation conv;
public Conversation get() {
return conv;
}
}