Skip to content

Instantly share code, notes, and snippets.

View martian17's full-sized avatar
🛰️
Working from home

Yutaro Yoshii martian17

🛰️
Working from home
View GitHub Profile
@martian17
martian17 / index.ts
Created March 23, 2023 14:38
meta programming in ts
//util functions
const isNode = typeof window === "undefined";
const U8FromView = function(view: ArrayBufferView): Uint8Array{
if(view instanceof Uint8Array){
return view;
}
return new Uint8Array(view.buffer,view.byteOffset,view.byteLength);
};
@martian17
martian17 / intersection.ts
Last active March 18, 2023 23:37
Testing code from stackoverflow
// source: https://stackoverflow.com/questions/72669756/property-selected-of-type-boolean-is-not-assignable-to-string-index-type
interface Field {
selected: boolean;
value: any;
}
type ConflictingVersionModel = {
[key: string]: Field;
} & { selected: boolean };
@martian17
martian17 / hanoi.js
Created March 14, 2023 15:08
Solves tower of hanoi
const range = function(n){
const arr = [];
for(let i = 0; i < n; i++){
arr.push(i);
}
return arr;
};
const peek = function(arr){
return arr[arr.length-1];
@martian17
martian17 / parking-spot.md
Last active March 14, 2023 09:56
Parking Jam Solver

Get all cars out!

This problem is based on a famous mobile game called parking jam. Here is a video footage from the game play.
https://www.youtube.com/watch?v=cDv_-LezHPw
In order to define the rules better, I decided to change it up a bit. Cars, walls, and empty spaces are now represented by characters on a grid of string. Each car consists of an arrow spanning two adjacent squares with the charset <>v^|-. Walls are marked by *, and the exit is marked by =. Here is an example input:

********
*<-|->^*
*  v<-|*
*<-  | =
* |-&gt;v *
********
*<>^<>^*
* v<>v*
*<> ^ =
* ^<>v *
* v <>*
********
@martian17
martian17 / nbt.js
Last active February 5, 2023 10:53
refactored
const TAG_End = 0;
const TAG_Byte = 1;
const TAG_Short = 2;
const TAG_Int = 3;
const TAG_Long = 4;
const TAG_Float = 5;
const TAG_Double = 6;
const TAG_Byte_Array = 7;
const TAG_String = 8;
const TAG_List = 9;
@martian17
martian17 / territorial-sweeper.mjs
Created February 1, 2023 06:24
territorial.io tool
let canvas = document.querySelector("canvas");
let ctx = canvas.getContext("2d");
let display = document.createElement("canvas");
document.body.appendChild(display);
display.style.zIndex = "1000";
display.style.position = "absolute";
display.style.bottom = "0px";
display.style.right = "0px";
display.style.pointerEvents = "none";
display.width = canvas.width/4;
@martian17
martian17 / randinspect.js
Created December 23, 2022 01:15
inspect Math.random
{
let ab = new ArrayBuffer(8);
let f = new Float64Array(ab);
let ints = new Int32Array(ab);
let tally = newarr(64);
for(let i = 0; i < 100000; i++){
f[0] = Math.random();
for(let i = 31; i >= 0; i--){
tally[31-i] += ((ints[0]>>i)&1);
}
@martian17
martian17 / filter.js
Created October 27, 2022 02:15
国土交通省ダウンロードフィルタリング
let inputs = [...document.querySelectorAll("table.responsive-table td input.waves-button-input")];
let arr = `01000-15.0b.zip
01000-20.0a.zip
02000-15.0b.zip
02000-20.0a.zip
03000-15.0b.zip
03000-20.0a.zip
04000-15.0b.zip
04000-20.0a.zip
05000-15.0b.zip
const [chrome,navigator,window,document,$vars] = (()=>{
let vars = [];
let proxyMethodNames =
`apply
construct
defineProperty
deleteProperty
get
getOwnPropertyDescriptor
getPrototypeOf