Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / sample.py
Created September 11, 2015 01:16
Pythonでは条件によってブロックをスキップするような構文がない
@on('POST', '/foobar')
def do_post(self):
do_something1()
do_something2()
## 残念ながら Python ではブロックをスキップする機能が
## ないのでこれは使えない
with invoke('new_cool_feature_name'):
old_feature1()
old_feature2()
## なので、decoratorをhiger order functionの
@kwatch
kwatch / bench1.rb
Last active January 7, 2016 10:50
Ruby on Rails, Sinatra, Rack+Request+Response, Keight.rb のベンチマークスクリプト
# -*- coding: utf-8 -*-
require 'sinatra/base'
require 'rack'
require 'rack/protection'
require 'rack/protection/frame_options'
require 'rack/protection/http_origin'
require 'rack/protection/ip_spoofing'
require 'rack/protection/json_csrf'
require 'rack/protection/path_traversal'
@kwatch
kwatch / bench_zerofill.py
Created November 11, 2015 14:09
Benchmark: create a list object filled by zero
# -*- coding: utf-8 -*-
###
### Benchmark: create a list object padding by zero
###
from benchmarker import Benchmarker
try:
xrange
# -*- coding: utf-8 -*-
###
### Benchmark: http://cocodrips.hateblo.jp/entry/2015/10/11/114212#問題2
###
from benchmarker import Benchmarker
try:
xrange
@kwatch
kwatch / 15puzzle.html
Last active December 16, 2015 00:18
15puzzle.html
<html>
<head>
<meta charset="utf-8" />
<title>15 Puzzle</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<div id="main-content">
<table id="puzzle">
<tbody>
@kwatch
kwatch / main.css
Created December 16, 2015 00:14
main.css
/* coding: utf-8 */
#main-content {
padding-top: 50px;
}
#puzzle {
border-collapse: collapse;
border: solid 1px #ccc;
font-size: x-large;
@kwatch
kwatch / 15puzzle.js
Created December 16, 2015 00:14
15puzzle.js
/// coding: utf-8
///
/// for 15puzzle
///
var Util = {
init: function() {
@kwatch
kwatch / read_nonblocking.rb
Created December 20, 2015 05:01
My favorite nonblocking read() API in Ruby
class IO
##
## Easy-to-use nonblocking read()
##
## * returns non-empty string when data exists
## * returns empty string when data not exist
## * returns nil when EOF
##
def read_nonblocking(size)
@kwatch
kwatch / ex1.cpp
Created February 16, 2016 04:19
Local variable is not initialized in C++
#include <iostream>
int fn() {
int x;
return x; // returns uninitialized local variable
}
int main(int argc, char*args[]) {
//std::cout << "Hello\n";
std::cout << fn() << "\n";
@kwatch
kwatch / ex2.cpp
Last active February 16, 2016 05:24
C++ compiler warns uninitialized local variable of int, but not of object.
#include <iostream>
#include <string>
void fn() {
int x;
std::string s;
std::cout << x; // warning: variable 'x' is uninitialized when used here
std::cout << s; // (no warnings due to default constructor)
std::cout << "\n";
}