Skip to content

Instantly share code, notes, and snippets.

@cherniag
cherniag / bash script - loop maven tests
Created October 2, 2017 12:19
bash script - loop maven tests
COUNTER=0
while [ $COUNTER -lt 100 ]; do
echo The counter is $COUNTER
mvn clean test -f <path>/pom.xml > maven.log
rc=$?
if [[ $rc -ne 0 ]] ; then
echo 'Could not perform tests'; exit $rc
fi
let COUNTER=COUNTER+1
done
@cherniag
cherniag / tshark and tcpdump
Last active September 29, 2017 13:33
tshark and tcpdump
sudo tcpdump -n -i lo 'port 8866 and host <ip>' -w -
-i is interface! -> ifconfig
sudo tshark -i lo -f "port 8866"
sudo tshark -i lo -e websocket.payload.text_unmask -Tfields port 8866
@cherniag
cherniag / get impala queries by statement
Created September 18, 2017 15:33
get impala queries by statement
http://<host>:7180/cmf/impala/completedQueries?startTime=1505403480000&endTime=1505404440000&filters=statement+RLIKE+%27<statement pattern>%27&offset=0&limit=300&serviceName=impala&histogramAttributes=query_duration&_=1505485509039
@cherniag
cherniag / default null value in Spring @Value
Created August 11, 2017 11:02
default null value in Spring @value
You must set the nullValue of the PropertyPlaceholderConfigurer. For the example I'm using the string @null but you can also use the empty string as nullValue.
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<!-- config the location(s) of the properties file(s) here -->
<property name="nullValue" value="@null" />
</bean>
Now you can use the string @null to represent the null value
@Value("${stuff.value:@null}")
private String value;
@cherniag
cherniag / mac console
Created August 4, 2017 13:06
mac console
for db in {file1,file2} ; do scp user@host:/tmp/${db}.sql ./folder_name ; done
@cherniag
cherniag / multiselect
Created August 1, 2017 09:05
multiselect
EntityManager em = getEntityManager();
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
CriteriaQuery<StreamSource> criteriaQuery = criteriaBuilder.createQuery(Domain.class);
Root<StreamSource> source = criteriaQuery.from(Domain.class);
criteriaQuery
.multiselect(source.get("id"), source.get("name"), source.get("accountId"), source.get("description"),
source.get("enabled"), source.get("type"), source.get("subStorageType"), source.get("storageConfiguration"),
source.get("playbackMode"), source.get("live"), source.get("cacheable"),
source.joinList("linkedSources", JoinType.LEFT),
source.get("createdDate"))
@cherniag
cherniag / openstreetmap
Last active May 25, 2017 14:21
openstreetmap
http://b.tile.openstreetmap.org/7/74/43.png
http://b.tile.openstreetmap.org/6/37/21.png
http://b.tile.openstreetmap.org/8/149/86.png
http://b.tile.openstreetmap.org/9/299/172.png
http://b.tile.openstreetmap.org/10/598/345.png
import retrofit.client.Response
import retrofit.mime.TypedString;
TypedString wrapped = new TypedString(script);
...
@POST("/validate")
Response validate(@Body TypedString script);
@cherniag
cherniag / JdbcTemplate with TransactionTemplate
Created April 11, 2017 15:44
JdbcTemplate with TransactionTemplate
If you look at the code for JdbcTemplate (one of the execute(...) methods) you will see
Connection con = DataSourceUtils.getConnection(getDataSource());
Which tries to retrieve a Connection from a ConnectionHolder registered with a TransactionSynchronizationManager.
If there is no such object, it just gets a connection from the DataSource and registers it (if it is in a transactional environment, ie. you have a transaction manager). Otherwise, it immediately returns the registered object.
This is the code (stripped of logs and stuff)
@cherniag
cherniag / CloseableHttpClient with ssl config
Created April 6, 2017 16:46
CloseableHttpClient with ssl config
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(connectTimeout)
.setSocketTimeout(socketTimeout)
.build();
HttpClientBuilder httpClientBuilder = HttpClients
.custom()
.setDefaultRequestConfig(requestConfig)
.evictIdleConnections(evictIdleConnectionSeconds, TimeUnit.SECONDS)
.setMaxConnPerRoute(maxConnections)