Skip to content

Instantly share code, notes, and snippets.

View tile-lat-lon.mjs
const pi = Math.PI;
const e = Math.E;
// tile座標とズームレベルから緯度経度を求める
function tile2latlon(x, y, z) {
const lon = (x / 2.0 ** z) * 360 - 180;// # 経度(東経)
const mapy = (y / 2.0 ** z) * 2 * pi - pi;
const lat = 2 * Math.atan(e ** (- mapy)) * 180 / pi - 90;// # 緯度(北緯)
return { lat: lat, lon: lon };
}
View FuncWorker.cc
template <class T>
constexpr bool is_string(){
return std::is_same<char *, typename std::decay< T >::type >::value
|| std::is_same< const char *, typename std::decay< T >::type >::value
|| std::is_same<std::string, typename std::decay<T>::type>::value;
};
template<typename FuncType = std::function<int()>,bool IsReturnValue = false>
class FuncWorker : public Napi::AsyncWorker
View sqlite3-napi.cc
#include "sqlite3-napi.h"
#include "uv.h"
#include <iostream>
using namespace sqlite3_napi;
// ---------------------------------------
// Database Implementation
// ---------------------------------------
View markdown.pl
#!/usr/bin/perl
#
# Markdown -- A text-to-HTML conversion tool for web writers
#
# Copyright (c) 2004 John Gruber
# <http://daringfireball.net/projects/markdown/>
#
View test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS詳細度テスト</title>
<style>
* {
font-size:10px;
View test.wat
;; JSの16進数字列からi64値に変換する
(func $hexArrayToi64
;; 引数
(param $length i32)(param $outoffset i32)(param $sign i32)
;; 戻り値
(result i32)
;; ローカル変数
(local $offset i32) (local $l i32) (local $temp i64)
(local.set $l (i32.shl (local.get $length) (i32.const 1)))
@sfpgmr
sfpgmr / test.mwat
Last active Apr 20, 2019
WASMテキストモードのプリプロセスをJSでできるようにしてみた。
View test.mwat
;; block
{@
$.X = 0x1;
$.Y = 2;
$.Z = 0x3;
}
;; code
(module
(export "test" (func $test))
View for.pegjs
/ ForToken __
"(" & __
init:(ExpressionNoIn __ )? ";" __
test:(Expression __)? ";" __
update:(Expression __)?
")" __
body:Statement
{
@sfpgmr
sfpgmr / co-test.mjs
Created Oct 13, 2018
オレオレ言語のコルーチンをハンド・コンパイルしてみた。
View co-test.mjs
import binaryen_ from '../binaryen-wasm';
import fs from 'fs';
export function getInstance(obj,imports = {}) {
const bin = new WebAssembly.Module(obj);
const inst = new WebAssembly.Instance(bin, imports);
return inst;
}
(async ()=>{
@sfpgmr
sfpgmr / .wat
Created Aug 14, 2018
メモリの検証コードを書く
View .wat
(module
(export "test" $test)
(memory $memory 1)
(export "memory" (memory $memory))
(func $test
(drop(grow_memory (i32.const 3)));;3ページ分確保
(i32.store
(i32.const 0)
(i32.mul (current_memory) (i32.const 65536));;現在のページ数にサイズ(65536bytes)をかけた数をオフセット0に格納
)