Skip to content

Instantly share code, notes, and snippets.

View kevinzhang96's full-sized avatar

Kevin Zhang kevinzhang96

View GitHub Profile
@kevinzhang96
kevinzhang96 / logging.js
Created July 15, 2016 21:21
A simple node module that makes console.log/error/warn/debug statements log through winston (simply include at the beginning of your app)
'use strict';
var util = require('util'),
winston = require('winston'),
logger = new winston.Logger(),
production = (process.env.NODE_ENV || '').toLowerCase() === 'production';
module.exports = {
middleware: function(req, res, next){
console.info(req.method, req.url, res.statusCode);
@kevinzhang96
kevinzhang96 / tooltip.js
Created February 23, 2016 02:12
Tooltip in D3
function addTooltip(svg, popHeight, popWidth, popx, popy, data) {
// Define the line
var valueline = d3.svg.line()
.x(function(d) { return popx(d.date); })
.y(function(d) { return 0; });
var lineSvg = svg.append("g");
var focus = svg.append("g")
.style("display", "none");
lineSvg.append("path")
.attr("class", "line")
@kevinzhang96
kevinzhang96 / upsert.js
Created January 4, 2016 01:05
Upsert Parse Cloud
// Takes 3 parameters:
// class: the object type to update; a single String.
// restrictions: the set of column restrictions; a Dictionary.
// updates: the set of column updates; a Dictionary.
Parse.Cloud.define("upsert", function(request, response) {
var query = new Parse.Query(request.params.class);
var restrictions = JSON.parse(request.params.restrictions);
for (var key in restrictions) {
@kevinzhang96
kevinzhang96 / MIPS_MULTICYCLE_VN.v
Last active January 6, 2025 14:55
multicycle mips processor verilog implementation
`include "alu_defines.v"
`include "mips_defines.v"
`include "mips_multicycle_defines.v"
`include "mips_memory_space_defines.v"
//`define VERBOSE
`default_nettype none
`timescale 1ns/1ps
/*
a version of the mips multicycle module with von Nuemann architecture
*/
@kevinzhang96
kevinzhang96 / nav.sh
Created November 9, 2015 16:14
A short shell script to make switching between folders in a directory easier.
# repository navigation shortcut
nav(){
# list all directories in ~/Repositories
DIRS=`ls -l ~/Repositories | egrep '^d' | awk '{print $9}'`
# and now loop through the directories:
for DIR in $DIRS
do
if [[ $DIR = $1* ]]
then
@kevinzhang96
kevinzhang96 / main.js
Created November 8, 2015 11:59
Script for parsing BPM
var audioobj = document.getElementsByTagName("audio")[0];
// var text = document.getElementById("text");
var actualBPM;
var request = new XMLHttpRequest();
console.log("Audio source: " + audioobj.src);
request.open('GET', audioobj.src, true);
request.responseType = 'arraybuffer';
var targetspd = 1;
request.onload = function() {
@kevinzhang96
kevinzhang96 / app.js
Created November 8, 2015 11:55
Node.js app file for YHack15, party-mode app
var express = require('express');
var app = express(); var app = express();
+var http = require('http').Server(app);
+var io = require('socket.io')(http);
app.use(express.static(__dirname + '/public')); app.use(express.static(__dirname + '/public'));
app.listen(process.env.PORT || 3000); app.listen(process.env.PORT || 3000);
+http.listen(3001, function(){
@kevinzhang96
kevinzhang96 / (pseudo)code.txt
Created November 7, 2015 23:52
Approximate stop frequency of movement using strided averages
keep track of up to last 3 stops
each time we stop, take average of last 3 times of stops; invert and that’s the BPM
double x[NUMBER];
double y[NUMBER];
long times[NUMBER];
long last[3] = {0};
double last_dist = UDOUBLE_MAX;
int curr_last = 0;
@kevinzhang96
kevinzhang96 / syscall.txt
Created November 6, 2015 09:31
Shell redirection system calls
echo foo > output.txt
open("output.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
echo foo < output.txt
open("output.txt", O_RDONLY|O_LARGEFILE) = 3
echo foo 2> output.txt
open("output.txt", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 3
@kevinzhang96
kevinzhang96 / codes.py
Created November 3, 2015 09:27
MIPS Assembler OP/FUNC codes and register encodings
rtypes = [
# List of all R-type instructions.
"sll", "srl", "sra", "sllv", "srlv", "srav", # shifts
"jr", "jalr", # jumps
"syscall", "break", # system
"mfhi", "mthi", "mflo", "mtlo", # move to
"mult", "multu", "div", "divu", # mult/div
"add", "addu", "sub", "subu", # add/sub
"and", "or", "xor", "nor", # bitwise
"slt", "sltu" # set less than