Skip to content

Instantly share code, notes, and snippets.

View up209d's full-sized avatar

Duc Duong up209d

View GitHub Profile
@up209d
up209d / require.hack.origin.js
Last active March 15, 2018 23:08
Nodejs Require Hacking
let Module = require('module');
let _require = Module.prototype.require;
Module.prototype.require = function() {
let currentPath = arguments[0];
try {
return _require.apply(this,arguments);
} catch (err) {
// Any errors from importing such as
// (not a js module, path cannot be resolved, unsupported extensions)
return currentPath; // fallback to return as a pure string
@up209d
up209d / leaflet.centerWithOffset.js
Last active November 29, 2017 07:02
Leaflet Hack for Center Point with Offset X/Y (Top/Left)
// Change the center of map with offset value,
// useful for some cases such as
// a Menu/Sidebar sit on top of the map
// a Footer sit on top of the map
// This hack covers zoom/pan and tileLoading working correctly to the new center (with offset) point
(function(global){
global.Map.prototype._getNewPixelOrigin = function (center, zoom) {
@up209d
up209d / leaflet.forceZIndex.js
Last active September 13, 2023 09:31
Force zIndex of Leaflet Marker
// Force zIndex of Leaflet
(function(global){
var MarkerMixin = {
_updateZIndex: function (offset) {
this._icon.style.zIndex = this.options.forceZIndex ? (this.options.forceZIndex + (this.options.zIndexOffset || 0)) : (this._zIndex + offset);
},
setForceZIndex: function(forceZIndex) {
this.options.forceZIndex = forceZIndex ? forceZIndex : null;
}
};
@up209d
up209d / .htaccess
Created November 28, 2017 07:26
Single Page Application .htaccess (gzip and fallback)
AddEncoding gzip .gz
RewriteEngine on
#For all request has header contents Accept-encoding: gzip
RewriteCond %{HTTP:Accept-encoding} gzip
#For all browser except Konqueror
RewriteCond %{HTTP_USER_AGENT} !Konqueror
@up209d
up209d / require.hack.js
Created March 15, 2018 23:08
Require Hack which get stats from webpack to render assets paths
// Require Hack which get stats from webpack to render assets paths
let Module = require('module');
let _require = Module.prototype.require;
Module.prototype.require = function() {
let currentPath = arguments[0];
// let currentFilename = currentPath.substring(currentPath.lastIndexOf('/')+1,currentPath.length);
// let currentFileext = currentPath.substring(currentPath.lastIndexOf('.')+1,currentPath.length);
// console.log(currentFilename,currentFileext,currentFileext.length);
try {
return _require.call(this,arguments[0]);
@up209d
up209d / WithStyleAndProps.js
Created March 23, 2018 00:41
Use props with withStyle in JSS
import React from 'react';
import {
withStyles,
Grid,
CircularProgress
} from 'material-ui';
// const PreloadComponent = props => {
// const { classes,size } = props;
// return (
@up209d
up209d / SSL Forced Forwarding
Created May 2, 2018 05:46
NGINX Routing Config
server {
listen 80;
server_name example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/server.crt;
@up209d
up209d / gist:1c5f6e53f13ce4bd27d6a4f9c37e3e9b
Created May 18, 2018 04:55
GLSL Avoid Divide By Zero (Return 0 instead)
float avoidDivideByZero (float value) {
float signValue = sign(value);
return (1. * abs(sign(value))) / (value + (abs(sign(value)) - 1.));
}
git push origin `git subtree split --prefix dist master`:gh-pages --force
@up209d
up209d / push.sh
Last active June 1, 2018 09:42
Force to push 'dist ' folder from local branch 'origin' to remote branch 'gh-pages'
git push origin `git subtree split --prefix dist master`:gh-pages --force