Skip to content

Instantly share code, notes, and snippets.

View zhenyanghua's full-sized avatar
🐢
I may be slow to respond.

Zhenyang Hua zhenyanghua

🐢
I may be slow to respond.
View GitHub Profile
@zhenyanghua
zhenyanghua / Dockerfile.jdk
Last active January 9, 2018 14:15
Dockerfiles
RUN apt-get -y install debconf-utils
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN apt-get -y install oracle-java8-installer
@zhenyanghua
zhenyanghua / README.md
Last active June 14, 2017 15:41
Git Cheat Sheet

pull the latest of the current branch

git pull

add all local changes to the stage and commit the staged local changes.

git commit –am “comments”

stash the local changes

@zhenyanghua
zhenyanghua / GeoMock.ts
Created March 3, 2017 19:04
GeoMock plus
export class GeoMock {
constructor() {
if (typeof navigator === "undefined" || navigator === null) {
window.navigator = {};
}
if (navigator.geolocation == null) {
window.navigator.geolocation = {};
}
navigator.geolocation.delay = 1000;
navigator.geolocation.shouldFail = true;
@zhenyanghua
zhenyanghua / index.html
Last active February 16, 2017 19:48
ES6 Naive Data Binding
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Test</title>
<link rel="stylesheet" href="">
<style>
body { background-color: rice; }
ul {
@zhenyanghua
zhenyanghua / coinsSums.js
Last active January 27, 2017 02:32
Games
/**
* Given an array of coins type, and an array of quatity for each type,
* find out the possible sums.
*/
function Set() {
this.set = {};
}
Set.prototype.add = function(value) {
if (!this.set[value]) this.set[value] = true;
}
@zhenyanghua
zhenyanghua / transpose.js
Created January 13, 2017 22:25
Algorithms
/**
* Question - Given an image represented by an N x N matrix, where
* each pixel in the image is 4 bytes, write a method to rotate the
* image by 90 degress. Can you do this in place?
*
* rotateCopy() method is a brute force method to transpose one item
* at a time and return a new array. It is very slow. The time
* complexity is O(N^2), and it take as N^2 * [0-2^32) bits of memory.
*
* rotate() method performs a cyclic swap on the edges on each layer.
@zhenyanghua
zhenyanghua / DataStructure.md
Last active January 31, 2017 16:18
Data Structure in JavaScript

Data Structures with JavaScript

This is a list of implementation and usage of popular data structure with JavaScript.

Currently include:

  • Queue
    • Priority Queue
    • Circular Queue
  • linked List
@zhenyanghua
zhenyanghua / Customer.js
Created October 4, 2016 19:04
Loopback query role by user Id
var _ = require('underscore');
module.exports = function(Customer) {
Customer.getRolesById = function (id, cb) {
Customer.getApp(function (err, app) {
if (err) throw err;
var RoleMapping = app.models.RoleMapping;
var Role = app.models.Role;
RoleMapping.find({ where : { principalId: id }}, function (err, roleMappings) {
var roleIds = _.uniq(roleMappings
@zhenyanghua
zhenyanghua / main.js
Last active September 19, 2016 12:36
ArcGIS Online login flow through JS 3.x
require([
'app/config',
'dojo/ready',
'dojo/on',
'dojo/dom',
'esri/arcgis/OAuthInfo',
'esri/IdentityManager'],
function(
config,
ready,