Getting started:
Related tutorials:
function requireAll(requireContext) { | |
var result = {} | |
requireContext.keys().forEach(path => { | |
var name = path.replace(/^.*(\\|\/|\:)/, '').split('.')[0] | |
result[name] = requireContext(path) | |
}) | |
return result | |
} | |
var modules = requireAll(require.context("./api", false, /^\.\/.*\.js$/)) |
Getting started:
Related tutorials:
// takes a {} object and returns a FormData object | |
var objectToFormData = function(obj, form, namespace) { | |
var fd = form || new FormData(); | |
var formKey; | |
for(var property in obj) { | |
if(obj.hasOwnProperty(property)) { | |
if(namespace) { |
create different ssh key according the article Mac Set-Up Git
$ ssh-keygen -t rsa -C "[email protected]"
When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:
const Article = require('../../../../app/models/article');
Those suck for maintenance and they're ugly.
/** | |
* test if the target is an object(array included) | |
*/ | |
export function isObject(obj: any): boolean { | |
return obj !== null && typeof obj === 'object'; | |
} | |
/** simple deep equal */ | |
export function isEqual(a: any, b: any): boolean { | |
if (isObject(a) && isObject(b)) { |
I've figured out several things while trying to extend my knowledge of Computer Graphics.
And that's what this is, a travel guide.
const exec = require('child_process').execSync; | |
const path = require('path'); | |
module.exports = ({registry, pkgName, pkgVersion, cwd = process.cwd()}) => { | |
const url = `${registry}/${pkgName}/download/${pkgName}-${pkgVersion}.tgz`; | |
exec(`echo ${url} | xargs curl | tar -xz`, { | |
cwd, | |
}); | |
return path.join(cwd, 'package'); | |
} |
import customModuleLoader = require('module'); | |
export class CustomModuleLoader { | |
public cOptions: any = require('../tsconfig.json').compilerOptions; | |
public replacePaths: any = {}; | |
constructor() { | |
Object.keys(this.cOptions.paths).forEach(alias => { | |
this.replacePaths[alias.replace(/\*.?/, '(.*)')] = this.cOptions.paths[alias][0].replace(/\*.?/, '$1'); |
const {app, BrowserWindow} = require('electron') | |
const path = require('path') | |
const url = require('url') | |
let window = null | |
// Wait until the app is ready | |
app.once('ready', () => { | |
// Create a new window | |
window = new BrowserWindow({ |