Skip to content

Instantly share code, notes, and snippets.

View huy-tran's full-sized avatar

huy-tran huy-tran

View GitHub Profile
@huy-tran
huy-tran / vuejs_auth.js
Created October 2, 2017 12:59
VueJS Auth Enquiry
// bootstrap.js
axios.interceptors.response.use(
response => {
/**
* If the response contains authorization header,
* Then we assume that it is from the renew token request.
* Set the new JWT token.
*/
const authHeader = response.headers.authorization;
if (authHeader) jwt.setToken(authHeader.substr(7));
@huy-tran
huy-tran / back-to-top.js
Created March 24, 2016 04:49
Back To Top Button
// Back To Top button
var offset = 500;
var offsetOpacity = 1500;
var scrollDuration = 700;
var $backToTop = $('.gh-top');
$(window).scroll(function () {
if ($(this).scrollTop() > offset) {
$backToTop.addClass('gh-top-visible');
} else {
@huy-tran
huy-tran / toggle-selection.js
Created March 24, 2016 04:39
jQuery Toggle Selection
var $formChoice = $('.gh-form-choice');
$('#typesOfStudy').on('change', function () {
var value = $(this).val();
if (value !== '') {
var formToShown = '.gh-form-' + value;
$formChoice.not(formToShown).slideUp(400, function () {
$(formToShown).slideDown();
});
} else {
$formChoice.slideUp();
@huy-tran
huy-tran / object_literal_look_up.js
Created February 13, 2016 22:35
Using Object Literal look up instead of Switch
function getHobbyOf(name) {
var hobby = {
'Huy': 'Guitar',
'Tram': 'Photography',
'default': 'Out of survey'
};
return hobby[name] || hobby['default'];
}
getHobbyOf('Huy'); // log 'Guitar'
@huy-tran
huy-tran / basic_switch.js
Created February 13, 2016 22:21
basic switch syntax
function getHobbyOf(name) {
var hobby;
switch (name) {
case 'Huy':
hobby = 'Guitar';
break;
case 'Tram':
hobby = 'Photography';
break;
default: