Skip to content

Instantly share code, notes, and snippets.

View sujinleeme's full-sized avatar
🏃‍♀️
�CPH marathon

Sujin Lee sujinleeme

🏃‍♀️
�CPH marathon
View GitHub Profile
import { useState, useEffect } from "react";
interface Dimensions {
width: number | null;
height: number | null;
}
export const useWindowDimensions = (): Dimensions => {
const hasWindow = typeof window !== "undefined";
@sujinleeme
sujinleeme / MockFile.js
Created February 14, 2021 12:56 — forked from josephhanson/MockFile.js
Mock file for JavaScript based file upload - with basic test harness
// mock file
function MockFile() { };
MockFile.prototype.create = function (name, size, mimeType) {
name = name || "mock.txt";
size = size || 1024;
mimeType = mimeType || 'plain/txt';
function range(count) {
var output = "";
@sujinleeme
sujinleeme / sample.json
Last active February 10, 2021 17:25
sample.json
{
"type":"object",
"require": true,
"patternProperties":{
"[A-Za-z:0-9]":{
"type":"object",
"additionalProperties":false,
"required":[
"time",
"timestamp",
@sujinleeme
sujinleeme / useRect.tsx
Last active March 21, 2024 15:27 — forked from morajabi/useRect.js
useRect — getBoundingClientRect() React Hook with resize handler (TypeScript)
// Require to install a package from npm with ResizeObserver typings.
// yarn --dev @types/resize-observer-browser
import { useCallback, useLayoutEffect, useRef, useState } from "react";
import ResizeObserver from 'resize-observer-polyfill'
type RectResult = {
bottom: number;
height: number;
left: number;
@sujinleeme
sujinleeme / react-testing-library--renderWithRedux.md
Created November 26, 2020 22:16 — forked from fleepgeek/react-testing-library--renderWithRedux.md
An Improvement to renderWithRedux helper function to enable rerender

Basic Implmentation

function renderWithRedux(ui, { initialState, store = createStore(rootReducer, initialState) } = {}, renderFn = render) {
  const obj = {
    ...renderFn(<Provider store={store}>{ui}</Provider>),
    store,
  };
  obj.rerenderWithRedux = (el) => renderWithRedux(el, { store }, obj.rerender);
  return obj;
import { RefObject, useEffect } from 'react';
const MOUSEDOWN = 'mousedown';
const TOUCHSTART = 'touchstart';
type HandledEvents = [typeof MOUSEDOWN, typeof TOUCHSTART];
interface UseOnClickOutsideProps {
innerRef: RefObject<HTMLElement>;
outerRef?: RefObject<HTMLElement> | { current: HTMLDocument };
const hiddenNumNeurons = 20
const hidden2NumNeurons = 5
const learningRate = 0.01
const num_iterations = 100
const batch_size = 20
const weights = tf.variable(tf.randomNormal([2, hiddenNumNeurons]))
const biases = tf.variable(tf.zeros([hiddenNumNeurons]))
const weights2 = tf.variable(tf.randomNormal([hiddenNumNeurons, hidden2NumNeurons]))
class Minesweeper {
constructor(cols, rows, mines) {
this.cols = cols
this.rows = rows
this.mines = mines
}
drawGrid() {
let grid = []
for (let i = 0; i < this.rows; i++) {
@sujinleeme
sujinleeme / README.md
Last active May 27, 2019 14:48
Find the nearest coordinate from a set of geographical coordinates using haversine

Find the nearest coordinate from a set of geographical coordinates using haversine

@sujinleeme
sujinleeme / README.md
Last active June 24, 2024 17:48
Get street Geojson using Openstreet's Nominaim API

Get Street Geojson using Openstreet's Nominaim API

  1. Update street names in all-streets.txt.
  2. Update your COUNTRY_CODE = 'sg' in geojson_generator.py.
  3. Run geojson_generator.py
  4. Check *.csv and geojson.json file.

Nominatim is a search engine for OpenStreetMap data. This is the debugging interface. You may search for a name or address (forward search) or look up data by its geographic coordinate (reverse search). Each result comes with a link to a details page where you can inspect what data about the object is saved in the database and investigate how the address of the object has been computed. To enhance understand of Nominatim, recommend to visit https://nominatim.openstreetmap.org/ and play for a while.