Skip to content

Instantly share code, notes, and snippets.

@takezoe
takezoe / JdbcSample.scala
Created June 30, 2012 01:00
Simple wrapper for JDBC API in Scala
import jp.sf.amateras.scala.util.Imports._
using(DriverManager.getConnection("")){ implicit conn =>
withTransaction { conn =>
// update
val rows = conn.execute(
"INSERT INTO USER_INFO (USER_ID, USER_NAME) VALUES (?, ?)",
1, "takezoe")
@takezoe
takezoe / gist:3461423
Created August 25, 2012 05:59
Jerkson in Play2 development mode

Jerkson in Play2 development mode

Play2 includes Jerkson which is a Scala wrapper for the Java based JSON library Jackson.

It's very useful and I'm loving it. However when we use it in the Play2 application, it fails to deserialize case classes after reloading in development mode. See the following code:

import com.codahale.jerkson.Json
@takezoe
takezoe / gist:5377727
Created April 13, 2013 09:28
Recommendation search in solr-scala-client 0.0.8
val client = new SolrClient("http://localhost:8983/solr")
// search documents similar to the specified (id: 123456).
val result = client.query("id:123456")
.fields("id, title, content")
.recommend("title, content")
.getResultAsMap()
result.documents.foreach {
println("id: " + doc("id"))
@takezoe
takezoe / webhook.json
Last active December 23, 2015 01:09
Payload of Github web hook
{
"ref":"refs/heads/master",
"after":"eb437202431c910fe3409eb89414c40e13c79247",
"before":"a6a771884ad093443e84fa12187cbccfd03bdeaa",
"created":false,
"deleted":false,
"forced":false,
"compare":"https://github.com/takezoe/test/compare/a6a771884ad0...eb437202431c",
"commits":[
{
@takezoe
takezoe / docker_cheatsheet.md
Last active August 29, 2015 13:59
Docker CheatSheet

#Docker CheatSheet

Run container shell

sudo docker run -i -t [container_name] /bin/bash

以下のようにポートを指定しておくとホストのポートにマッピングできる。

@takezoe
takezoe / commons-daemon_1.0.10-1.0.15.diff
Created May 13, 2014 05:49
Diff between Commons Daemon 1.0.10 and 1.0.15
diff -r commons-daemon-1.0.10-native-src/NOTICE.txt commons-daemon-1.0.15-native-src/NOTICE.txt
2c2
< Copyright 1999-2012 The Apache Software Foundation
---
> Copyright 1999-2013 The Apache Software Foundation
diff -r commons-daemon-1.0.10-native-src/RELEASE-NOTES.txt commons-daemon-1.0.15-native-src/RELEASE-NOTES.txt
2c2
< Version 1.0.10
---
> Version 1.0.15
@takezoe
takezoe / sample.js
Last active August 29, 2015 14:02
GitBucket plug-in example
// Add a global menu item to the header
PluginSystem.addGlobalMenu("Google", "http://www.google.co.jp/", "data:image/png;base64,..."
function(context){
return context.loginAccount.isDefined();
}
);
// Add a custom action
PluginSystem.addGlobalAction('/test', function(request, response){
return "<h1>This is Test Plug-In</h1>";
@takezoe
takezoe / CaseClassAnnotation.md
Last active August 29, 2015 14:03
Scalaのケースクラスのプロパティに付けたアノテーションを読み取る

Javaで作ったこんなアノテーションがあるとします。

package jp.sf.amateras.sample;

import java.lang.annotation.*;

@Target({ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Id {
@takezoe
takezoe / export-issues.js
Last active March 20, 2018 15:16
GitBucket Plug-in Example
var plugin = JavaScriptPlugin.define(
'export-issues', '1.0.0',
'Naoki Takezoe',
'https://twitter.com/takezoen',
'Export issues as JSON from REPO_URL/issues/export.'
);
plugin.addRepositoryAction('/issues/export', function(request, response, repository){
var issues = plugin.db().select("SELECT * FROM ISSUE WHERE "+
"USER_NAME ='" + repository.owner() + "' AND " +
@takezoe
takezoe / plugin.scala
Last active August 29, 2015 14:05
Scala version of GitBucket Plug-in
import plugin._
val pluginDef = ScalaPlugin.define(id, version, author, url, description)
pluginDef.addRepositoryAction("/issues/export", Security.Member()){ (request, response, repository) =>
db.select(s"""SELECT * FROM ISSUE WHERE
USER_NAME = '${repository.owner}' AND
REPOSITORY_NAME = '${repository.name}' AND
PULL_REQUEST = false""").map { issue =>
Map(