Skip to content

Instantly share code, notes, and snippets.

@kwatch
kwatch / perceptron.py
Last active July 17, 2016 02:22
(obsolete) (ML) Example1
# -*- coding: utf-8 -*-
import sys
import numpy as np
class Perceptron(object):
"""Perceptron classifier.
Parameters
@kwatch
kwatch / models.py
Created July 5, 2016 00:22
SQLおじさんのサンプルSQLをO/Rマッパーで書いてみた
# -*- coding: utf-8 -*-
"""
SQLAlchemy example code.
Requirements:
* Python3
* PostgreSQL
* SQLAlchemy
@kwatch
kwatch / 0_reuse_code.js
Created May 15, 2016 01:40
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@kwatch
kwatch / pydiet.sh
Last active May 8, 2016 15:34
pydiet.sh -- remove unnecessary files from Python directory interactively
#!/bin/sh
###
### pydiet.sh -- remove unnecessary files from Python directory interactively
###
### Feature:
### * remove test script files (ex: python2.7/test/*)
### * remove *.pyo files (ex: python2.7/**/*.pyo)
### * remove *.opt-[12].pyc files (Python 3.5 or later)
###
@kwatch
kwatch / scrumble_bench.py
Last active March 4, 2016 08:27
benchmark: scrumble_uinit32 vs encrypt
# -*- coding: utf-8 -*-
import sys
from benchmarker import Benchmarker
import main
from rchk.utils.simple_crypto import encrypt, decrypt
from rchk.utils import scrumble_uint32
@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";
}
@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 / 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 / 15puzzle.js
Created December 16, 2015 00:14
15puzzle.js
/// coding: utf-8
///
/// for 15puzzle
///
var Util = {
init: function() {
@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;