Skip to content

Instantly share code, notes, and snippets.

View billykwok's full-sized avatar
🎯
Focusing

Billy Kwok billykwok

🎯
Focusing
View GitHub Profile
@billykwok
billykwok / insertionSortRecursion.js
Created January 16, 2016 23:42
Recursive Version of Insertion Sort in ES6
function insertSortRec(array) {
if (array.length <= 1) {
return array;
} else {
const key = array.pop();
let subArray = insertSortRec(array);
let i = subArray.length - 1;
while (i >= 0 && subArray[i] > key) {
subArray[i + 1] = subArray[i];
--i;
@billykwok
billykwok / selectionSort.js
Created January 16, 2016 23:44
Selection Sort in ES6
function selectSort(array) {
for (let j = 0; j < array.length; ++j) {
let indexOfMin = j;
for (let i = j + 1; i < array.length; ++i) {
if (array[i] < array[indexOfMin]) indexOfMin = i;
}
[ array[j], array[indexOfMin] ] = [ array[indexOfMin], array[j] ];
}
return array;
}
@billykwok
billykwok / minMax.js
Created January 16, 2016 23:45
O(n) algorithm to find min and max
function minMax(array) {
if (array.length <= 1) {
return [ array[0], array[0] ];
} else if (array.length == 2) {
return array[0] < array[1] ? [ array[0], array[1] ] : [ array[1], array[0] ];
} else {
const breakpt = array.length / 2;
const [ minLeft, maxLeft ] = minMax(array.slice(0, Math.floor(breakpt)));
const [ minRight, maxRight ] = minMax(array.slice(Math.floor(breakpt)));
return [ minLeft < minRight ? minLeft : minRight,
#include "smallsh.h" /* include file for example */
#include <stdlib.h>
#include <signal.h>
/* program buffers and work pointers */
static char inpbuf[MAXBUF], tokbuf[2*MAXBUF], *ptr = inpbuf, *tok = tokbuf;
int intr_p = 0;
char *prompt = "Command>"; /* prompt */
int fg_pid = 0;
char decodeKey(unsigned long key, unsigned char times) {
switch (*key) {
case REMOTE_BTN_0: return ' ';
case REMOTE_BTN_1: return '1';
case REMOTE_BTN_2:
switch (times) {
case 2: return 'B';
case 3: return 'C';
case 2: return 'B';
case 3: return 'C';

Keybase proof

I hereby claim:

  • I am billykwok on github.
  • I am billykwok (https://keybase.io/billykwok) on keybase.
  • I have a public key ASBUqKMA-0HO7jfigtVIq4kvqTmuVwCMqqdzha_DOE2Wqgo

To claim this, I am signing this object:

@billykwok
billykwok / lab1.ino
Last active September 5, 2021 23:29
#define _TASK_MICRO_RES
#include <TaskScheduler.h>
#include <TaskSchedulerDeclarations.h>
#include <TaskSchedulerSleepMethods.h>
#define PWM_PERIOD 10000
#define SAMPLING_FREQUENCY 150
#define LED_BLUE LED_BUILTIN
#define LED_RED PIN_SPI_MISO
import SerialPort from 'serialport';
import Vibrant from 'node-vibrant';
import readline from 'readline';
import util from 'util';
(async () => {
const entries = await SerialPort.list();
const entry = entries.find(
(it) => it.manufacturer && it.manufacturer.includes('Arduino')
);
#define BAUD_RATE 9600
#define DELIMITER '\n'
#define SAMPLING_RATE 100
#define LED_RED 9
#define LED_GREEN 10
#define LED_BLUE 11
int t = 0;
int dt = 1;
import SerialPort from 'serialport';
import readline from 'readline';
(async () => {
const entries = await SerialPort.list();
const entry = entries.find(
(it) => it.manufacturer && it.manufacturer.includes('Arduino')
);
if (!entry) {
console.warn('No Arduino found');