Skip to content

Instantly share code, notes, and snippets.

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

Bastien Colmard Baztoune

🏠
Working from home
  • Paris
View GitHub Profile
import org.specs2.mock.Mockito
import org.specs2.mutable.Specification
class MyService {
def test(param1: String)(implicit param2: String = "ABCD"): String = s"$param1#$param2"
}
class MyServiceTest extends Specification with Mockito {
// DO NOT MIX MATCHERS AND LITERALS. Mockito fails with "Invalid use of argument matchers!"
tmpdir=tmp
if [ -d "$tmpdir" ]; then
rm -rf $tmpdir
fi
mkdir $tmpdir
height=1280
width=11
n=0
for f in *.jpg
do
@Baztoune
Baztoune / Régions-France.json
Created September 6, 2013 13:30
Découpage administratif des régions de France au format GeoJson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Baztoune
Baztoune / Régions-France-simple.json
Last active December 22, 2015 11:09
Découpage administratif simplifié des régions de France au format GeoJson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Baztoune
Baztoune / UseCase.java
Created July 31, 2013 09:06
Handle file path pattern in JNDI
String filePathPattern = (String) InitialContext.doLookup("my/filePathPattern");
StringBuilder filePath = new StringBuilder();
Formatter frmt = new Formatter(filePath);
frmt.format(filePathPattern,"firstStringParam","secondStringParam");
@Baztoune
Baztoune / application_fr.properties
Last active December 20, 2015 06:49
How to use resource bundle with a locale variant in JSF 1.2
my.var=BlahdeBlih
other.var=ROFLOL
@Baztoune
Baztoune / CustomDateConverter.java
Created February 20, 2013 11:54
SimpleDateFormat (used by the default Converter, extended by Seam Converter) accepts a 2 digits year, even if the patter is set to a 4 digits year, so entering 27/10/45 was translated to 27/10/0045 by the Converter. My simple fix was to ensure the Date was between 1800 and 2100 (I could also throw an Exception if a regexp pattern was not matched…
package com.domiserve.servidom.util;
import java.util.Calendar;
import java.util.Date;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
-- src > http://www.talkapex.com/2009/07/oracle-how-to-update-all-sequences.html
-- Increment all sequences by a fixed number
DECLARE
v_increase_by NUMBER;
v_bkp_increment_by NUMBER;
v_str VARCHAR2 (1000);
v_count NUMBER;
BEGIN
v_increase_by := 2000;
@Baztoune
Baztoune / DebugHibernateSQLQueryWithEnumParameter.md
Last active December 12, 2015 05:28
I work with Hibernate 3.2.6.ga. I store my enum values as String in my database, using @Enumerated(EnumType.STRING). This time, I had to work with "native" SQL for some reason, so I used SQLQuery, and tried to filter my request by setting an enum value, but the query returned 0 result instead of, let's say 15.

It appeared that the final String parameter set in the SQL query was not the one I expected. Logging the SQL parameters (org.hibernate.type=TRACE) shows that the parameter looks like some hash (2c6d8085fef280...), not a regular String. While debugging the SQLQuery, i saw that the namedparameter's type was of type SerializableType instead of StringType. Hence Hibernate calls NullableType.nullSafeSet() in his Loader.bindNamedParameters() method, that calls Serializable.set(), which sets the Enum value as bytes. So the problem seems to come from TypeFactory.heuristicType() that doesn't find any suitable type for my Enum, except SerialisableType.

I didn't find any corresponding JIRA on hibernate bugtracker or anything else on Google, except that https://forum.hibernate.org/viewtopic.php?f=9&t=984527 so I don't really know if it's worth reporting the bug (maybe that branch is not even maintained anymore?)

TL;DR

don't set enum p

@Baztoune
Baztoune / MyJsfHelper.java
Created January 22, 2013 11:33
In some cases you need the options of your selectbox to be made of a code and a label, but separated by spaces so all labels are aligned. To do this you can use a monospace font, and add the right amount of spaces (rightpad). Be sure to tell JSF to not escape the labels. I also had to implement my own converter.
/**
* return a list of JSF SelectItem made of a code and a
* label, separated by spaces. All the labels are aligned
* (depending you use a monospace font)
*/
@Factory(value = "codeSelectItemList", scope = ScopeType.SESSION)
public List<SelectItem> getFixedSizeSelectItems(){
int padSize = 8;
String padChar = StringEscapeUtils.unescapeHtml("&nbsp;");