This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL="http://content.guardianapis.com/search?api-key=test&show-fields=starRating&page-size=100&tag=tone/albumreview,tone/reviews&from-date=2015-01-03&to-date=2015-02-03" | |
curl -s $URL | jq '.response.results[]' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
URL="http://content.guardianapis.com/search?api-key=test&show-fields=starRating&page-size=100&tag=tone/albumreview,tone/reviews&from-date=2015-01-03&to-date=2015-02-03" | |
curl -s $URL | jq '[.response.results[]|select(.fields.starRating == "4" or .fields.starRating == "5")] | length' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"response": { | |
"status": "ok", | |
"userTier": "developer", | |
"total": 15895, | |
"startIndex": 1, | |
"pageSize": 10, | |
"currentPage": 1, | |
"pages": 1590, | |
"orderBy": "newest", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[.[]|select(.fields.starRating == "4")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
for i in $( ls $1 ); do | |
echo Removing: $2$i | |
rm $2$i | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
findViewById(R.id.myView).setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
handleClick(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Checking for null through an object graph quickly becomes unwieldy | |
if (article.getContributor() != null && | |
article.getContributor().getImage() != null && | |
article.getContributor().getImage().getSize() != null) { | |
Size size = article.getContributor().getImage().getSize(); | |
setContributorImageSize(size.getWidth(), size.getHeight()); | |
} | |
//Chaining multiple optional values using bind and map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Imperative style of dealing with an Option type | |
if(article.getMainImage().isSome()) | |
setArticleImage(article.getMainImage().some()); | |
//Functional approach using map | |
article.getMainImage().map(this::setArticleImage); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Article { | |
DisplayImage mainImage; | |
//Rest of the class declaration | |
public DisplayImage getMainImage(){ | |
//What happens if there is no main image on this article? | |
return mainImage; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<ContributorCount> getContributorCounts() { | |
List<ArticleView> articleViews = getArticleViews(); | |
//First iterate over the articles counting the occurrences of | |
//each contributor | |
HashMap<String, Integer> contributorCounts = new HashMap<String, Integer>(); | |
for (ArticleView articleView : articleViews) { | |
Integer count = contributorCounts.get(articleView.contributor); | |
if (count == null) | |
contributorCounts.put(articleView.contributor, 1); |