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
| for { | |
| entry <- contacts | |
| name <- Option(entry.getName) | |
| full_name <- Option(name.getFullName) | |
| birthday <- Option(entry.getBirthday) | |
| when = birthday.getWhen | |
| } | |
| yield "%s: %s".format(full_name.getValue, when) |
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
| # Sendgrid.com configuration: | |
| mail.smtp.host=smtp.sendgrid.net | |
| mail.smtp.auth=true | |
| [email protected] | |
| mail.password=letme1n |
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
| import javax.mail._ | |
| def optionalAuth: Box[Authenticator] = for { | |
| user <- Props.get("mail.user") | |
| pass <- Props.get("mail.password") | |
| } yield new Authenticator { | |
| override def getPasswordAuthentication = new PasswordAuthentication(user,pass) | |
| } | |
| Mailer.authenticator = optionalAuth |
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
| #!/bin/bash | |
| # Converts HTML from https://exportmyposts.jazzychad.net/ exports to Markdown | |
| POSTS_DIR=/Users/richard/Desktop/d6y/posts | |
| for file in $POSTS_DIR/*.html | |
| do | |
| echo $file |
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
| trait TideSource { | |
| def lowsFor(day:LocalDate): List[Tide] | |
| } |
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
| case class Tide(when:LocalTime, height:Metre) { | |
| override val toString = when.toString("HH:mm") + " (" + height + ")" | |
| def forZone(destZone:DateTimeZone) = Tide( | |
| when.toDateTimeToday(DateTimeZone.forID("GMT")).withZone(destZone).toLocalTime(), | |
| height) | |
| } |
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
| object VisitBrightonScraper extends VisitBrightonScraper | |
| class VisitBrightonScraper extends TideSource { | |
| def page = Source.fromURL( "http://www.visitbrighton.com/site/tourist-information/tide-timetables").mkString | |
| override def lowsFor(day:LocalDate) = { | |
| // We want the times that start with the date in this | |
| // format: 10th May 2009 | |
| val date = day.ordinal + DateTimeFormat.forPattern(" MMM yyyy").print(day) |
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
| // Here's a method that uses the time call: | |
| int f() throws MyException { | |
| time("opName", { => | |
| // some statements that can throw MyException | |
| }); | |
| time("opName", {=> | |
| return ...compute result...; | |
| }); | |
| } |
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
| interface Block { | |
| R execute() throws X; | |
| } | |
| public R time(String opName, Block block) throws X { | |
| long startTime = System.nanoTime(); | |
| boolean success = true; | |
| try { | |
| return block.execute(); | |
| } catch (final Throwable ex) { |
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
| def time(opname, block) | |
| { | |
| long start\_time = System.nanoTime() | |
| boolean success = true | |
| try { | |
| return block() | |
| } catch (Throwable ex) { | |
| success = false; | |
| throw ex | |
| } finally { |