Skip to content

Instantly share code, notes, and snippets.

View rupertbates's full-sized avatar

Rupert Bates rupertbates

  • Guardian News and Media
  • London
View GitHub Profile
@rupertbates
rupertbates / getContributorCountsFunctional.java
Last active August 29, 2015 14:10
getContributorCounts method in a functional style
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
}
@rupertbates
rupertbates / DataFrame.R
Created June 10, 2014 21:20
Select from R data frame
good[(good$Ozone > 31) & (good$Temp > 90), ]
@rupertbates
rupertbates / rename-prepend.sh
Created November 4, 2013 21:16
Rename - prepend a string onto all files in a director
rename 's//text-to-prepend/' *.jpg
@rupertbates
rupertbates / parse-ophan-ip-and-dt.sh
Created July 11, 2013 16:21
Use sed to print the client IP and date time stamp from each line of an Ophan log file
sed 's_.*clientIp\":\"\([^\"]*\)\".*dt\"\:\"\([^\"]*\)\".*_\2 \1_'
@rupertbates
rupertbates / fastReadTextFromFile.java
Created May 2, 2013 15:33
Read text from a file using a FileChannel and MappedByteBuffer
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();
@rupertbates
rupertbates / WebviewArticlePresenter.java
Last active December 25, 2016 08:43
Work out the maximum scroll extent of an Android WebView
int maxScrollExtent = (int) ((mOverlayTop.getContentHeight() * mOverlayTop.getScale()) - mOverlayTop.getHeight());
@rupertbates
rupertbates / delete-intellij.sh
Created March 14, 2013 16:51
Delete all IntelliJ settings - Removes all saved IntelliJ settings on Mac OS
find ~/Library -iname *intellij* -exec rm -rf {} \;
@rupertbates
rupertbates / numlines.sh
Created January 30, 2013 10:44
Get number of lines in file with Awk
awk 'END{print FNR}';
@rupertbates
rupertbates / git-colours.git
Created January 12, 2013 22:11
Switch on colours in Git
git config --global color.ui true
@rupertbates
rupertbates / Mongo matchWeek find.js
Created January 7, 2013 17:49
Find Mongo matchWeek records between a certain number, filter the result fields and then sort
db.matchWeek.find({number:{$gt:18, $lt:23}}, {number: 1, startDate:1, endDate:1}).sort({number:1}).pretty()