Skip to content

Instantly share code, notes, and snippets.

View okmttdhr's full-sized avatar
🥕
Is this organic?

okmttdhr, tada okmttdhr

🥕
Is this organic?
View GitHub Profile
@okmttdhr
okmttdhr / PriorityQueue.ts
Last active March 9, 2022 00:50
PriorityQueue in TypeScript
const root = 0;
const parentIndex = i => Math.floor((i - 1) / 2);
const leftIndex = i => 2 * i + 1;
const rightIndex = i => leftIndex(i) + 1;
// With Bitwise Operations;
// const parentIndex = i => ((i + 1) >>> 1) - 1;
// const leftIndex = i => (i << 1) + 1;
// const rightIndex = i => (i + 1) << 1;
@okmttdhr
okmttdhr / libuv event loop source code.c
Last active July 22, 2021 05:26
libuv event loop source code
// https://github.com/okmttdhr/libuv/blob/8ea8f124386486af2380127c6885848f9d502a36/src/unix/epoll.c#L208-L420
for (;;) {
/* Only need to set the provider_entry_time if timeout != 0. The function
* will return early if the loop isn't configured with UV_METRICS_IDLE_TIME.
*/
if (timeout != 0)
uv__metrics_set_provider_entry_time(loop);
/* See the comment for max_safe_timeout for an explanation of why
* this is necessary. Executive summary: kernel bug workaround.
@okmttdhr
okmttdhr / gRPCClientContext.tsx
Created March 13, 2020 07:23
gRPC request client as React.Context
import React from "react";
import { MessengerClient } from "./messenger/MessengerServiceClientPb";
interface GRPCClientContextValue {
messengerClient?: MessengerClient;
}
const defaultContextValue = {
messengerClient: new MessengerClient(`http://localhost:8080`)
};
@okmttdhr
okmttdhr / heap-sort.hs
Created February 23, 2020 00:38
haskell heap sort
data Tree a = Empty | Node !a !(Tree a) !(Tree a)
makeTree :: [a] -> Tree a
makeTree xs = fst $ makeTree' (length xs) xs
makeTree' :: Int -> [a] -> (Tree a, [a])
makeTree' 0 xs = (Empty, xs)
makeTree' n (x:xs) = (Node x l r, zs)
where
m = n `div` 2
(l, ys) = makeTree' m xs
@okmttdhr
okmttdhr / retry.ts
Created February 4, 2020 06:39
Retry promise with incremental backoff in TypeScript
export const retry = (fn: () => Promise<any>, timeout = 1000, retries = 5) =>
new Promise((resolve, reject) => {
fn()
.then(resolve)
.catch(() => {
setTimeout(() => {
const retriesLeft = retries - 1;
if (retries < 0) {
return reject('maximum retries exceeded');
}
@okmttdhr
okmttdhr / gps.md
Last active April 30, 2019 07:24
How GPS works
  • W3C Geolocation API - Wikipedia
    • The most common sources of location information are IP address, Wi-Fi and Bluetooth MAC address, radio-frequency identification (RFID), Wi-Fi connection location, or device Global Positioning System (GPS) and GSM/CDMA cell IDs.
  • Location information server - Wikipedia
  • Global Positioning System - Wikipedia
    • The GPS concept is based on time and the known position of GPS specialized satellites.
    • The satellites carry very stable atomic clocks that are synchronized with one another and with the ground clocks.
    • Each GPS satellite continuously transmits a radio signal containing the current time and data about its position.
  • GPS navigation device - Wikipedia
  • A GPS navigation device, GPS receiver, or simply GPS is a de
@okmttdhr
okmttdhr / システム時刻について.md
Last active April 15, 2019 08:05
システム時刻について
  • 時刻系(じこくけい)とは時間が経過する歩度、もしくは時刻、またはその両方の基準である。
  • UTCやGMTなども厳密には定義が異なる。
  • その中でも国際原子時(TAI)はUTCを含む他の時刻基準の計算の基となる基礎的な国際時刻基準である。
  • TAIは国際度量衡局(BIPM)によって維持されており、環境的・相対論的効果を補正された世界中の数多くの原子時計の入力を合成して作られている。
@okmttdhr
okmttdhr / criminal_jc.md
Created February 21, 2019 15:17 — forked from shunirr/criminal_jc.md
女子中学生チケット詐欺事件

criminal_jc

@okmttdhr
okmttdhr / md.md
Created November 12, 2018 08:57
Disable uglify with nuxt.config.js