Skip to content

Instantly share code, notes, and snippets.

View watermint's full-sized avatar
💭
I may be slow to respond.

Takayuki Okazaki watermint

💭
I may be slow to respond.
View GitHub Profile
@watermint
watermint / gist:3273976
Created August 6, 2012 12:07
ByteCodeMachine fails (JRuby 1.7.0preview1)
It's not reproducible with option --1.8.
ByteCodeMachine.java:561:in `opExactMB3N': java.lang.ArrayIndexOutOfBoundsException: 20
from ByteCodeMachine.java:205:in `matchAt'
from Matcher.java:293:in `matchCheck'
from Matcher.java:438:in `search'
from RubyString.java:2799:in `subBangNoIter19'
from RubyString.java:2755:in `sub_bang19'
from RubyString$INVOKER$i$sub_bang19.gen:-1:in `call'
from JavaMethod.java:343:in `call'
@watermint
watermint / gist:3433770
Created August 23, 2012 07:17
Restart Node
#!/usr/bin/env ruby
pipe = '/somewhere/commands'
launch_cmd = 'cd /somewhere ; node'
process_name = 'node'
open(pipe, 'r') do |f|
begin
f.each_line do |line|
case line.strip
@watermint
watermint / rename-yyyymmdd-to-iso8601.rb
Created March 20, 2013 08:32
rename-yyyymmdd-to-iso8601.rb
Dir.entries('.').keep_if {|x| x.start_with?('2') }.each do |d|
d =~ /^(2[0-9]{3})([0-9]{2})([0-9]{2})$/
puts "mv #{d} #{$1}-#{$2}-#{$3}"
end
public static void loadScript(Context context, Scriptable scope, String name) throws IOException {
String path = "src/main/resources";
try (Reader reader = new FileReader(new File(path + "/" + name))) {
Script script = context.compileReader(reader, name, 1, null);
script.exec(context, scope);
}
}
public static String[] getGoogleCodePrettifyScripts() {
@watermint
watermint / gist:5279281
Created March 31, 2013 02:41
google-code-prettifyを適用する
function sourcecolon(source){
var body = document.documentElement.childNodes[1];
var tag = document.createElement("code");
tag.className = "prettyprint";
tag.innerHTML = source.code;
body.appendChild(tag);
prettyPrint();
var printed = document.innerHTML;
@watermint
watermint / gist:5279287
Created March 31, 2013 02:44
適用した結果
<html><head/><body><code class="prettyprint prettyprinted"><span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">Sakura</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> main</span><span class="pun">(</span><span class="typ">String</span><span class="pun">...</span><span class="pln"> args</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="typ">System</span><span class="pun">.</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">&quot;bloom!&quot;</span><span class="pun">);</span><span class="pln"> </span><span class="com">/* hanami */</span><span class="pln"> </span><span class="pun">}</sp
@watermint
watermint / SimpleAnalyzer.scala
Last active December 15, 2015 21:49
Source:のAnalyzerをScalaで実装してみる
import scala.util.parsing.combinator.RegexParsers
import scala.util.parsing.input.Positional
object SimpleAnalyzer {
trait SearchKeyword extends Positional
case class KeywordIgnore(content:String) extends SearchKeyword
case class KeywordDefPackage(packageName:List[String]) extends SearchKeyword
case class KeywordDefClass(className:List[String]) extends SearchKeyword
case class KeywordRefSymbol(packageName:List[String]) extends SearchKeyword
case class KeywordComment(content:String) extends SearchKeyword
@watermint
watermint / gist:5471541
Created April 27, 2013 01:40
文字列をサロゲートペアを考慮した1文字ずつに分割する
object SurrogatePair {
case class Pair(x: Char, y: Option[Char] = None) {
lazy val surrogatePair = y match {
case None => false
case Some(yy) => Character.isSurrogatePair(x, yy)
}
lazy val text = surrogatePair match {
@watermint
watermint / A.java
Created July 26, 2013 02:20
enumにデフォルト実装をもたせられるか
interface Animal {
default void say() {
System.out.println("I'm Animal");
}
}
enum Bird implements Animal {
Sparrow,
Pigeon
}
@watermint
watermint / application-logger.xml
Created October 7, 2013 12:56
Configure Play2.2/Scala logging format as LTSV (Labeled Tab-separated Values).
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${application.home}/logs/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${application.home}/logs/application.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>14</maxHistory>
</rollingPolicy>
<encoder>
<charset>UTF-8</charset>