Skip to content

Instantly share code, notes, and snippets.

View gartz's full-sized avatar
:octocat:

Gabriel Reitz Giannattasio gartz

:octocat:
View GitHub Profile
@gartz
gartz / deepFreeze.js
Created January 27, 2022 05:36
js deepFreeze
/**
* Will deep freeze any object recursively. And it supports circular references.
*/
function deepCloneAndFreeze(arg) {
const circularFrozenRefMap = new WeakMap();
function deepCloneAndNativeFreeze(arg) {
const clone = Array.isArray(arg) ? [] : {};
circularFrozenRefMap.set(arg, clone);
const isObject = input => typeof input === 'object';

Keybase proof

I hereby claim:

  • I am gartz on github.
  • I am gartz (https://keybase.io/gartz) on keybase.
  • I have a public key ASA6-4vXcNkCOBAE7LV01HqVZvbdD1avB5DCexzlLSylnwo

To claim this, I am signing this object:

@gartz
gartz / HtmlWebpackPlugin_templateEngine.js
Created August 16, 2019 00:31
HtmlWebpackPlugin_templateEngine is a very simple template engine made for HtmlWebpackPlugin, so you can use native js template string to generate the HTML files.
const optionalCloseTags = ['link', 'meta', 'br'];
const serializeAttributes = (attributes) => Object.entries(attributes).map(([key, value]) => {
if (typeof value === 'boolean') {
return value ? key : '';
}
return `${key}="${value}"`
}).join(' ');
const html = (strList, ...args) => strList.reduce(
@gartz
gartz / justdoit
Created August 13, 2019 20:41
replace sudo by justdoit and give you a motivational speech when stdout/stderr
#!/bin/bash
declare -a keepTrying=("Yesterday you said tomorrow"
"Don't let your dreams be dreams"
"And you're not going to stop there"
"No, what are you waiting for?")
declare -a youDidIt=("You should get to the point where anyone else would quit"
"Make your dreams come true"
"Nothing is impossible"
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello World</title>
<script src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
</head>
<body>
<div id="root"></div>
/**
* Copyright 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
@gartz
gartz / bind-test.js
Last active September 14, 2015 12:57
bind test
// Begin with:
delete Function.prototype.bind;
function bind(/* ... */){
/* ... */
}
// Ends with:
Function.prototype.bind = bind;