Skip to content

Instantly share code, notes, and snippets.

@hoshi-takanori
hoshi-takanori / sample.svg
Last active March 20, 2016 08:53
Convert SVG to Android VectorDrawable in Haskell.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hoshi-takanori
hoshi-takanori / SurrogatePair.java
Last active March 15, 2016 07:04
Surrogate pair index conversion in Java.
public class SurrogatePair {
public static int convertToUTF16Index(String str, int index) {
int result = 0;
for (int i = 0; i < index && result < str.length(); i++, result++) {
if (result + 1 < str.length() &&
Character.isSurrogatePair(str.charAt(result), str.charAt(result + 1))) {
result++;
}
}
return result;
@hoshi-takanori
hoshi-takanori / BinaryTree.swift
Last active March 24, 2019 21:04
Binary Tree in Swift 2.0.
//: Binary Tree
protocol CollectionTypeConvertible {
typealias T
var array: [T] { get }
}
class Node<T: Comparable> {
let value: T
var left: Node?
@hoshi-takanori
hoshi-takanori / nolist.go
Last active February 24, 2024 18:56
http.FileServer with no directory listing.
// http://grokbase.com/p/gg/golang-nuts/12a9xcadca/go-nuts-disable-directory-listing-with-http-fileserver
package main
import (
"net/http"
"os"
)
type NoListFile struct {
@hoshi-takanori
hoshi-takanori / gob-example.go
Created May 27, 2015 08:30
How to use bytes.Buffer with gob encoder/decoder.
package main
import (
"bytes"
"encoding/gob"
"io"
)
type Data struct {
A int
@hoshi-takanori
hoshi-takanori / custom-file-server.go
Last active August 29, 2015 14:21
Custom http.FileServer to overwrite Content-Type header.
package main
import (
"net/http"
"strings"
)
var CustomTypeMap = map[string]string{
"text/x-java-source": "text/plain",
}
@hoshi-takanori
hoshi-takanori / app.js
Last active December 2, 2021 10:25
Invoke CGI from Express.js.
var express = require('express');
var cgi = require('./cgi');
app = express();
var script = __dirname + '/hello.cgi';
app.get('/', cgi(script, function (req, options) {
options.env.USERNAME = 'Mr. User';
}));
app.use(function (err, req, res, next) {
@hoshi-takanori
hoshi-takanori / MyMemoryStore.js
Last active August 29, 2015 14:03
Create my own session store for Express 4.
module.exports = function (session) {
var Store = session.Store;
function MyMemoryStore(options) {
Store.call(this, options || {});
this.debug = options && options.debug;
this.sessions = {};
}
MyMemoryStore.prototype.__proto__ = Store.prototype;
@hoshi-takanori
hoshi-takanori / Server.java
Created May 29, 2014 11:49
ちょーかんたんなサーバー。
import java.io.*;
import java.net.*;
/**
* ちょーかんたんなサーバー。
*/
public class Server {
/**
* ポート番号。
*/
@hoshi-takanori
hoshi-takanori / webprog.txt
Last active August 29, 2015 14:01
Webプログラミング入門の講義予定。
Webプログラミング入門
1. ネットワークプログラミングの基礎
講義
- ネットワークの論理構成
- ホスト名とIPアドレス
- TCP/UDPとポート番号
- プロトコル、ステートフルとステートレス
演習
簡単なチャットプログラム