Skip to content

Instantly share code, notes, and snippets.

View zetavg's full-sized avatar

Pokai Chang zetavg

View GitHub Profile
// define vars
var a = 'foo';
function printA() {
console.log('a is ' + a);
}
// scope
{
var a = 'bar';
const resolvers = {
get([obj, path = ''], name) {
if (name === '__internal') {
return obj
}
return obj[name] || new Proxy([obj, `${path}${name}.`], resolvers)
},
set([obj, path = ''], name, value) {
obj[`${path}${name}`] = value
return value
@zetavg
zetavg / private-property-constructor.js
Last active May 4, 2019 01:53
JS private property using function scopes.
const Person = (() => {
const getName = privateProperties => privateProperties.name.split(' ')[0]
const setName = (privateProperties, name) => {
privateProperties.name = name
}
const getAge = privateProperties => privateProperties.age - 4
const setAge = (privateProperties, age) => {
privateProperties.age = age
}
@zetavg
zetavg / package-lock.json
Created April 11, 2019 15:36
Npm install a file
{
"name": "npm-install-test",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"sample-npm-package-prepack": {
"version": "file:../../sample-npm-package-prepack",
"dependencies": {
"@babel/cli": {
{
"bootstrapped": true,
"ignore_vcs_packages":
[
"Theme - Spacegray"
],
"in_process_packages":
[
],
"installed_packages":
let
nixpkgs = import <nixpkgs> {};
overlays = [
(self: super: { aa-bb = "${self.aa} ${self.bb}"; })
(self: super: { aa = "a"; })
(self: super: { bb = "b"; })
(self: super: { aa = super.aa + "a"; })
(self: super: { bb = "bbb"; })
];
inherit (builtins) foldl';
let
nixpkgs = import <nixpkgs> {
overlays = [
# This overlay obtains self.bash and super.bash, and save them under the
# attrs "bash-from-self" and "bash-from-super" for further examination
(self: super: {
bash-from-self = self.bash;
bash-from-super = super.bash;
})
];
fix = \f -> let r = f r in r -- retuns f (f (f (f (f ...)))), sounds like infinile loop?
data D = D {
a :: Int,
b :: Int,
c :: Int
} deriving (Show)
d = (\self -> D 1 (a self + 1) (a self + b self)) -- Can reference itself!
-- ^ ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
const makeOverridable = obj => ({
...obj,
override: overrides => makeOverridable({
...obj,
...overrides,
}),
})
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;