Skip to content

Instantly share code, notes, and snippets.

View vuongtran's full-sized avatar
🎯
Focusing

Vuong vuongtran

🎯
Focusing
  • Ho Chi Minh City, Vietnam
View GitHub Profile
// Constructor
function Foo(bar) {
// always initialize all instance properties
this.bar = bar;
this.baz = 'baz'; // default value
}
// class methods
Foo.prototype.fooBar = function() {
};
@vuongtran
vuongtran / RESTful API sample structure using Node.js, Express.js included tesing
Last active December 4, 2019 15:44
RESTful API sample structure using Node.js, Express.js included tesing
Let's lool at the following example structure for RESTful API using Node.js, Express.js included tesing
app/
|---models/
|---controller/
|---helpers/
|---middlewares/
|---tests/
|---models/
|---controllers/
@vuongtran
vuongtran / Middleware to allow cross-domain access in express.js
Created April 22, 2015 03:35
Config middleware to allow cross-domain access in express.js
var express = require('express'),
app = express();
app.use( function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
next();
});
@vuongtran
vuongtran / Delay scroll to fix issue scroll event handlers
Created January 27, 2015 14:21
Directly attaching a handler to the scroll event is considered bad practice because (depending on the browser) this event can fire many times within a few milliseconds. A solution below will be deal with this issue.
var scrollticker;
jQuery(window).scroll(function() {
if (scrollticker) {
window.clearTimeout(scrollticker);
scrollticker = null;
}
// Set Timeout
scrollticker = window.setTimeout(function() {
if (jQuery('#div-fetching').length) {
if (jQuery(window).scrollTop() >= jQuery('#div-fetching').offset().top + jQuery('#div-fetching').outerHeight() - window.innerHeight) {