Skip to content

Instantly share code, notes, and snippets.

@shunjikonishi
shunjikonishi / enum.js
Last active December 16, 2015 20:39
Template of javascript-enum
function Enum(values) {
for (var i=0; i<values.length; i++) {
var v = values[i];
this[v.name] = v;
}
$.extend(this, {
"fromCode" : function(v) {
for (var i=0; i<values.length; i++) {
if (values[i].code == v) return values[i];
}
@shunjikonishi
shunjikonishi / messages-play2.js
Last active December 16, 2015 20:39
Template of messages.js (Playframework 2 - scala)
@(map: Map[String, String])
if (typeof(flect) == "undefined") flect = {};
if (typeof(flect.app) == "undefined") flect.app = {};
if (typeof(flect.app.XXXX) == "undefined") flect.app.XXXX = {};
flect.app.XXXX.MSG = {@map.map{ case(key, value) =>
"@key" : "@value",}
"format" : function(fmt) {
for (i = 1; i < arguments.length; i++) {
var reg = new RegExp("\\{" + (i - 1) + "\\}", "g")
@shunjikonishi
shunjikonishi / messages-play1.js
Created May 1, 2013 04:52
Template of messages.js (Playframework 1)
if (typeof(flect) == "undefined") flect = {};
if (typeof(flect.app) == "undefined") flect.app = {};
if (typeof(flect.app.XXXX) == "undefined") flect.app.XXXX = {};
flect.app.XXXX.MSG = {
#{list items:map.entrySet(), as:'entry' }
"${entry.getKey()}" : "${entry.getValue()}",#{/list}
"format" : function(fmt) {
for (i = 1; i < arguments.length; i++) {
var reg = new RegExp("\\{" + (i - 1) + "\\}", "g")
@shunjikonishi
shunjikonishi / strToDate.js
Last active December 17, 2015 14:39
yyyy-MM-dd HH:mm:ss形式のstrToDateとdateToStr
function strToDate(str) {
var y = parseInt(str.substring(0, 4)),
m = parseInt(str.substring(5, 7)),
d = parseInt(str.substring(8, 10)),
h = parseInt(str.substring(11, 13)),
mi = parseInt(str.substring(14, 16)),
s = parseInt(str.substring(17, 19)),
ms = 0;
return new Date(y, m - 1, d, h, mi, s, ms);
}
@shunjikonishi
shunjikonishi / HerokuApi.java
Last active December 21, 2015 02:58
The prototype of HerokuApi wrapper for Playframework 1.2.x
package models;
import play.libs.WS;
import play.libs.WS.HttpResponse;
import play.libs.WS.WSRequest;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.Serializable;
public class HerokuApi implements Serializable {
@shunjikonishi
shunjikonishi / gist:9969366
Last active August 29, 2015 13:58
WebSocket負荷テストの結果
WebSocket負荷テストの結果
----
Room2, Client1 = 10000
Room2, Client2 = 10000
Room3, Client1 = 3600
Room3, Client2 = 3600
Room4, Client1 = 5500
Room4, Client2 = 5500
Room5, Client1 = 10000
Room5, Client2 = 10000
@shunjikonishi
shunjikonishi / InboundMailServlet.java
Last active August 29, 2015 14:05
SendGridでメールを送受信するサンプル
package herokuSamples.web.mail;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.io.UnsupportedEncodingException;
import java.io.InputStream;
import java.io.IOException;
@shunjikonishi
shunjikonishi / directive.js
Last active August 29, 2015 14:08
AngularJS: Custom maxlength and minlength with surrogate pair support.(1.2.x)
angular.module('directive')
.directive("spMaxlength", function() {
return {
restrict: 'A',
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
var max = parseInt(attrs.spMaxlength || 0, 10);
ctrl.$parsers.unshift(function(viewValue) {
var len = viewValue ? viewValue.length - (viewValue.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g)||[]).length : 0;
if (len <= max) {
@shunjikonishi
shunjikonishi / Gruntfile.js
Created December 4, 2014 08:31
Gruntからherokuコマンドを実行する
module.exports = function (grunt) {
'use strict';
function loadDependencies(deps) {
if (deps) {
for (var key in deps) {
if (key.indexOf("grunt-") == 0) {
grunt.loadNpmTasks(key);
}
}