Skip to content

Instantly share code, notes, and snippets.

@NWChen
NWChen / 99p.hs
Created May 11, 2020 21:46
99 haskell questions
-- 1
myLast :: [x] -> x
myLast [] = error "Empty list"
myLast [x] = x
myLast (_:xs) = myLast xs
-- 2
myLength :: [x] -> Int
myLength [] = 0
myLength (_:xs) = 1 + myLength xs
@NWChen
NWChen / doomsday.md
Created April 25, 2020 17:54
doomsday

Doomsday algorithm

(given a date, what day of the week is it?)

1. What is <year>'s doomsday?

doomsday is the last day of February. In leap years, doomsday = 2/28. In normal years, doomsday = 2/29 doomsday in 2020 is Saturday, 2/29.

Given doomsday we can compute any day of the week in February:

  • 2/15 = 2/29 - 2 weeks = Saturday
  • 2/23 = 2/29 - 1 week + 1 day = Sunday
@NWChen
NWChen / PR2_log.md
Last active April 30, 2019 18:08
PR2 log during `roslaunch /etc/ros/robot.launch`
@NWChen
NWChen / perceptron.py
Created December 30, 2018 03:55
Python Rosenblatt Perceptron
import matplotlib.pyplot as plt
import numpy as np
X = np.array([
[0.8, 0.4],
[0.3, 0.1],
[0.8, 0.8],
[0.4, 0.6],
[0.6, 0.8],
[0.4, 0.2],
No typos will be found - file '/home/nwchen/Desktop/senior/os/spelling.txt': No such file or directory
No structs that should be const will be found - file '/home/nwchen/Desktop/senior/os/const_structs.checkpatch': No such file or directory
WARNING: Missing or malformed SPDX-License-Identifier tag in line 1
#1: FILE: f18-hmwk2-team12/kernel/kernel/ptree.c:1:
+#include <linux/err.h>
ERROR: open brace '{' following function definitions go on the next line
#9: FILE: f18-hmwk2-team12/kernel/kernel/ptree.c:9:
+void writepr(struct task_struct *root, unsigned long idx,
+ struct prinfo *prarray) {
set nocompatible
filetype off
" vundle runtime path
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
" vundle plugins
Plugin 'severin-lemaignan/vim-minimap'

Exploratory analysis

Feature Unit
TIME s
T ATM C
T MUSCLE C
PWM Hz
FORCE N
import subprocess
import re
import time
import httplib2
import io
from apiclient.discovery import build
import os
import oauth2client
from oauth2client.file import Storage
from apiclient.http import MediaFileUpload, MediaIoBaseDownload
#!/bin/bash
echo "starting hw1-part2"
source ~/fetch_ws/devel/setup.bash
roslaunch fetch_gazebo playground.launch &
sleep 10s
source ~/fetch_ws/devel/setup.bash
roslaunch fetch_navigation fetch_nav.launch map_file:=EMPTY &
sleep 10s
source ~/fetch_ws/devel/setup.bash
import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
def showCam():
cam = cv2.VideoCapture(0)
while True:
ret_val, img = cam.read()