Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block wjx

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
wjx / get_authors.js
Created Mar 24, 2017
Promise version answer to the EloquentJavascript Exercise 20.1
View get_authors.js
var http = require("http");
var Promise = require("promise");
function getAuthor(type) {
return new Promise(function(resolve, reject) {
var request = http.request({
hostname: "",
path: "/author",
method: "GET",
headers: {Accept: type}

#Create your own map with OpenStreetMap

This is some note of me playing with OpenStreetMap and creating an Android app that renders the map drawn.

##Draw a map

###Get GPS trace

If you want to draw your own map, OpenStreetMap

wjx /
Last active Jan 16, 2017
Array to BST
//is the better solution(return created node, instead of a separated
//insert operation).
//Note here int mid = (int)Math.floor(n / 2); is used to get the middle
//node instead of int mid = (start + end) / 2;, resulting right middle
//node is selected when there is even number of nodes in the array.
import java.util.*;
import java.lang.*;
wjx / Promise-all.js
Created Dec 18, 2016
Alternative solution for EloquentJavaScript exercise 17.2
View Promise-all.js
function all(promises) {
return new Promise(function(success, fail) {
// Your code here.
function promiseThen(i) {
return promises[i].then(function(res) {
//we should return the res here.
//push into results here won't work, since
//promises here settles at different time
//and elements in results will be out of order.
return res;
wjx / content-negotiation.js
Created Dec 12, 2016
Promise version of EloquentJavaScript Excercise 17.1
View content-negotiation.js
function requestAuthor(type) {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();"GET", "", true);
req.setRequestHeader("accept", type);
req.onload = function() {
if(req.status == 200) {
wjx / precomputed-mirroring.js
Last active Dec 5, 2016
Implementation for book EloquentJavaScript chapter16 exercise "Precomputed mirroring"
View precomputed-mirroring.js
var playerSprites = document.createElement("img");
var extraCanvas = document.createElement("canvas");
var extraCx = extraCanvas.getContext("2d");
playerSprites.src = "img/player.png";
playerSprites.addEventListener("load", function(event) {
var width = playerSprites.width;
var height = playerSprites.height;
extraCx.scale(-1, 1);
extraCx.translate(-width, 0);
wjx / mouse-trail.html
Created Nov 30, 2016
Implementing mouse trail using requestAnimationFrame for EloquentJavaScript Exercise 14.2
View mouse-trail.html
<!doctype html>
.trail { /* className for the trail elements */
position: absolute;
height: 6px; width: 6px;
border-radius: 3px;
background: teal;
body {
wjx / secril-client-sap.cpp
Last active Aug 29, 2015
View secril-client-sap.cpp
* Copyright (C) 2010 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
wjx / stdio.c
Last active Aug 29, 2015
View stdio.c
__sread(void *cookie, char *buf, int n)
FILE *fp = cookie;
int ret;
ret = TEMP_FAILURE_RETRY(read(fp->_file, buf, n));
/* if the read succeeded, update the current offset */
if (ret >= 0)
Copyright 2009, The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
You can’t perform that action at this time.