Skip to content

Instantly share code, notes, and snippets.

View aprilandjan's full-sized avatar
👻
wandering

May aprilandjan

👻
wandering
View GitHub Profile
@aprilandjan
aprilandjan / output_require_time_cost.js
Created October 20, 2023 02:33
print output commonjs require time cost
// place the code at the beginning of your script file
// before any other use of 'require'
const Module = require('module').Module;
const originalLoad = Module._load;
Module._load = function (name, parent) {
const uid = `${parent} -> ${name}`;
console.time(uid);
const exports = originalLoad.apply(Module, arguments);
console.timeEnd(uid);
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({
@aprilandjan
aprilandjan / CustomModuleLoader.ts
Created November 10, 2021 08:15 — forked from deejayy/CustomModuleLoader.ts
Solves the problem with typescript->javascript compilation and module path aliases (compilerOptions.paths).
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');
@aprilandjan
aprilandjan / download.js
Created January 7, 2020 11:32
download-and-extract-npm-module
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');
}

Travel Guide to OpenGL

I've figured out several things while trying to extend my knowledge of Computer Graphics.

  1. OpenGL can be a bitch if you don't know what you're doing.
  2. There is no worse pain than to experience CMake without knowing what you're doing.
  3. When walking to the depths of hell, it would be nice to have a travel guide.

And that's what this is, a travel guide.

@aprilandjan
aprilandjan / utils.ts
Created April 2, 2019 11:09
hand-made, lightweight utility functions to do value operations.
/**
* 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)) {
@aprilandjan
aprilandjan / better-nodejs-require-paths.md
Created January 31, 2019 13:49 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

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.

Possible solutions

@aprilandjan
aprilandjan / multiple_ssh_setting.md
Created January 4, 2019 12:45 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
@aprilandjan
aprilandjan / object-to-form-data.js
Created August 29, 2018 08:54 — forked from ghinda/object-to-form-data.js
JavaScript Object to FormData, with support for nested objects, arrays and File objects. Includes Angular.js usage.
// 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) {
@aprilandjan
aprilandjan / README.md
Created March 19, 2018 10:16 — forked from hofmannsven/README.md
My simply MySQL Command Line Cheatsheet