Skip to content

Instantly share code, notes, and snippets.

@etexier
etexier / Prime.java
Created February 22, 2019 21:33
Prime numbers
/**
* Utility method for prime numbers.
**/
public class Prime {
public static boolean isPrime(long n) {
return n > 1 && LongStream.rangeClosed(2, (long) Math.sqrt(n)).noneMatch(divisor -> n % divisor == 0);
}
public static long countPrimes(int max) {
return LongStream.range(1, max).filter(Prime::isPrime).count();
}
@etexier
etexier / java-stream-readme.md
Last active May 11, 2024 19:32
Cheat sheet on Java streams

Java Streams

Overview

As part of Java 8 new features, lambda expressions are now supported (Project Lambda). See this very easy-to-read article from Brian Goetz State of the Lambda but more importantly focusing more on streams: State of the Lambda: Libraries Edition

Quick ways to create a stream

// From parameters
@etexier
etexier / single-module-pom-template.xml
Last active February 22, 2019 01:59
Minimal pom template for single module maven project
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>co.texier</groupId>
<artifactId>myproj</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
@etexier
etexier / rede-inject.pt
Created December 11, 2015 16:34
rede test keys injection
// This inject rede test keys
fw-erase-all-keys
fw-enable-disabled-kek-slots
fw-load-kek-component -s 0 303030303030303030303030303030303030303030303030 FFFF0000010001000000
println "injecting IPEK 4C436198800CCFD486406C6A92B737BF4C436198800CCFD4"
fw-load-initial-dukpt-key -s 0 303030303030303030303030303030303030303030303030 8015A93F0FE6BA436E4527A89142F09AAEB0685B6F33A8C1F61FFAF95319D78F FFFFF000060000200000 66A6EC3AC9B7E08A
fw-load-kek-component -s 5 3090BE648B68BB2E06F01465566EC3583090BE648B68BB2E FFFF0000010001000005
println "injecting IDEK CF50CCB408E4330677A6AD20064B772BCF50CCB408E43306"
fw-load-initial-dukpt-key -s 5 3090BE648B68BB2E06F01465566EC3583090BE648B68BB2E 747248C411B1BBFC7BEA0497FBF055EB06CE1720C584CBB85019B142981C2F3D FFFFF000070000200000 D9AAEBD4D9FC3CE6
fw-disable-empty-kek-slots
println "Re-initialize device keys"
fw-factory-reset
fw-initialize
println "Re-initialized"
@etexier
etexier / short-google-distance
Created November 6, 2014 21:06
REST Google Distance example with shorten JSON response
+Name googleDistance
+Request
http://maps.googleapis.com/maps/api/distancematrix/json?origins=435+Tasso+Street+Palo+Alto+CA&amp;destinations=Embarcadero+Street+San+Francisco+CA&amp;sensor=false&amp;mode=driving&amp;language=en&amp;units=imperial
+Response
+Body
{
"rows" : [
{
"elements" : [
@etexier
etexier / curl-distance-api
Last active August 29, 2015 14:08
curl command for google distance API
curl 'http://maps.googleapis.com/maps/api/distancematrix/json?origins=435+Tasso+Street+Palo+Alto+CA&amp;destinations=Embarcadero+Street+San+Francisco+CA&amp;sensor=false&amp;mode=driving&amp;language=en&amp;units=imperial'
{
"destination_addresses" : [ "Embarcadero North Street, San Francisco, CA, USA" ],
"origin_addresses" : [ "435 Tasso Street, Palo Alto, CA 94301, USA" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "34.4 mi",
@etexier
etexier / google distance rest-by-example
Last active August 29, 2015 14:05
google distance rest-by-example
# This is a sample request that can be used as the Rest specification for a controller
# Be sure to precede request example with '# Request' and example response with '# Response'
+name getDistance
+Request
http://maps.googleapis.com/maps/api/distancematrix/json?origins=435+Tasso+Street+Palo+Alto+CA&destinations=Embarcadero+Street+San+Francisco+CA&sensor=false&mode=driving&language=en&units=imperial
# This is the expected response:
+Response
+Content-type application/json
@etexier
etexier / TraderService.mab
Last active August 29, 2015 14:02
Create a TraderService controller out of RPC-ENCODED sample wsdl (2.3.0_M6.1)
pc -qf
api-add wsdl -q -Dwsdl=http://ec2-54-234-110-40.compute-1.amazonaws.com:7001/webservice/TraderService?WSDL
@etexier
etexier / traderservice.wsdl
Created June 2, 2014 23:35
Trader service sample RPC-ENCODED WSDL
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:tns="http://www.bea.com/examples/Trader"
xmlns:wsr="http://www.openuri.org/2002/10/soap/reliability/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding"
xmlns:conv="http://www.openuri.org/2002/04/wsdl/conversation/"