Skip to content

Instantly share code, notes, and snippets.

View kmylo's full-sized avatar
🎯
Focusing

kmylo kmylo

🎯
Focusing
View GitHub Profile
@kmylo
kmylo / tinyFetch.js
Created July 18, 2023 02:59
A tiny wrapper around fetch() replace-axios-with-a-simple-custom-fetch-wrapper
// A tiny wrapper around fetch(), borrowed from
// https://kentcdodds.com/blog/replace-axios-with-a-simple-custom-fetch-wrapper
export async function client(endpoint, { body, ...customConfig } = {}) {
const headers = { 'Content-Type': 'application/json' }
const config = {
method: body ? 'POST' : 'GET',
...customConfig,
headers: {
@kmylo
kmylo / useListGroupBy.tsx
Created March 15, 2023 07:07
react custom hook to group by some key array of items (Map version)
import { useMemo } from "react";
type ListGroupByMap<T> = Map<T[keyof T], T[]>;
const useListGroupBy = <T,>(list: T[], typeKey: keyof T): ListGroupByMap<T> => {
const updatedListByType = useMemo(() => {
const listByType = new Map<T[keyof T], T[]>();
list.forEach((item) => {
const itemValue = item[typeKey];
if (listByType.has(itemValue)) {
@kmylo
kmylo / .eslintrc
Created January 9, 2022 07:24
react eslintrc
{
"env": {
"node": true,
"browser": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
@kmylo
kmylo / conditionsArray.js
Created October 18, 2021 05:05
conditions array
let condition1 = 13 ==='13';
let condition2 = 1 === 1
let condition3 = {} ==={};
let condArray = [
condition1, condition2
]
if(!condArray.includes(false)){
console.log('all false')
@kmylo
kmylo / CT.css_mod.js
Created October 18, 2021 00:23
CT.css performance (modified)
let ctCss= `
/*!==========================================================================
#CT.CSS
==========================================================================*//*!* ct.css – Let’s take a look inside your <head>…
*
* © Harry Roberts 2021 – twitter.com/csswizardry*/head{--ct-is-problematic: solid;--ct-is-affected: dashed;--ct-notify: #0bce6b;--ct-warn: #ffa400;--ct-error: #ff4e42}head,head script,head script:not([src])[async],head script:not([src])[defer],head style,head [rel=stylesheet],head script~meta[http-equiv=content-security-policy],head>meta[charset]:not(:nth-child(-n+5)){display:block}head script,head style,head [rel=stylesheet],head title,head script~meta[http-equiv=content-security-policy],head>meta[charset]:not(:nth-child(-n+5)){margin:5px;padding:5px;border-width:5px;background-color:#fff;color:#333}head ::before,head script,head style{font:16px/1.5 monospace,monospace;display:block}head ::before{font-weight:700}head script[src],head link[rel=stylesheet]{border-style:var(--ct-is-prob
@kmylo
kmylo / CT.css.js
Created October 18, 2021 00:23
CT.css performance (original)
(function(){
var ct = document.createElement('link');
ct.rel = 'stylesheet';
ct.href = 'https://csswizardry.com/ct/ct.css';
document.head.appendChild(ct);
}())
@kmylo
kmylo / gist:a280924d96731db961b571f1b3b401ea
Created June 27, 2021 06:07
chrome devtools snippets jq backup
jq .devtools.preferences.scriptSnippets "/mnt/c/Users/{myuser}/AppData/Local/Google/Chrome/User Data/{myprofile#}/Preferences" \
| jq '. | fromjson' > bkp_myprofile#.json
@kmylo
kmylo / sublime ES key binding curly brackets }
Created October 6, 2020 05:06
Restoring } key in sublime text for spanish keyboards
[
/*
Restoring } key in sublime text for spanish keyboards
-----------------------------------------------------------------------------
FROM: http://arqex.com/727/restoring-key-in-sublime-text-for-spanish-keyboards
*/
{ "keys": ["ctrl+alt+/"], "command": "insert", "args": {"characters": "}"}}
]
@kmylo
kmylo / swap_array_items.js
Last active December 19, 2019 19:15
Swap two array items position
Array.prototype.move = function(from, to) {
this.splice(to, 0, this.splice(from, 1)[0]);
};
const swapPositions = (array, a ,b) => {
[array[a], array[b]] = [array[b], array[a]]
}
@kmylo
kmylo / clean-angularjs-html
Created April 13, 2018 15:00
clean angularjs html (comments, attr, and class)
<h3>limpamos angular:</h3>
<pre>
//inyectamos javascript
var script = document.createElement('script');script.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js";document.getElementsByTagName('head')[0].appendChild(script);
//Borramos los comments
$("*").contents().filter(function(){ return this.nodeType == 8;}).remove();
//luego borramos los atributos