This file contains hidden or 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
| int maxScrollExtent = (int) ((mOverlayTop.getContentHeight() * mOverlayTop.getScale()) - mOverlayTop.getHeight()); |
This file contains hidden or 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 static String fastReadTextFromFile(File file) { | |
| FileInputStream inputStream = null; | |
| try { | |
| inputStream = new FileInputStream(file); | |
| FileChannel ch = inputStream.getChannel(); | |
| MappedByteBuffer mb = ch.map(FileChannel.MapMode.READ_ONLY, | |
| 0L, ch.size()); | |
| byte[] barray = new byte[Math.min(mb.remaining(), BYTE_ARRAY_SIZE)]; | |
| int getSize; | |
| StringBuilder sb = new StringBuilder(); |
This file contains hidden or 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
| sed 's_.*clientIp\":\"\([^\"]*\)\".*dt\"\:\"\([^\"]*\)\".*_\2 \1_' |
This file contains hidden or 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
| rename 's//text-to-prepend/' *.jpg |
This file contains hidden or 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
| good[(good$Ozone > 31) & (good$Temp > 90), ] |
This file contains hidden or 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(); | |
| return articleViews | |
| .map(a -> a.contributor) //Get the contributor names from the article views | |
| .sort(Ord.stringOrd) //Need to sort before grouping | |
| .group(Equal.stringEqual) //Group by contributor name | |
| .filter(l -> l.length() > 1) //remove any contributors who only appear once | |
| .map(l -> new ContributorCount(l.head(), l.length())); //Map to the return type | |
| } |
This file contains hidden or 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); |
This file contains hidden or 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 hidden or 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 hidden or 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 |