Skip to content

Instantly share code, notes, and snippets.

@imekachi
imekachi / mongoose-paginate.js
Created September 18, 2019 02:43
based on mongoose-paginate npm package, fixed deprecaion warning, add aggregateMode support
import _ from 'lodash'
// This is based on a PR which fixed collection.count deprecation warning
// https://github.com/edwardhotchkiss/mongoose-paginate/blob/e807d87b02aca2198f4fb2e5e896e6aad4b77f55/index.js
// but only god knows when the PR will get merged, so here we are, create our own fork.
// Now with aggregateMode support!!.
/**
* mongoose-paginate
* @param {Object|Array} [query={}] - this must be array when using aggregate mode (options.aggregateMode = true)
[
{ "keys": ["ctrl+j"], "command": "find_under_expand" },
{ "keys": ["ctrl+shift+j"], "command": "find_all_under" },
{ "keys": ["super+d"], "command": "duplicate_line" },
{ "keys": ["alt+shift+up"], "command": "swap_line_up" },
{ "keys": ["alt+shift+down"], "command": "swap_line_down" },
]
@imekachi
imekachi / introspectionQuery.js
Created November 27, 2018 09:21
Fetch introspectionQuery from your graphQL api and create `graphql.schema.json` file. Works with local host with https(self-signed certificate)
const fetch = require('isomorphic-unfetch')
const fs = require('fs')
const path = require('path')
const https = require('https')
// by-pass self-signed certificate rejection on local server
const agent = new https.Agent({
rejectUnauthorized: false,
})
@imekachi
imekachi / async-await.js
Created September 26, 2018 02:05 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works
const axios = require('axios'); // promised based requests - like fetch()
function getCoffee() {
return new Promise(resolve => {
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee
});
}
@imekachi
imekachi / pure.zsh
Last active September 3, 2018 04:10 — forked from elijahmanor/pure.zsh
Add node and npm versions to [email protected]
# pure.zsh is located at /usr/local/lib/node_modules/pure-prompt/pure.zsh
# Pure @1.8.0
# by Sindre Sorhus
# https://github.com/sindresorhus/pure
# MIT License
# For my own and others sanity
# git:
# %b => current branch
@imekachi
imekachi / access_local_servers_from_mobile.md
Last active July 4, 2018 10:07
Accessing local servers from Android/Mobile device with custom domain, Use pc as DNS server for mobile in the same LAN.

On PC/Mac

  1. You have to run proxy server on you machine. Download SquidMan UI app of squid proxy. (Unfortunately this app is MacOS only. For Windows user, try alternative proxy server app)
  2. Setting up, at Preferences > General set desire port for proxy server to HTTP Port: (default is 8080)
  3. Config ip addresses that can access this proxy in Preferences > Clients
    • press New
    • enter ip and subnet you want ie. 192.168.1.0/24
  4. Disable localhost apps protection, go to Preferences > Template scroll and find http_access deny to_localhost and comment the line by adding # in front of it.
@imekachi
imekachi / difference.js
Last active June 8, 2018 08:10 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
return _.transform(object, (result, value, key) => {
if (!_.isEqual(value, base[key])) {
result[key] = _.isObject(value) && _.isObject(base[key]) ? difference(value, base[key]) : value
@imekachi
imekachi / yammer-draft.js
Created December 25, 2017 07:53
Inject the code to yammer page, it will automatically save data in localStorage and load it when the page is loaded. For preventing data lost in unexpected page closing.
var storage = {
key: 'yammer_draft',
save: function(data) {
localStorage.setItem(this.key, JSON.stringify(data))
},
get: function() {
return JSON.parse(localStorage.getItem(this.key))
}
}
@imekachi
imekachi / storybook.config.js
Created August 11, 2017 09:27
dynamically load stories
import { configure } from '@storybook/react'
// each filename returns as "./_Component.js"
const req = require.context('../src/stories', true, /^(\.\/_)(.+)(\.js$)/)
// Explicitly require load stories
// function loadStories() {
// // require('../src/stories');
// req.keys().forEach(filename => req(filename))
// }
@imekachi
imekachi / config-overrides.js
Last active January 13, 2019 16:46
Unlock decorator syntax in create-react-app for MobX without ejecting using react-app-rewired.
/**
* React-app-rewired, tweaking configs without ejecting create-react-app project
*
* 1. yarn add react-app-rewired babel-plugin-transform-decorators-legacy
* 2. copy this file to root (same as node_modules) and name it as 'config-overrides.js'
* 3. you can add more plugins if want, if not, skip to (4.)
* 4. edit package.json script to use 'react-app-rewired' instead of 'react-scripts'
*
* "scripts": {
* "start": "react-app-rewired start",