Skip to content

Instantly share code, notes, and snippets.

@horte
horte / JDBIDaoMySQLInExample.java
Last active December 20, 2015 06:38
Example using MySQL IN statements with JDBI
@UseStringTemplate3StatementLocator
public interface ModelDao {
@RegisterMapper(ModelPropertyMapper.class)
@SqlQuery("select * from model_property where model_id in ( <modelIds> )")
public List<ModelProperty> findModelPropertiesByModelIds(@BindIn("modelIds") Collection<Long> modelIds);
}
@horte
horte / ParameterizedParameters.java
Created July 24, 2013 13:40
Example of Parameterized test.
@Parameterized.Parameters
public static Collection<Object[]> generateData()
{
List<Object[]> data = new LinkedList<>();
//check limit and offset
data.add(new Object[]{generateParameters("league=55581"), generateExpectedValues("positionStatuses=true;labels.type=group;stats.name=gp,w,d,l,ga,gf,gd,pts")});
data.add(new Object[]{generateParameters("league=55581;size=small"), generateExpectedValues("positionStatuses=true;labels.type=group;stats.name=gp,pts")});
data.add(new Object[]{generateParameters("league=54275;size=medium"), generateExpectedValues("positionStatuses=true;labels.type=group;stats.name=gp,w,d,l,gd,pts")});
data.add(new Object[]{generateParameters("league=57973;size=large;round=3"), generateExpectedValues("positionStatuses=true;labels.type=group;stats.name=gp,w,d,l,gf,ga,gd,pts;stats.name.gp=3")});
data.add(new Object[]{generateParameters("league=55581;sort=team.name"), generateExpectedValues("positionStatuses=true;labels.type=group;sta
@horte
horte / saplo-php-example.php
Created June 26, 2013 14:56
Saplo PHP Example
<?php
include "saplo4php-2.0.php"; //downloaded from https://github.com/saplo/saplo4php-2.0
//When creating the SaploAPI object ($client) you will automatically be authenticated.
$client = new SaploAPI("APIKEY", "SECRETKEY");
//You can also get your Access Token
echo $client->getAccessToken();
@horte
horte / saplo-keyword-extraction.java
Last active December 16, 2015 11:58
Saplo Keyword Extraction
//Import saplo4j: https://github.com/saplo/saplo4j
SaploClient client = new SaploClient.Builder("apikey",
"secretkey").endpoint("https://api.saplo.com/rpc/json").build();
JSONObject params = new JSONObject();
params.put("html", "<html><h1>Headline</h1><p>text</p></html>"); //will clean html and extract article text. Important to leave html structure since it is used when we are trying to extract the relevant article text.
//params.put("url", "http://saplo.com"); will fetch html and clean and extract article text
@horte
horte / publisher.relatedTexts-example.java
Last active October 12, 2015 05:38
Custom JSON - publisher.relatedTexts example
JSONObject params = new JSONObject();
params.put("collection_id", collection.getId());
params.put("text_id", articleId);
params.put("collection_scope", (new JSONArray()));
params.put("wait", 50);
params.put("limit", 50);
params.put("days_old", 14);
params.put("allow_later_texts", true);
params.put("tags_skip_tag_related", true);
@horte
horte / ContentPatternConverter.java
Created May 13, 2012 11:22
Partial Update in Spring 3.1 Controller using @RequestBody with Validation
public class ContentPatternConverter implements Converter<String, ContentPattern> {
private PatternService patternService;
@Autowired
public ContentPatternConverter(PatternService patternService) {
this.patternService = patternService;
}
@Override
@horte
horte / jackson-objectmapper-config.java
Created March 2, 2012 18:43
Jackson ObjectMapper Configuration ignore all fields as default
//Turn off visibility for all fields when serializing (forces @JsonProperty annotations on entities)
setVisibilityChecker(getSerializationConfig().getDefaultVisibilityChecker()
.withCreatorVisibility(JsonAutoDetect.Visibility.NONE)
.withFieldVisibility(JsonAutoDetect.Visibility.NONE)
.withGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withIsGetterVisibility(JsonAutoDetect.Visibility.NONE)
.withSetterVisibility(JsonAutoDetect.Visibility.NONE));
//Turn off visibility for all fields when deserializing (forces @JsonProperty annotations on entities)
@horte
horte / spring-requestbody.java
Created March 2, 2012 18:32
Spring @RequestBody
@RequestMapping(value = "/objects/", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.CREATED)
@ResponseBody
public SomeObj createObject(@RequestBody SomeObj obj) {
//Do your things
return obj;
}