Skip to content

Instantly share code, notes, and snippets.

View neewbee's full-sized avatar
🎯
Focusing

neewbee neewbee

🎯
Focusing
View GitHub Profile
@neewbee
neewbee / nginxproxy.md
Created September 1, 2017 07:24 — forked from soheilhy/nginxproxy.md
How to proxy web apps using nginx?

Virtual Hosts on nginx (CSC309)

When hosting our web applications, we often have one public IP address (i.e., an IP address visible to the outside world) using which we want to host multiple web apps. For example, one may wants to host three different web apps respectively for example1.com, example2.com, and example1.com/images on the same machine using a single IP address.

How can we do that? Well, the good news is Internet browsers

@neewbee
neewbee / uuid-generator.js
Last active August 7, 2017 01:02
uuid generator
function uuidGenerator() {
var S4 = function() {
return (((1 + Math.random()) * 0x10000) | 0)
.toString(16)
.substring(1);
};
return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
*pollData({ userId = 1 }, { call, put }) {
function delay(millis) {
const promise = new Promise(resolve => {
setTimeout(() => resolve(true), millis);
});
return promise;
}
try {
yield call(delay, 2000);
yield put({ type: "fetch", payload: { page: 1 } });
function ChildComonent({ onClick, item }) {
return <li onClick={onClick}>{item}</li>;
}
export default class Demo extends Component {
constructor(props) {
super(props)
this.test3 = this.test3.bind(this)
this.test6 = () => {
console.log(this.state.id)
function interval(fn, delay) {
console.log("start interval");
setInterval(fn, delay);
}
async function timeout(fn, delay) {
console.log("start timeout");
(async function _() {
console.log("in timeout")
// mimic long running code
@neewbee
neewbee / timeout for fetch API
Created July 13, 2017 13:27
It seem that fetch has a long way to go
var p = Promise.race([
fetch('/resource-that-may-take-a-while'),
new Promise(function (resolve, reject) {
setTimeout(() => reject(new Error('request timeout')), 5000)
})
])
p.then(response => console.log(response))
p.catch(error => console.log(error))
@neewbee
neewbee / random.js
Created July 12, 2017 07:29 — forked from kerimdzhanov/random.js
Javascript get random number in a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {float} a random floating point number
*/
function getRandom(min, max) {
return Math.random() * (max - min) + min;
}

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})