Skip to content

Instantly share code, notes, and snippets.

View zhxnlai's full-sized avatar

Zhixuan Lai zhxnlai

  • Square Inc
  • San Francisco, CA
View GitHub Profile
@zhxnlai
zhxnlai / playground.js
Created January 14, 2015 16:07
playground with local storage
function insertPlayground(lang, optSource) {
var fromString = (lang.fromString || fail('language object must have a fromString method')).bind(lang);
var evalAST = lang.evalAST ? lang.evalAST.bind(lang) : undefined;
var transAST = lang.transAST ? lang.transAST.bind(lang) : undefined;
if (!evalAST && !transAST) {
fail('language object must have either an evalAST or a transAST method');
}
var syntaxHighlight = lang.grammar.semanticAction({
number: function(_) {
@zhxnlai
zhxnlai / Extract code section from github
Created February 7, 2015 00:47
Extract code section from github
var file = document.querySelector(".file");
file.style.margin = 0
var body = document.createElement("body");
body.appendChild(file);
document.body = body;
@zhxnlai
zhxnlai / zhxnlai.md
Last active August 29, 2015 14:19
One Pager

Zhixuan's One Pager

Hi, my name is Zhixuan Lai. I am a undergraduate student at UCLA interested in client side application and programming language.

I have played with many client side technologies:

Games

Last spring, I spent a lot of time on learning Unity3d game engine. It enabled me to make mobile multiplayer games using AR and VR technologies (e.g. Vuforia and Oculus Rift), two of which (Horoscoper and Spacinarium) won me hackathon prices.

@zhxnlai
zhxnlai / vc.sh
Created April 21, 2015 21:25
Video Conversion
# To pngs 1 frame per second
# https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
mkdir frames && ffmpeg -i video.mov -vf fps=1 frames/ffout%03d.png
# screen recording to gif
mkdir bufferFrames && ffmpeg -i video.mov -vf scale=320:-1 -r 30 bufferFrames/ffout%03d.png && convert -delay 4.167 -loop 0 bufferFrames/ffout*.png ZLHistogramAudioPlotBuffer.gif
@zhxnlai
zhxnlai / project5
Created May 17, 2015 00:05
Project 5
// stores an array of images (PImage[]) for each scene
ArrayList<PImage[]> scenes;
// keeps track of the index of the current scene
int sceneIndex = 0;
// used to animate the images of the current scene
int frameIndex = 0;
// keep track of the last mouse position
float clickedX;
float clickedY;
@zhxnlai
zhxnlai / final.md
Last active August 29, 2015 14:22
115A notes

Math 115A

Chapter 1

1.2-1.6

Definitions

  • Definition of a vector space

@zhxnlai
zhxnlai / index.js
Last active December 4, 2015 01:12
A script that stimulates mouse events to remove all of your photos on Google Photos. (copy and paste to the console at https://photos.google.com/)
function click(el) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
function click2(el) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("mousedown", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
@zhxnlai
zhxnlai / Problem 1.js
Last active January 25, 2016 17:12
Vegenere cipher
function getCharCodes(s) {
return s.toUpperCase().split("").map(c => c.charCodeAt(0))
}
function zip(a, b) {
return a.map((char,i) => [char, b[i % b.length]]);
}
function decrypt(ciphertext, key) {
const plaintextCharCode = zip(getCharCodes(ciphertext), getCharCodes(key)).map(pair => (pair[0] - pair[1] + 26) % 26 + "A".charCodeAt(0))
@zhxnlai
zhxnlai / dispatch_async.swift
Last active June 15, 2016 08:19
Async programming in swift
// get a global concurrent queue
let queue = dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0)
// submit a task to the queue for background execution
dispatch_async(queue) {
let enhancedImage = self.applyImageFilter(image) // expensive operation taking a few seconds
// update UI on the main queue
dispatch_async(dispatch_get_main_queue()) {
self.imageView.image = enhancedImage
UIView.animateWithDuration(0.3, animations: {
self.imageView.alpha = 1
@zhxnlai
zhxnlai / PromiseKit.swift
Created June 15, 2016 07:47
Async programming in swift 2
dispatch_promise {
return self.applyImageFilter(image)
}.then { enhancedImage in
self.imageView.image = enhancedImage
return UIView.animateWithDurationPromise(0.3) {
self.label.alpha = 1
}
}.then {
// add code to happen next here
}