Skip to content

Instantly share code, notes, and snippets.

@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
var assert = require("chai").assert;
var codecheck = require("codecheck");
var expected = [];
for (var i=1; i<= 100; i++ ) {
if(i % 15 == 0) expected.push("FizzBuzz");
else if (i % 5 == 0) expected.push("Buzz");
else if (i % 3 == 0) expected.push("Fizz");
else expected.push("" + i);
}
module.exports = function (grunt) {
'use strict';
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var proxyOptionsLocal = {
"use strict";
var React = require("react");
var Link = require('react-router').Link;
var Tabs = React.createClass({
render: function() {
return (
<div>
<ul>

Usecase

  • There are too many items.
    • e.g. log output
    • It migght be more than million.
  • Need to store latest 1000 items.

Solution

We can implement with simple array