Skip to content

Instantly share code, notes, and snippets.

View int128's full-sized avatar

Hidetake Iwata int128

View GitHub Profile
@int128
int128 / gist:2840142fbf884b678dfc
Created March 29, 2016 13:20
Using closure of Groovy2 on Groovy1
class ClosureBridge {
static Closure wrap(closureOnAnotherWorld) {
{ ->
closureOnAnotherWorld.delegate = delegate
closureOnAnotherWorld.resolveStrategy = resolveStrategy
closureOnAnotherWorld.call()
}
}
}
@int128
int128 / gist:810690033ca07622f4b7
Created March 26, 2016 11:54
Groovy Trait with Annotation
import java.lang.annotation.Retention
import java.lang.annotation.RetentionPolicy
@Retention(RetentionPolicy.RUNTIME)
@interface T {
Class formatter
}
trait A {
@T(formatter = {})
class A {
def foo
}
class B {
def foo
}
class C {
@Delegate A a = new A()
@int128
int128 / app.js
Last active October 14, 2017 08:22
Record history on Google Spreadsheet
// Add a trigger to run everyday
function appendHistoryRow() {
var app = SpreadsheetApp.getActive();
app.setSpreadsheetTimeZone('Asia/Tokyo');
var historyRow = app.getRangeByName('history_row');
var values = historyRow.getValues();
values[0][0] = new Date();
historyRow.getSheet().appendRow(values[0]);
}
@int128
int128 / jsdom.js
Created July 27, 2015 06:46
Attempt to use xslt with jsdom but failed
var jsdom = require("jsdom");
document = jsdom.jsdom();
window = document.defaultView;
var xslt = require("xslt");
var result = xslt(
'<a>xxx</a>',
'<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="xml" encoding="UTF-8"/></xsl:stylesheet>');
console.info(result);
@int128
int128 / client.conf
Created July 20, 2015 08:16
OpenVPN client.conf
##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server. #
# #
# This configuration can be used by multiple #
# clients, however each client should have #
# its own cert and key files. #
# #
# On Windows, you might want to rename this #
# file so it has a .ovpn extension #
@int128
int128 / google-apps-script.js
Created April 4, 2015 06:49
Google Apps Script Template
/**
* @OnlyCurrentDoc Limits the script to only accessing the current spreadsheet.
*/
/**
* A function that takes a single input value and returns a single value.
* Returns a simple concatenation of Strings.
*
* @param {String} name A name to greet.
* @return {String} A greeting.
@int128
int128 / GroovySsh.rb
Created February 25, 2015 15:03
Groovy SSH on Homebrew
class GroovySsh < Formula
homepage "https://github.com/int128/groovy-ssh"
url "https://github.com/int128/groovy-ssh/releases/download/v1.1.3/groovy-ssh.jar"
version "1.1.3"
sha1 "2674602e2c966893eecafa75a9ec38bf46d8f392"
head "https://github.com/int128/groovy-ssh.git"
depends_on :java => "1.6+"
@int128
int128 / setenv.sh
Created February 18, 2015 14:33
How to prevent freeze on waiting random device on Java
  1. /tmp/apache-tomcat-7.0.59/bin/setenv.sh に下記の内容を書く.
  2. chmod +xなどは不要.
  3. setenv.shがすでに存在する場合はCATALINA_OPTSの内容をマージする.
@int128
int128 / parser.groovy
Last active August 29, 2015 14:15
Method Overload with Map and Closure in Groovy
@groovy.transform.ToString()
class Args {
Collection items
Map settings
Closure closure
static Args parse(Object[] objects) {
def args = new Args()
def stack = objects as LinkedList
if (stack.last() instanceof Closure) {