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
@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) {
@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();
});
// 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 / transferring-money.feature
Created July 6, 2015 02:52
Example scenario using in BDD
Scenario: Transferring money from current account to saving account
Given I have a current accout with 1000
And I have a saving account with 2000
When I transfer 500 from my current account to my savings account
Then I should have 500 in my current account
And I should have 2500 in my saving account
@vuongtran
vuongtran / uuid.js
Created July 26, 2015 23:26
Create UUID
// Code based on RFC 4122, section 4.4 (Algorithms for Creating a UUID from Truly Random or Pseudo-Random Number).
// http://www.ietf.org/rfc/rfc4122.txt
function createUUID() {
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
@vuongtran
vuongtran / boom-get-request.js
Last active September 9, 2015 03:32
boom-get-request
// $.get(url)
// .done(function(response) {
// if (response.status === 'success') {
// // draw chart line now
// //fnDrawChartPieAndBar(option);
// } else {
// console.log(response.message);
// }
// }).fail(function(error) {
// console.log(error);
@vuongtran
vuongtran / nodejs .gitignore sample
Created June 6, 2017 05:22
Just a nodejs .gitignore sample to get start
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Runtime data
pids
*.pid
@vuongtran
vuongtran / repos_awesome.txt
Last active December 15, 2017 03:26
JavaScript Nodejs React Redux... repos awesome to use
The one-liner node.js http-proxy middleware for connect, express and browser-sync
https://github.com/chimurai/http-proxy-middleware
@vuongtran
vuongtran / react-handle-event-resize
Created May 14, 2018 16:01
React handle event window resize
import React, { Component } from 'react';
export default class RenderProducts extends Component {
constructor(props) {
super(props);
this.state = {
innerWidth: window.innerWidth,
}
this.handleResize = this.handelResize.bind(this);
}
handleResize(){
@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/