Skip to content

Instantly share code, notes, and snippets.

View EnixCoda's full-sized avatar
👀
Open for local/remote frontend opportunities

Enix EnixCoda

👀
Open for local/remote frontend opportunities
View GitHub Profile
@EnixCoda
EnixCoda / readme.md
Last active December 3, 2024 09:01
Vite custom JSON loader plugin

In my special use case, I import JSON file and use them as functions.

For example,

import validator from './example.schema.json'; // schema JSON imported as function
import data from './data.json';                // general JSON imported as data

console.log(data); // { value: 'random-data' }
validator(data);
@EnixCoda
EnixCoda / readme.md
Last active December 3, 2024 08:37
Override Vite's internal JSON plugin

In my special use case, I import JSON file and use them as functions.

For example,

import validator from './example.schema.json'; // schema JSON imported as function
import data from './data.json';                // general JSON imported as data

console.log(data); // { value: 'random-data' }
validator(data);
@EnixCoda
EnixCoda / .gitconfig
Created March 29, 2021 15:14
Multiple git configs & users on single machine, require git version >= 2.13
[user]
name = globalName
email = [email protected]
useConfigOnly = true # recommended to keep
[includeIf "gitdir:~/special-workspace/"]
path = ~/special.gitconfig
@EnixCoda
EnixCoda / jest-puppeteer.config.js
Last active June 8, 2023 05:21
Test local Chrome extensions with Jest and Puppeteer
// install dependencies first:
// $ yarn add jest jest-puppeteer puppeteer -D
const path = require('path')
const CRX_PATH = path.resolve(__dirname, 'path/to/local/extension/dir')
module.exports = {
launch: {
headless: false, // required for loading extensions
@EnixCoda
EnixCoda / machine.js
Created November 28, 2019 02:24
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@EnixCoda
EnixCoda / styled.js
Last active October 14, 2019 01:49
simple styled-components
/*
* Usages
*
* native tags
* styled.div`color: red;`
*
* custom components
* styled((props) => <div {...props} />)`color: red;`
*
*/
@EnixCoda
EnixCoda / index.jsx
Created November 22, 2018 10:00
render with global data and inner counter
const globalData = []
class Component extends React.Component {
componentDidMount() {
setInterval(() => {
globalData.push(0)
this.setState((count = 0) => count + 1,)
}, 100)
}
render() {
@EnixCoda
EnixCoda / index.js
Created September 22, 2018 06:23
turn ref into render props
class _ControllerX extends React.Component {
static propTypes = {
forwardRef: PropTypes.func
}
ref = r => this.r = r
someCallback() {
this.r.method()
}
@EnixCoda
EnixCoda / polyfill.js
Created August 9, 2018 01:50
Async/Await polyfill
module.exports = function decorate(func) {
const f = func()
return (function run(input) { f.next(input).then(run) })()
}
@EnixCoda
EnixCoda / NodeJS.v.10.7.0.md
Last active November 1, 2018 19:16
safe-touch benchmark, MacBookPro 2015 15'
***********************************************************
try...catch VS safe-touch
Will run 100,000 times for each test case.

Will test with these retrieve methods:
  function impossibleRetrieve(_) { return _[Math.random()][Math.random()] }
  function shallowRetrieve(_) { return _.key }
  function deepRetrieve(_) { return _.a.b.c.d.e.f.g.h.i }