Skip to content

Instantly share code, notes, and snippets.

View nobusue's full-sized avatar

Nobuhiro Sue nobusue

View GitHub Profile
@nobusue
nobusue / Hex2BinDec.groovy
Created August 12, 2015 03:00
Groovyで16進->2進/10進変換
groovy -e "def b='10 49 4a 03'; println b.split(' ').collect{ Integer.decode('0x'+it) }.join(' '); println b.split(' ').collect{ Integer.toBinaryString(Integer.decode('0x'+it)).padLeft(8,'0') }.join('_')"
@nobusue
nobusue / CassandraInsertAndSelect.groovy
Created May 4, 2015 03:01
Cassandra Java Driverでデータのinsertとselectを行う
@Grapes(
@Grab(group='com.datastax.cassandra', module='cassandra-driver-core', version='2.1.5')
)
import com.datastax.driver.core.*
def cluster = Cluster.builder().addContactPoint('127.0.0.1').build()
def session = cluster.connect()
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('foo', 'bar');");
session.execute("INSERT INTO first_keyspace.first_table (name, value) VALUES ('gee', 'baz');");
@nobusue
nobusue / ShowCassandraMetadata.groovy
Created May 4, 2015 02:41
localhostのCassandraにJava Driverで接続してクラスタ名やホスト名を取得
@Grapes(
@Grab(group='com.datastax.cassandra', module='cassandra-driver-core', version='2.1.5')
)
import com.datastax.driver.core.*
def cluster = Cluster.builder().addContactPoint('127.0.0.1').build()
def metadata = cluster.getMetadata()
println "Connected to cluster: ${metadata.getClusterName()}"
@nobusue
nobusue / gist:823fbebf56205d89de31
Created December 29, 2014 08:50
Gradle Tomcat Plugin利用サンプル(Gradle徹底入門より)
// build.gradle: Gradle2.2.1で稼働確認ずみ
// (1) Tomcatプラグイン利用のための設定
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.bmuschko:gradle-tomcat-plugin:2.0'
}
}
@nobusue
nobusue / native2ascii_imperfect.gradle
Created July 21, 2014 16:39
Gradleでのnative2asciiの代替(不完全版)
/* 行末に特定の日本語文字があると文字化けしてしまう・・残念 */
import org.apache.tools.ant.filters.EscapeUnicode
apply plugin: 'java'
processResources {
include '**/*.properties'
filter{ String line ->
//byte[] bytes = line.getBytes()
@nobusue
nobusue / build.gradle
Created May 3, 2014 15:41
Gradle SSH Pluginをオフラインで利用する(Fabricぽいことしたい) ref: http://qiita.com/nobusue/items/e93e928b937c5c8eb4e6
remotes {
localhost {
host = 'localhost'
user = System.properties['user.name']
identity = file("${System.properties['user.home']}/.ssh/id_rsa")
}
}
task showPlatformVersion(type: SshTask) {
session(remotes.localhost) {
@nobusue
nobusue / KonekoTube.groovy
Created December 1, 2011 15:46
G* Advent Calendar 2011/12/02: G*といえば猫、ということでYouTubeから子猫動画をランダムに再生
def feed = new XmlSlurper().parse(
"http://gdata.youtube.com/feeds/api/videos?category=kitten")
def uri = feed.entry[(int)(Math.random()*feed.itemsPerPage.toInteger())]
.link.find{it.@rel == 'alternate'}.@href
java.awt.Desktop.getDesktop().browse(new URI(uri.toString()))
@nobusue
nobusue / bayes.groovy
Created November 6, 2011 01:08
指定したURLの内容からジャンルをベイズ推定: groovy bayes.groovy <url>
/*
* ベイジアンフィルタのサンプル(Groovyバージョン)
* 元ネタ) 機械学習 はじめよう 第3回 ベイジアンフィルタを実装してみよう
* http://gihyo.jp/dev/serial/01/machine-learning/0003
*
* 分かち書きにはGomokuを利用
* https://github.com/sile/gomoku
* gomoku-0.0.4.jarをダウンロードし、~/.groovy/lib か <GROOVY_HOME>/lib にコピーしておく
*
* 学習ソースとしてWikipediaのテキストをJsoupで取得
@nobusue
nobusue / wikipedia.groovy
Created November 5, 2011 12:23
Wikipedia scraping: groovy wikipedia.groovy <keyword> キャッシュ機能付き
@Grab(group='org.jsoup', module='jsoup', version='1.6.1')
import org.jsoup.*
def keyword = 'Groovy'
if(args && args[0]) keyword = args[0]
def home = System.getProperty('user.home')
def tmp = home + '/tmp'
@nobusue
nobusue / cal.groovy
Created November 5, 2011 10:54
calコマンド: groovy cal.groovy <year> <month>
import static java.util.Calendar.*
def cal = Calendar.instance
def year = cal[YEAR]
def month = cal[MONTH]
if(args && args[0] && args[0].isInteger() && args[1] && args[1].isInteger()) {
year = args[0].toInteger()
month = args[1].toInteger()
cal[YEAR] = year