Skip to content

Instantly share code, notes, and snippets.

View lucacesari's full-sized avatar
🎯
Focusing

Luca Cesari lucacesari

🎯
Focusing
  • RCP Vision
  • Florence (Italy)
View GitHub Profile
@lucacesari
lucacesari / Rakefile
Created September 14, 2014 10:30
Fabulous testing with Rake and Minitest
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << 'test'
t.pattern = "test/**/*_test.rb"
t.warning = true
t.verbose = true
end
@lucacesari
lucacesari / gist:542615a4a241ac630544
Created September 14, 2014 15:00
Call external process in Java7
ProcessBuilder builder = new ProcessBuilder();
builder.command("command1");
builder.inheritIO(); // if you need to see the sysout and syserr
Process p = builder.start();
p.waitFor()
@lucacesari
lucacesari / Watermark.java
Last active August 29, 2015 14:06
(Buffered)Image watermarking
private static BufferedImage watermark(BufferedImage image, String text) {
final FontMetrics fm = graphics.getFontMetrics();
// center text string
final int x = (image.getWidth() / 2) - fm.stringWidth(text);
final int y = (image.getHeight() / 2) - fm.getHeight();
final Graphics2D graphics = image.createGraphics();
graphics.setPaint(Color.white);
graphics.setFont(new Font("SansSerif", Font.BOLD, 10));
graphics.drawString(text, x, y);
@lucacesari
lucacesari / add_to_path.bat
Created September 16, 2014 14:22
Add path to Windows %PATH% variable
@echo off
REM If your path contains spaces remember to quote it
setx /m Path "%~1;%PATH%"
echo "%~1 has been added to the Path"
echo "Restart any application that needs to use the modified Path"
@lucacesari
lucacesari / add_env_var.bat
Created September 16, 2014 14:26
Add a system enviroment variable in Windows
@echo off
REM Usage: add_env_var.bat NEW_ENV_VAR "my_path"
REM If the inserted path contains spaces remember to quote it
REG ADD "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v %1 /t REG_SZ /d %2
@lucacesari
lucacesari / test_path.bat
Created September 16, 2014 15:11
Test if a command is in the Windows %Path%
@echo off
REM Usage: test_path.bat cmd_to_test
for %%x in (%1) do (
if not [%%~$PATH:x]==[] (
echo "Command %1 found"
goto :eof
)
)
echo "Command %1 NOT found"
@lucacesari
lucacesari / fatjar.gradle
Created September 19, 2014 06:45
Create a fat jar with Gradle
ext {
vendor = "vendor"
version = "42.0"
basename = "foo"
mainClassName = "bar.foo.mainClass"
}
dependencies {
compile project(':my_other_project')
compile 'ch.qos.logback:logback-classic:1.1.1'
@lucacesari
lucacesari / obfuscate.gradle
Created September 19, 2014 06:55
Obfuscate a jar with Gradle
ext {
mainClassName = "foo.bar.buz.mainClass"
basename = "fooBar"
version = "42.0"
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
injars "./build/libs/${basename}-${version}.jar"
outjars "./build/libs/${basename}-${version}-obf.jar"
@lucacesari
lucacesari / CommandBuilder.java
Created October 15, 2014 07:39
Eclipse parameterized Command builder
/*
* This content is released under the MIT License (http://opensource.org/licenses/MIT).
* Copyright (c) 2014 Luca Cesari <luc@cesari.me>
*/
package lucacesari.gists;
import java.util.ArrayList;
import java.util.List;
@lucacesari
lucacesari / CliUtils.java
Created October 15, 2014 08:13
Get Eclipse application arguments
/*
* This content is released under the MIT License (http://opensource.org/licenses/MIT).
* Copyright (c) 2014 Luca Cesari <luc@cesari.me>
*/
package lucacesari.gists;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;