Skip to content

Instantly share code, notes, and snippets.

@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);
}
}
@shunjikonishi
shunjikonishi / dena.js
Created March 6, 2015 10:02
2015/03/06 DeNA問題とVasily問題の回答
var STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_!+-/.:";
var INPUT = "JfnAmrOmaTrRr:lmiCLmgCUpmoRRF/yycf:T!ZC-yuFyLfZLUrRyORUcf:ROy-fOOTlfiLC-iCU:cfLy";
var LOOP = 100000;
function adjust(n) {
while (n > 58) {
n -= 59;
}
while (n < 0) {
n += 59;
@shunjikonishi
shunjikonishi / sql-fixtures.js
Created April 24, 2015 04:21
node-sql-fixtures #28
"use strict";
/*
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NULL,
github_username VARCHAR(255) NULL,
password VARCHAR(255) NULL,
image_url VARCHAR(255) NULL,
@shunjikonishi
shunjikonishi / implicitDef.scala
Created May 13, 2015 10:58
Simple example of implicit def.(REPL)
scala> val a = "Jack"
a: String = Jack
scala> a.hello
<console>:9: error: value hello is not a member of String
a.hello
^
scala> class B(s: String) {
| def hello = "Hello " + s
@shunjikonishi
shunjikonishi / Test.scala
Last active August 29, 2015 14:22
問5回答 40分くらい
// http://www.softantenna.com/wp/software/5-programming-problems/
// Problem 5
case class Expr(str: String, ret: Int) {
def plus(n: Int) = Expr(str + " + " + n, ret + n)
def minus(n: Int) = Expr(str + " - " + n, ret - n)
def concat(n: Int) = {
val next = last match {
case 0 => ret * 10 + n
case x if (x < 0) => ret - x + (x * 10) - n
case x if (x > 0) => ret - x + (x * 10) + n
@shunjikonishi
shunjikonishi / QueryDSL.scala
Last active August 29, 2015 14:23
Skinny group by sample
val c = Challenge.syntax("c")
val cr = ChallengeResult.syntax("cr")
val list = withSQL {
select(
c.result.*,
sqls"count(cr.id) as count"
).from(Challenge as c)
.leftJoin(ChallengeResult as cr)
.on(c.id, cr.challengeId)
.where(buildCondition(user.id, publicOnly))
SELECT
c.id,
count(cr.id) as count
FROM challenges c
LEFT OUTER JOIN exam_challenges ec ON (c.id = ec.challenge_id)
INNER JOIN exams e ON (ec.exam_id = e.id)
LEFT OUTER JOIN exam_delivers ed ON (ed.exam_id = e.id)
LEFT OUTER JOIN challenge_results cr ON (c.id = cr.challenge_id AND cr.deliver_id = ed.id)
WHERE c.user_id in (1)
GROUP BY c.id