Skip to content

Instantly share code, notes, and snippets.

View Pyppe's full-sized avatar

Pyry-Samuli Lahti Pyppe

View GitHub Profile
// Create BUILD_INFO file showing status about the build in question
unmanagedResources in Compile <++= baseDirectory.map { base =>
val dir = java.nio.file.Files.createTempDirectory("sbt_build_info_").toFile
val buildFile = java.io.File.create(dir, "BUILD_INFO")
buildFile.deleteOnExit
dir.deleteOnExit
val fw = new java.io.FileWriter(buildFile)
fw.write(
s"""|Built by ${System.getProperty("user.name")} @ ${java.net.InetAddress.getLocalHost.getHostName} on ${new java.util.Date}
|===
@Pyppe
Pyppe / start-paused-torrent.scala
Last active August 29, 2015 13:57
Simple scala script for wrapping `transmission-remote`
#!/bin/bash
exec scala -savecompiled "$0" "$@"
!#
// Given all torrents are paused, this script starts the first one
import sys.process._
val host = "127.0.0.1:9091"
val auth = "myuser:mypassword"
@Pyppe
Pyppe / slick.scala
Created March 26, 2014 15:16
Slick 2.0.1: How to map from Set[String] to Option[String]
implicit val SetOfStrings = MappedColumnType.base[Set[String], Option[String]] (
values => values match {
case values if values.nonEmpty => Some(values.toSeq.sorted.mkString("\n"))
case _ => None
},
str => str.map(_.split('\n').toSet).getOrElse(Set.empty)
)
// could not find implicit value for evidence parameter of type SchemaBase.this.driver.BaseColumnType[Option[String]]
@Pyppe
Pyppe / CachedFuture.scala
Created May 21, 2014 15:29
CachedFuture.scala
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
object CachedFuture {
/**
* Returns a function which returns previously calculated Future (if one exists, and hasn't expired)
* - If result does not exist (or has expired), we share a common `pendingResult`
* to prevent same calculation being repeated.
*/
add_to_path() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
export PATH="$1:$PATH"
fi
}
add_to_path $HOME/apps/foobar
findFromHistory() {
history | cut -c 8-|awk '!x[$0]++'|grep $1
}
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success}
object FutureCache {
/**
* Returns a function which returns previously calculated Future (if one exists, and hasn't been expired)
* - If result does not exist (or has expired), we share a common `pendingFuture`
* to prevent same calculation being repeated
*/
plz-sudo() {
local pass=`gimme-passwd`
echo $pass | sudo -S "$@"
}
gimme-passwd() {
local GPG_PASS_FILE="/home/pyppe/password.txt.gpg"
read -sp "Enter passphrase: " gpgpass
echo "${gpgpass}" | gpg --yes --no-tty --batch --passphrase-fd 0 -o- $GPG_PASS_FILE
}
curl -XPOST http://localhost:9200/_optimize
curl -XPOST http://localhost:9200/_flush
curl -XPOST http://localhost:9200/_all/_close
# DO THE BACKUP
curl -XPOST http://localhost:9200/_all/_open
(function() {
var ISO_DAY = 'YYYY-MM-DD';
var FIN_DAY = 'D.M.YYYY';
function showExport(data) {
$('#polar-flow-export').remove();
var $el = $('<div id="polar-flow-export"></div>');
$el.
css({
object Main extends App {
import play.api.libs.json._
import play.api.libs.json.Reads._
val json = Json.obj(
"foo" -> "bar",
"user" -> Json.obj(
"name" -> "Mike",
"age" -> 45,
"food" -> "pizza"