Skip to content

Instantly share code, notes, and snippets.

View manrueda's full-sized avatar

Manuel Rueda manrueda

View GitHub Profile
@manrueda
manrueda / index.js
Created April 15, 2021 12:27
This script will find all CSS statements and sort them by the impact that have on the current DOM
// Finds the most impactful CSS statements based on DOM impact
const allRules = Array.from(document.styleSheets).map(s => Array.from(s.rules).filter(e => e.selectorText)).flat()
const removePseudo = selector => selector.split(',').map(s => s.replace(/::[^ ,]*/g, '').trim()).filter(Boolean).join(', ')
const results = allRules.map(r => {
// removes the pseudo elements and pseudo classes
const impactedNodes = document.querySelectorAll(removePseudo(r.selectorText)).length;
return {
impactedNodes,
@manrueda
manrueda / create-monorepo.sh
Last active January 8, 2020 00:02
Monorepo creator
#!/bin/bash
# This removes a warning from Git to avoid delay
export FILTER_BRANCH_SQUELCH_WARNING=1;
new_repo=~/dev/ado/blue-workspace
mkdir -p "$new_repo"
cd "$new_repo"
git init
@manrueda
manrueda / data.json
Created January 6, 2020 00:39
Toolkit site items
[]
@manrueda
manrueda / index.ts
Created March 29, 2019 20:31
typedoc-plugin-external-module-name issue
/**
* @module @cool/package
*/
import * as _sub from './sub'
export const sub: typeof _sub = _sub;
@manrueda
manrueda / clean-up.sh
Created August 28, 2017 15:19
Remove cache instances of GitLab CI Runner
docker ps -a | grep cache | awk '{print $2}'
@manrueda
manrueda / code-generator.js
Created June 6, 2017 18:50
Generate code from swagger source
const swaggerExtractor = /https?:\/\/(.*)\/.*\/#!\/(.*)\/(.*)/i
function getUrlsParts (url) {
const [, domain, entity, method] = url.match(swaggerExtractor)
return { domain, entity, method }
}
async function getModels(url) {
const { domain, entity, method } = getUrlsParts(url)
const req = await fetch(`https://${domain}/api/core/swagger/api-docs/${entity}`)
const jsonResponse = await req.json()
@manrueda
manrueda / Dockerfile
Last active June 6, 2017 02:43
Node.js v8.0.0 - ARMv7l
# Node.js v8.0.0 - ARMv7l
FROM arm32v7/buildpack-deps:jessie
RUN groupadd --gid 1000 node \
&& useradd --uid 1000 --gid node --shell /bin/bash --create-home node
# gpg keys listed at https://github.com/nodejs/node#release-team
RUN set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
@manrueda
manrueda / http-file-explorer.js
Created May 23, 2017 00:31
CRUD over a folder over HTTP
const formidable = require('formidable')
const fs = require('fs-extra')
const path = require('path')
module.exports = ({path: _path}) => {
fs.ensureDirSync(_path)
return async (req, res) => {
const method = req.method.toLowerCase()
switch (method) {
case 'get':
@manrueda
manrueda / converter.js
Last active August 24, 2016 14:59
Convert a JSON string to a an string with JS code representing that object
(JSONString => {
let objectString = JSONString;
JSONString.match(/"(.*?)":\n*(.*)/gi).forEach(line => {
var parts = line.match(/"(.*?)":\n*(.*)/);
if (parts[2].match(/^"(.*)",?$/)){
let hasComma = !!parts[2].match(/^"(.*)",{1}$/)
parts[2] = '\'' + parts[2].match(/^"(.*)",?$/)[1] + '\'' + (hasComma ? ',': '');
}
objectString = objectString.replace(parts[0], parts[1] + ': ' + parts[2])
})
@manrueda
manrueda / grid.html
Last active June 27, 2016 20:14
WjFlexGridCellTemplate with angular templates, width error
<div>
<wj-flex-grid items-source="data" style="height: 150px;margin-top:10px" control="flex" initialized="initialized(s,e)">
<wj-flex-grid-column header="Country" binding="country" width="*" allow-resizing="false">
<wj-flex-grid-cell-template cell-type="Cell">
<!--<h1>{{$item.country}}</h1>-->
<div ng-include="'tpl.html'"></div>
</wj-flex-grid-cell-template>
</wj-flex-grid-column>
<wj-flex-grid-column header="Sales" binding="sales" width="*" allow-resizing="false"></wj-flex-grid-column>
<wj-flex-grid-column header="Expenses" binding="expenses" width="*" allow-resizing="false"></wj-flex-grid-column>