Skip to content

Instantly share code, notes, and snippets.

View shimataro's full-sized avatar
:octocat:
I ♥️ 🍮

shimataro shimataro

:octocat:
I ♥️ 🍮
View GitHub Profile
@shimataro
shimataro / 1-deno-example.ts
Last active June 11, 2020 05:51
Deno examples
import { serve } from "https://deno.land/std@0.55.0/http/server.ts";
const s = serve({ port: 8000 });
console.log("http://localhost:8000/");
for await (const req of s) {
req.respond({ body: "Hell Word\n" });
}
@shimataro
shimataro / radix_sort.py
Last active September 17, 2019 14:33
基数ソート
#!/usr/bin/env python3
# coding: utf-8
from typing import List, Tuple, Union
def radix_sort(values: List[int]) -> List[int]:
"""
基数ソート
:param values: 入力値
:return: ソートされた値
@shimataro
shimataro / bucket_sort.py
Created September 15, 2019 17:17
粛清しないO(n)のソート
# coding: utf-8
from typing import List
def bucket_sort(values: List[int]) -> List[int]:
"""
バケットソート(分布数えソート)
:param values: 入力値(0から9までの整数値とする)
:return: ソートされた値
"""
@shimataro
shimataro / json.ts
Last active May 25, 2019 03:51
TypeScriptでJSON型
type json = null | boolean | number | string | JsonArray | JsonObject;
interface JsonArray extends Array<json> {
}
interface JsonObject {
[key: string]: json;
}
@shimataro
shimataro / deep-typeof.mjs
Last active August 26, 2018 21:04
再帰的なtypeof; nullや配列はobject型として判定しない
export default deepTypeof;
/**
* 再帰的なtypeof; nullや配列はobject型として判定しない
* @param {*} value 型を調べるデータ
* @returns {string} 型名
*/
function deepTypeof(value) {
const typename = typeof value;
@shimataro
shimataro / hiragana2romaji.js
Last active August 30, 2024 22:12
ひらがな→ローマ字変換
exports.default = hiragana2romaji;
// 変換テーブル; 文字数の多いものから登録していく
const convtables = [
{ // 3文字
"っきゃ": "kkya",
"っきぃ": "kkyi",
"っきゅ": "kkyu",
"っきぇ": "kkye",
"っきょ": "kkyo",
@shimataro
shimataro / disconnect_from_client.js
Last active January 13, 2018 05:33
Node.jsの挙動確認
// クライアントからの接続が切れたリクエストはどうなるのっと
var http = require("http");
function main(host, port)
{
http.createServer(respond).listen(port, host);
var url = "http://" + host + ":" + port + "/";
console.log("curl " + url);
}
@shimataro
shimataro / express-finally.es
Created January 10, 2018 14:35
res.finally()
function middleware(req, res, next) {
// 正常/異常を問わず、終了時に必ず呼びたい関数
res.finally = (callback) => {
res
.on("close", callback) // 異常終了
.on("finish", callback); // 正常終了
if (res.socket.destroyed) {
// すでに接続が切れていた
callback();
}
@shimataro
shimataro / ResourceManager.es
Last active January 8, 2018 11:31
リソースマネージャーを作ってみた
export class ResourceManager {
constructor() {
this._resourceFunctionsMap = {};
this._resourceSingletonMap = {};
this._closeCallbacks = [];
this._closed = false;
}
/**
* リソース登録
#!/bin/bash
# reverse mouse scroll direction
function _reverse_mouse_scroll_direction() {
local IFS=$'\n'
local DEVICE_NAME=$1
local PROP_NAME=$2
for id in $(xinput list | grep -F "${DEVICE_NAME}" | perl -n -e'/id=(\d+)/ && print $1')