Skip to content

Instantly share code, notes, and snippets.

View javiergamarra's full-sized avatar
😠

Javier Gamarra javiergamarra

😠
View GitHub Profile
@javiergamarra
javiergamarra / Resize image as SDK does
Created May 22, 2015 21:37
Classic code for resizing an image
public static byte[] decodeSampledBitmapFromResource(String path, int reqWidth, int reqHeight) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, options);
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
@javiergamarra
javiergamarra / Example server_context.xml
Last active August 29, 2015 14:21
Example server_context.xml for Liferay Screens
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Change these values for your Liferay Portal installation -->
<string name="liferay_server">http://WRITE_HERE_YOUR_HOST:8080</string>
<integer name="liferay_company_id">WRITE_HERE_YOUR_COMPANY_ID</integer>
<integer name="liferay_group_id">WRITE_HERE_YOUR_GROUP_ID</integer>
</resources>
@javiergamarra
javiergamarra / Example of reading a file of points with multiple spaces between
Last active August 29, 2015 14:17
Example of reading a file of points with multiple spaces between
public static void main(final String[] args) {
final String path = args[0];
try (BufferedReader br = new BufferedReader(new FileReader(path))) {
String line = br.readLine();
final int rows = Integer.parseInt(line);
final Point[] points = new Point[rows];
for (int i = 0; i < rows; i++) {
line = br.readLine();
numbers = Arrays.asList(new Integer[] { 1, 2, 3, 4, 5, 6 });
numberOperations = 0;
private boolean isEven(int n) {
System.out.println(numberOperations + " - Is " + n + " even?");
numberOperations++;
return n % 2 == 0;
}
private int doubleIt(int n) {
OptionalInt result = numbers.stream().filter(this::isEven)
.mapToInt(this::doubleIt).filter(this::isGreaterThan5)
.findFirst();
System.out.println("first number is " + result.getAsInt());
assertThat(result.getAsInt(), equalTo(8));