Skip to content

Instantly share code, notes, and snippets.

View cheton's full-sized avatar
🎯

Cheton Wu cheton

🎯
View GitHub Profile
@cheton
cheton / distributed-mediasoup.js
Created August 5, 2022 04:34 — forked from gurupras/distributed-mediasoup.js
mediasoup horizontal scaling
onServerStartup () {
const { serverId, ip } = getServerInfo() // serverId does not change across restarts
this.serverId = serverId
// We don't have any routers or producers (yet). Clear any value that exists in the DB related to our serverId
clearSharedDB(serverId, 'routers')
clearSharedDB(serverId, 'producers')
// Update the DB with our serverId and ip so that others will know how to reach us
registerServerInDB(serverId, ip)
@cheton
cheton / machine.js
Created May 21, 2020 14:58
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: 'fetchMachine',
initial: 'idle',
context: {
isFetchedOnce: false,
isFetching: false,
data: null,
error: null,
},
states: {
@cheton
cheton / init.vim
Created February 5, 2020 09:39
Neovim
" Convert new tabs to spaces
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
" No end of line
set noeol
call plug#begin()
@cheton
cheton / theme-preset.js
Last active December 27, 2019 10:42
(Draft) Trend Micro Frontend Theme
const breakpoints = [
'320px',
'640px',
'1024px',
'1280px',
'1680px',
];
// @media screen and (min-width: 320px)
// @media screen and (min-width: 640px)
// @media screen and (min-width: 1024px)
@cheton
cheton / Carousel.jsx
Created November 21, 2018 13:24
Carousel
@cheton
cheton / Parallelogram.jsx
Last active November 21, 2018 13:23
Parallelogram
import React from 'react';
import styled, { css } from 'styled-components';
const Component = styled.div`${({
width,
height,
before,
beforeBorderMask,
beforeBorderColor,
beforeBackgroundColor,
@cheton
cheton / expose-cards-timeout.js
Last active August 3, 2018 16:56
Expose Cards w/ Timeout
require('babel-core/register');
require('babel-polyfill');
const timeout = (ms) => new Promise((resolve, reject) => {
setTimeout(() => reject(new Error(`Timeout exceeded: ${ms}ms`)), ms);
});
class Player {}
class AsyncAction {
# GRBL Source (The standard GRBL firmware is identaical to the Inventables GRBL, just some minor config changes.)
https://github.com/gnea/grbl
Compiled with settings:
[Changes to (config.h)]
#define DEFAULTS_X_CARVE_1000MM
#define HOMING_FORCE_SET_ORIGIN // Enabled
#define ENABLE_M7 // Enabled
#define ENABLE_SAFETY_DOOR_INPUT_PIN // Enabled
@cheton
cheton / particulate-matter.js
Last active July 3, 2018 16:17
A Particulate Matter Detector Using PM 2.5 Sensor by PLANTOWER
//
// http://aqicn.org/air/view/sensor/spec/pms7003.pdf
//
const SerialPort = require('serialport');
const port = new SerialPort('/dev/ttyUSB0', {
baudRate: 9600
});
@cheton
cheton / find-raspberry.sh
Created July 3, 2018 06:26 — forked from niun/find-raspberry.sh
Find Raspberry Pi in network (looking for MAC address vendor prefix of Raspberry Pi Foundation using nmap, awk for ipv4 / ping6, ip, grep for ipv6 neighbour discovery)
sudo nmap -sP 192.168.0.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'