Skip to content

Instantly share code, notes, and snippets.

@Test
public void testLLN() {
final Random random = new Random();
for (int j = 4; j >= 2; j--) {
int tries = Integer.MAX_VALUE / (int) (Math.pow(10.0, j));
int equalsEight = 0;
Integer x;
for (int i = 0; i < tries; i++) {
x = random.nextInt(6);
if (x == 5) {
Android Emulator usage: emulator [options] [-qemu args]
options:
-sysdir <dir> search for system disk images in <dir>
-system <file> read initial system image from <file>
-datadir <dir> write user data into <dir>
-kernel <file> use specific emulated kernel
-ramdisk <file> ramdisk image (default <system>/ramdisk.img
-image <file> obsolete, use -system <file> instead
-initdata <file> same as '-init-data <file>'
-data <file> data image (default <datadir>/userdata-qemu.img
public class RuleEngine implements Serializable {
private transient ScriptEngineManager factory = new ScriptEngineManager();
private transient ScriptEngine engine = factory.getEngineByName("groovy");
public Object execute(String szScript, String szMethodName, Object... parameters) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, ScriptException {
engine.eval(szScript);
Invocable invocable = (Invocable) engine;
Object result = invocable.invokeFunction(szMethodName, parameters);
return result;
@JonathanLalou
JonathanLalou / .java
Created March 21, 2017 04:51
update dynamically log level with Apache Log4J
public void changeLogLevel(String logLevel) {
final Level formerLogLevel = LogManager.getRootLogger().getLevel();
final Level newLogLevel = Level.toLevel(logLevel);
LogManager.getRootLogger().setLevel(newLogLevel);
final Enumeration currentLoggers = getLoggerRepository().getCurrentLoggers();
while (currentLoggers.hasMoreElements()) {
logger.setLevel(newLogLevel);
}
auditEventService.saveAuditEvent(LOG_LEVEL_UPDATE_OK, "Log level was changed from: " + formerLogLevel.toString() + " to: " + logLevel);
@JonathanLalou
JonathanLalou / QualityCheck.groovy
Created June 6, 2017 04:18
that no XHTML file misses id in <p:XYZ> or <b:XYZ> tags
/**
* Checks that no XHTML file misses id in <p:XYZ> or <b:XYZ> tags
* Limitations:
* <ul>
* <li>ignores some tags such as b:row, p:ajax, etc.</li>
* <li>quick and dirty</li>
* </ul>
*/
@Test
void 'check no missing id in XHTML component tags'() {
@JonathanLalou
JonathanLalou / datatable-lazy-or-not.xhtml
Created June 19, 2017 04:05
Annoying: #Primefaces's datatable must be declared at lazy=true, otherwise commandButton (at least #Bootsfaces'ones) are ignored
<!-- lazy is true-->
<p:dataTable
id="butterDT"
var="butter" value="#{aBean.butters}"
lazy="true"
>
<p:column>
<!-- will be intercepted and handled at runtime-->
<b:commandButton actionListner="#{aController.doSomething(butter)}"
/>

Hi,

Here is a summary of the issue I write about on Twitter (cf https://twitter.com/John_the_Cowboy/status/921973717823082497 and previous tweets):

  • versions:
    • JRebel Agent 7.1.1
    • licence "myRebel"
    • Tomcat 7.0.59 (appears also with 8.5.23)
    • JDK 1.8.0_141-b15
    • the application is deployed via IntelliJ IDEA CE 2017.2.5
@JonathanLalou
JonathanLalou / thin-jar.xml
Created December 21, 2017 01:47
Maven-Assembly descriptor to generate a thin (regular) JAR in addition to SpringBoot's fat jar
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>thin</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
@JonathanLalou
JonathanLalou / gist:d7cfce1dd5b87637bf526543508f08f8
Created December 21, 2017 01:49
maven assembly plugin block to build a thin jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>src/main/resources/assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
package com.github.jonathanlalou
import org.junit.Test
import static org.junit.Assert.fail
class RerunFailedTests {
@Test void testOne() { fail("testOne") }
@Test void two() { fail("two") }