Skip to content

Instantly share code, notes, and snippets.

@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 '{
@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 / 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 / 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
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 / 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" !!)
@onilton
onilton / lista
Created February 24, 2016 15:34
Lista de músicas do show do Rolling Stones SP (2016)
1 - Intro (Satisfaction)
2 - Satisfaction
3 - I can't get no, I can't get no
4 - When I'm drivin' in my car
5 - (I Can't Get No) Satisfaction
6 - Hey hey hey, that's what I say
INTERVALO
7 - Cause I try
@onilton
onilton / quill-0.4.0-queryprobing-problem.scala
Created February 25, 2016 19:22
Quill 0.40 Query Probing Problem
package com.nobody
import io.getquill.JdbcSourceConfig
import io.getquill.naming.{ LowerCase, SnakeCase }
import io.getquill.sources.jdbc.JdbcSource
import io.getquill.sources.sql.idiom.MySQLDialect
import io.getquill._
object CustomDbSource {
@onilton
onilton / acesso.md
Created September 13, 2016 20:11 — forked from felipehummel/acesso.md
API NewsMonitor de Busca de Notícias

Acesso API (URL, Autenticação)

URL base da API NewsMonitor de Busca: https://api.spixdiscovery.com:8083/

A API utiliza autenticação básica HTTP (HTTP Basic Auth). Você receberá de nosso representante uma apiKey e um apiPassword. Para acessar a API será necessário passar esses valores como usuário e senha na autenticação básica HTTP.

Bibliotecas de HTTP, de todas as linguagens de programação, geralmente possuem facilidades para setar diretamente esse usuário e senha de forma fácil.

@onilton
onilton / pyrocks.py
Last active March 31, 2017 14:38
PythonRocksBot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# sudo pip install python-telegram-bot
# http://t.me/PythonRocksBot
from telegram.ext import Updater, MessageHandler, Filters
answers = {