Skip to content

Instantly share code, notes, and snippets.

View p3t0r's full-sized avatar

Peter Maas p3t0r

  • Adevinta
  • Hilversum, the Netherlands
View GitHub Profile
Dir.glob("**/*.java").map{|it| it.split('/').last[0..-6]}.map{|it| [it, it.length]}.sort{|a, b| b[1] <=> a[1]}[0..5]
import scala.util.control.Breaks._
breakable {
for(i <- 1 to 10) if (i==3) break else println(i)
}
// ---- Implementation
import java.beans.Introspector
object BeanUtils {
val pathSeperator = """\."""
def readValue(obj: Object, path: String): String = {
val res = path.split(pathSeperator).foldLeft(obj) {
(a: Object, prop: String) =>
mvn -o dependency:tree | cut -c 7- | egrep '[\\\+\|].*' | sed 's/^[^a-z]*//g' | awk -F':' '{print "cp `find ~/.m2/repository -name " $2"-"$4".jar` lib/"}' | sh
object Time {
def apply[T](name: String)(block: => T) {
val start = System.currentTimeMillis
try {
block
} finally {
val diff = System.currentTimeMillis - start
println("# Block \"" + name +"\" completed, time taken: " + diff + " ms (" + diff / 1000.0 + " s)")
}
}
// Somple simple examples of using regular expressions in combination with pattern matching in Scala
//
// runs correctly on scala 2.8-nightly and 2.7.6.final
val RegionExpr = """.*?[aieoué][^aieoué](.+)""".r // string after first non-vowel following a vowel
"vergadering" match {
case RegionExpr(matchedGroup) => println("matched group: " + matchedGroup) // prints "gadering"
case _ =>
}
object Main {
implicit def extendString(string:String) = new MyString(string)
def main(args: Array[String]) :Unit = {
val testValue = "1000";
println(testValue.getClass().getName()) // prints java.lang.String
println(testValue.isNumeric) // prints true
println(testValue.lastIndexOf("0")) // prints 3
println(testValue.getClass().getName()) // prints java.lang.String
}
package com.finalist.examples
import javax.portlet._
import CollectionExtensions._
class MyPortlet extends GenericPortlet {
var normalView = null:PortletRequestDispatcher
override def init(config:PortletConfig):Unit = {
<html>
<body>
<h1>blaat</h1>
<script type="text/javascript" charset="utf-8">
window.onload = function() { alert('hi there!') }
</script>
</body>
</html>
{
"_id": "_design/news",
"_rev": "1-3487605953",
"language": "javascript",
"views": {
"articles": {
"map": "function(doc) {\n var newsitem = doc.newsitem\n if(newsitem && newsitem.tags.indexOf('artikel') != -1){\n emit(null, newsitem.title);\n }\n}"
}
}
}