Skip to content

Instantly share code, notes, and snippets.

synchronized def print(String str) {
System.out.print str
}
def bootServer() {
def server = new ServerSocket(8080)
Thread.start {
while (true) {
def soc
try { soc = server.accept() }
catch (SocketException e) { println "[server] SocketError: $e.message"; break }
@am4dr
am4dr / socket.groovy
Created October 6, 2016 16:26
with Java Socket
new Socket('example.com', 80).withStreams { is, os ->
def req = 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n'
println "[[$req]]"
os << req.getBytes('utf-8')
System.out << is // blocking
}
@echo off
pushd %~dp0
powershell -Command "& {ls | where {$_.name.endswith('-orig')} | %%{$to = ($_.name -replace '-orig',''); echo "rename` $_` $to"; Rename-Item $_.name $to} }"
popd
@Grab(group='org.apache.commons', module='commons-lang3', version='3.4')
String a = '\\u003cb\\u003e'
println a
println org.apache.commons.lang3.StringEscapeUtils.unescapeJava(a)
// Outputs:
// \u003cb\u003e
// <b>
" License: MIT
" (c) 2015 am4dr <t.f.octo@gmail.com>
if exists('g:loaded_syntastic_groovy_groovyc_checker')
finish
endif
let g:loaded_syntastic_groovy_groovyc_checker = 1
let s:save_cpo = &cpo
set cpo&vim
@am4dr
am4dr / sketch.groovy
Last active August 29, 2015 14:18
GroovyConsole上でProceccing
@Grab(group='org.processing', module='core', version='2.2.1')
import processing.core.*
class MySketch extends PApplet {
final float r = 200
final int FPS = 60
final float sec = 1
final float radpf = 2*PI / sec / FPS
void setup() {
frameRate(FPS)
@am4dr
am4dr / pathToStringWithSeparator.groovy
Last active August 29, 2015 14:16
Pathを任意のセパレータを用いて文字列化する。JavaとStreamによる方法。
import java.nio.file.Path
import java.nio.file.Paths
def p = Paths.get('aaa', 'bbb', 'ccc').resolve('xxx/yyy/zzz/')
assert p as String == /aaa\bbb\ccc\xxx\yyy\zzz/
import java.util.stream.*
def pathToString(Path path, String separator = '/', boolean startsWithSeparator = false) {
StreamSupport.stream(path.spliterator(), false)
.map{ it.toString() }
@am4dr
am4dr / svg-memo.html
Created February 27, 2015 08:20
SVG <symbol>
<!doctype html>
<html lang="ja">
<head>
<title>power!</title>
</head>
<body>
<svg width="600" height="200">
<defs>
<symbol id="rrr" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid"
width="100" height="100">
@am4dr
am4dr / sc.vim
Last active August 29, 2015 14:02
" usage
" 1. acrobat readerで全文選択コピー
" 2. バッファに貼り付け
" 3. :source sc.vim
" TODO
" - markを上手に使って全体的にもう少しきれいに書けそう?
" - `^##`にマッチしない行で条件に合う行を全部結合したい処理をきれいに。
" Contentsをaとしてマーク
g/^Contents$/normal ma
@am4dr
am4dr / get_url.js
Last active August 29, 2015 14:01
そのページのタイトルとURLをmarkdownのリンクの書式"[title](url)"で得るためのブックマークレット。execCommand('copy')。
javascript:var e=document.createElement('input');e.type='text';e.value="["+document.title+"]"+"("+document.URL+")";document.body.appendChild(e);e.select();document.execCommand('copy');document.body.removeChild(e);void(0);