Skip to content

Instantly share code, notes, and snippets.

View javiergamarra's full-sized avatar
😠

Javier Gamarra javiergamarra

😠
View GitHub Profile
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));
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) {
@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();
@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 / 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 / gist:485e8af27775b7fd7834
Created September 1, 2015 11:18
Add image with 200dpi in PDFBox (for a friend)
double resolution = 200;
double points = 72;
double ratio = resolution / points;
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), drawable);
Double width = bitmap.getWidth() / ratio;
Double height = bitmap.getHeight() / ratio;
<?xml version="1.0" encoding="utf-8"?>
<com.liferay.mobile.screens.viewsets.defaultviews.webcontentdisplay.WebContentDisplayView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/liferay_webview_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@javiergamarra
javiergamarra / build.gradle
Created October 8, 2015 13:10
liferay screens dependency
compile 'com.liferay.mobile:liferay-screens:+'
@javiergamarra
javiergamarra / build.gradle
Created October 8, 2015 13:11
exclude packaging options
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
@javiergamarra
javiergamarra / server_context.xml
Created October 8, 2015 13:14
example server for AT & workshops
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="liferay_server">http://audiencetargeting.liferay.org.es/</string>
<string name="liferay_company_id">20155</string>
<string name="liferay_group_id">78201</string>
</resources>