Skip to content

Instantly share code, notes, and snippets.

View cheeaun's full-sized avatar
📬
Subscribe to my newsletter https://cheeaun.substack.com/

Chee Aun cheeaun

📬
Subscribe to my newsletter https://cheeaun.substack.com/
View GitHub Profile
We can't make this file beautiful and searchable because it's too large.
name,content,lng,lat
yy,Happy birthday Singapore!! Thank you Moments of Life team for creating this!,103.762,1.354
wj,Happy Birthday Singapore!,103.8,1.274
Cindy Lim Qiu Xia,Happy birthday to Singapore .,103.885,1.326
GJ,Happy Birthday Singapore!,103.873,1.368
Alexa,"Thanks for being there for my yesterdays, for growing with me into my today, and for giving me hope towards my tomorrow. Happy 55th and to more glorious years ahead! 😍 🇸🇬",103.806,1.443
GJ,Happy Birthday Singapore!!,103.873,1.368
Tanglin Boy,I love Singapore from the bottom of my heart! Happy National Day!,103.79851,1.2992
Tom,HBD Singapore!,103.80249,1.27221
z,"Happy Birthday, Singapore!",103.93579,1.36536
@cheeaun
cheeaun / median.js
Created June 14, 2020 07:11
Find median from array of numbers (mutable, due to .sort())
function median(numbers) {
const middle = (numbers.length + 1) / 2;
const sorted = numbers.sort((a, b) => a - b);
const isEven = sorted.length % 2 === 0;
return isEven
? (sorted[middle - 1.5] + sorted[middle - 0.5]) / 2
: sorted[middle - 1];
}
@cheeaun
cheeaun / p-timeout.js
Created April 25, 2020 12:59
promisified setTimeout
const pTimeout = (t) =>
new Promise((res, rej) => {
setTimeout(res, t);
});
@cheeaun
cheeaun / ImperativeText.js
Created April 24, 2020 13:46
React Native's Text component, but imperative instead for setting the text value
import React, { forwardRef, useState, useImperativeHandle } from 'react';
import { Text } from 'react-native';
export default forwardRef((props, ref) => {
const [text, setText] = useState('');
useImperativeHandle(ref, () => ({
setText: t => {
if (t) setText(t);
},
}));
@cheeaun
cheeaun / resize-nearest-neighbour.js
Created March 21, 2020 12:12
Resize (2D but flat) array of values with nearest neighbour algorithm
const width = 300;
const height = 200;
const newWidth = width * 2;
const newHeight = height * 2;
const xRatio = width / newWidth;
const yRatio = height / newHeight;
const resizeValues = (id, values) => {
const newValues = new Array(newWidth * newHeight);
for (let i = 0; i < newHeight; i++) {
for (let j = 0; j < newWidth; j++) {
@cheeaun
cheeaun / durian.geojson
Last active May 1, 2019 14:08
Durio species GeoJSON, extracted from https://github.com/cheeaun/exploretrees-sg dataset
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cheeaun
cheeaun / singapore-boundary.geojson
Created February 12, 2019 15:22
Singapore land boundary GeoJSON (hi-res)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cheeaun
cheeaun / checkweathersg.sh
Last active November 18, 2018 15:22
One-liner command to grab rain radar snapshot in ASCII format from https://checkweather.sg
node -e "require('https').get('https://api.checkweather.sg/now?ascii=1', res => res.on('data', d => process.stdout.write(d + '\n\n')))"
@cheeaun
cheeaun / .block
Last active January 28, 2018 11:02
Film Flowers, Full Starter Code
license: gpl-3.0