Skip to content

Instantly share code, notes, and snippets.


May aprilandjan

View GitHub Profile
aprilandjan / download.js
Created Jan 7, 2020
View download.js
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`, {
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 / utils.ts
Created Apr 2, 2019
hand-made, lightweight utility functions to do value operations.
View utils.ts
* 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 /
Created Jan 31, 2019 — forked from branneman/
Better local require() paths for Node.js

Better local require() paths for Node.js


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 /
Created Jan 4, 2019 — forked from jexchan/
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 ""
aprilandjan / object-to-form-data.js
Created Aug 29, 2018 — 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.
View object-to-form-data.js
// 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) {
View webpack-require-context.js
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$/))
View ua.js
var userAgent = window.navigator.userAgent.toLowerCase()
var ua = {
isIOS: userAgent.match(/iphone|ipad|ipod/i),
isAndroid: userAgent.match(/android/i),
isWechat: userAgent.match(/micromessenger/i),
isWeibo: userAgent.match(/weibo/i),
isQQ: userAgent.match(/qq/i),
isMobile: userAgent.match(/iphone|ipad|ipod|android/i)
aprilandjan / slugify.js
Last active Apr 14, 2017 — forked from mathewbyrne/slugify.js
Javascript Slugify
View slugify.js
function slugify(text)
return text.toString().trim().toLowerCase()
.replace(/\s+/g, '-') // Replace spaces with -
// .replace(/[^\w\-]+/g, '') // Remove all non-word chars
.replace(/[^a-zA-Z0-9_\u3400-\u9FBF\s-]/g,'') // remove all non-word & non-chinese chars
.replace(/\-\-+/g, '-') // Replace multiple - with single -
You can’t perform that action at this time.