Skip to content

Instantly share code, notes, and snippets.

@yusuiked
yusuiked / hook-chain
Created July 19, 2021 02:47
git の hook を複数実行したい時
#!/usr/bin/env bash
export GIT_DIR=`git rev-parse --git-dir`
hookname=`basename $0`
FILE=`mktemp`
trap 'rm -f $FILE' EXIT
cat - > $FILE
@yusuiked
yusuiked / pukiwiki2md.groovy
Last active October 24, 2016 06:05
PukiWiki のページファイル名の変換と、Pukiwiki 記法から Markdown 記法へ変換する雑なスクリプト
StringBuilder sb = new StringBuilder()
new File('wiki.txt').eachLine { line ->
// link
line = line.replaceAll(/\[\[(.*):(https*:.*)\]\]/, '[$1]($2)')
if (line.startsWith('#geshi')) {
// code
sb << line.replaceFirst(/^#geshi\((.*)\)\s*\{\{$/, '```$1')
} else if (line.startsWith('}}')) {
sb << line.replace('}}', '```')
} else if (line.matches(/^\|.*\|h$/)) {
@yusuiked
yusuiked / file0.groovy
Last active April 17, 2016 03:17
Gradle 2.0 以降と IDEA プラグインで Configuration として provided を定義して idea.module のスコープに追加すると ClassCastException が発生する ref: http://qiita.com/yukung/items/1ccb29cc2c0cc9905e8e
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.8
version = '0.0.1-SNAPSHOT'
repositories {
mavenCentral()
}
@yusuiked
yusuiked / build.gradle
Created March 2, 2015 03:00
Gradle で provided スコープを実現する
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.7
tasks.withType(AbstractCompile) { options.encoding = 'UTF-8' }
version = '1.0'
configurations {
provided
}
@yusuiked
yusuiked / file0.txt
Last active August 29, 2015 14:10
Gradle で NoClassDefFoundError でビルドできない時 ref: http://qiita.com/yukung/items/fb3f2592a9f01003229c
$ ./gradlew tasks --debug
(省略)
15:49:07.706 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
15:49:07.707 [ERROR] [org.gradle.BuildExceptionReporter]
15:49:07.707 [ERROR] [org.gradle.BuildExceptionReporter] * Where:
15:49:07.707 [ERROR] [org.gradle.BuildExceptionReporter] Build file '~/src/github.com/yukung/some-project/build.gradle' line: 167
15:49:07.707 [ERROR] [org.gradle.BuildExceptionReporter]
15:49:07.708 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
15:49:07.708 [ERROR] [org.gradle.BuildExceptionReporter] A problem occurred evaluating root project 'some-project'.
15:49:07.708 [ERROR] [org.gradle.BuildExceptionReporter] > [Ljava/util/HashMap$Entry;
@yusuiked
yusuiked / ConcurrentNew.java
Last active October 16, 2020 16:07
Sample code to sort by word length.
import java.util.concurrent.atomic.LongAdder;
public class ConcurrentNew {
public static void main(String[] args) {
// Java8 から追加された、複数スレッドからアトミックに更新できる Long 型の LongAdder
// Java5 からある、AtomicInteger などと同じような考え方だが、Atomic系のクラスよりも高いパフォーマンスを出す。
// 複数スレッドから頻繁に更新するようなケースで高いパフォーマンスを発揮する。
// 他にも DoubleAdder などがある。
LongAdder longAdder = new LongAdder();
// 加算
@yusuiked
yusuiked / javaee6.web.xml
Created February 13, 2014 03:08
JavaEE6 の web.xml の書き方。JSPテンプレートも込みで。
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="serv" version="3.0">
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
@yusuiked
yusuiked / .bash_profile
Last active May 1, 2017 02:02
こっちはMacのbash用
# ls coloring and shortcut
alias ls='ls -G'
alias ll='ls -hl'
alias la='ls -a'
export CLICOLOR=1
export LSCOLORS=gxfxcxdxbxegedabagacad
# less coloring settings
export LESS='-R'
@yusuiked
yusuiked / recursiveFilter.groovy
Created January 6, 2012 04:12
フィルタリングの再帰バージョン。
def filter(list, p) {
if (list.size() == 0) return list
if (p(list.head()))
[] + list.head() + filter(list.tail(), p)
else
filter(list.tail(), p)
}
l = filter(1..20, {n-> n % 2 == 0})
@yusuiked
yusuiked / filter.groovy
Created January 6, 2012 04:10
リストとリストに対するフィルタリングの実装をクロージャとして渡してフィルタリングする
def filter(list, p) {
def new_list = []
list.each { i ->
if (p(i))
new_list << i
}
new_list
}
modBy2 = { n -> n % 2 == 0}