Skip to content

Instantly share code, notes, and snippets.

@onilton
onilton / fotocrawl.scala
Created February 3, 2016 02:15
A one-liner for crawling fotolog in scala
import sys.process._
(0 to 510 by 30).flatMap(p => "(http://sp6.fotolog.com[^\"]+)".r.findAllIn(s"curl -s http://www.fotolog.com/_tixa14/mosaic/$p/" !!))
.map(_.replaceAll("_t.jpg", "_f.jpg"))
.foreach(u => s"wget $u" !!)
import scala.tools.ant.sabbus.Break
object test {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
val vetorInverso = Map( 0 -> 0, 1 -> 5, 2 -> 4, 3 -> 3, 4 -> 2, 5 ->1 )
//> vetorInverso : scala.collection.immutable.Map[Int,Int] = Map(0 -> 0, 5 -> 1
//| , 1 -> 5, 2 -> 4, 3 -> 3, 4 -> 2)
vetorInverso(3) //> res0: Int = 3
@onilton
onilton / suspend-on-low-battery.sh
Last active August 29, 2015 14:19
suspend-on-low-battery
#!/bin/bash
# This is a fix for my samsung np900x4c laptop, who doesn't seem to shutdown nicely when low on battery
# Just put this in your cron (Runs every 1 minute).
# * * * * * /home/YOURUSERNAME/bin/suspend-on-low-battery
# ==== START FIX ====
# Command notify-send would not show the message on your
# screen when started by cron.
# This fix will work in any crontab. sudo crontab-e or crontab -e
@onilton
onilton / scheduled_task.scala
Created September 27, 2013 08:39
Scheduled task in scala
import akka.actor.ActorSystem
import scala.concurrent.duration._
val actorSystem = ActorSystem()
val scheduler = actorSystem.scheduler
val task = new Runnable { def run() { println("Hello") } }
implicit val executor = actorSystem.dispatcher
@onilton
onilton / refactor2.scala
Created February 17, 2012 12:56 — forked from felipehummel/refactor2.scala
Refactor implicit
def create(userId: String, feedItemId: String) {
println("user: "+userId + " clipou: "+feedItemId)
redisClientPool.withClient { implicit client =>
val itemsAdded = addItemToClips(userId, feedItemId)
if (itemsAdded != 0) {
addClipToTimeline(userId, feedItemId)
userFollowersSet(userId).flatten.foreach { followerId =>
addClipToTimeline(followerId, feedItemId)
}
}
@onilton
onilton / percolatorbugreproduce.sh
Created January 25, 2012 19:43
Reproduce possible percolator bug
#!/bin/bash
echo ; echo
echo "Create test index"
curl -XPUT localhost:9200/testindex?pretty=true
echo ; echo
echo "Insert doc 1"
curl -XPUT http://localhost:9200/testindex/article/1?pretty=true -d '{