Skip to content

Instantly share code, notes, and snippets.

View gilbarbara's full-sized avatar
💥
Keep Buggering On

Gil Barbara gilbarbara

💥
Keep Buggering On
View GitHub Profile
@gilbarbara
gilbarbara / config.ts
Last active September 28, 2023 16:49
Playwright coverage
import { join } from 'path';
export const TEMP_DIRECTORY = join(__dirname, '..', '.temp');
@gilbarbara
gilbarbara / gitsubmodules.sh
Last active October 18, 2022 23:45
Install git submodules from a .gitmodules file
#!/bin/sh
set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $path
@gilbarbara
gilbarbara / vercel-cors.ts
Created August 16, 2022 00:07
Vercel cors helper
export function cors(fn: NextApiHandler, methods = ['GET']) {
return async (request: NextApiRequest, response: NextApiResponse) => {
const allowedMethods = [...methods, 'OPTIONS'].join(',');
response.setHeader('Access-Control-Allow-Credentials', 'true');
response.setHeader('Access-Control-Allow-Origin', '*');
response.setHeader('Access-Control-Allow-Methods', allowedMethods);
response.setHeader(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Authorization, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
@gilbarbara
gilbarbara / HtmlWrapper.js
Created December 25, 2017 15:11
Convert DOM node to React Element
@@ -0,0 +1,21 @@
import React from 'react';
import PropTypes from 'prop-types';
import ReactHtmlParser from 'react-html-parser';
export default class HtmlWrapper extends React.Component {
static propTypes = {
element: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
export function slugify(input = '') {
return removeAccents(input)
.replace(/[\u0300-\u036f]/g, '')
.replace(/[()]/g, '')
.replace(/ /g, '-')
.replace(/[|^{}%"<>\\`]/g, '')
.toLowerCase();
}
/**
* Remove accents
*/
export function removeAccents(input: string) {
const removalMap = {
A: /[AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄ]/g,
AA: /[Ꜳ]/g,
AE: /[ÆǼǢ]/g,
AO: /[Ꜵ]/g,
AU: /[Ꜷ]/g,
@gilbarbara
gilbarbara / .editorconfig
Created May 20, 2015 23:56
basic .editorconfig fille
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# change these settings to your own preference
indent_style = space
indent_size = 4
@gilbarbara
gilbarbara / react-d3.jsx
Last active September 9, 2020 08:44
React + D3 example
import React from 'react';
import { autobind } from 'core-decorators';
import d3 from 'd3';
import moment from 'moment';
import classNames from 'classnames';
export default class EvolutionChart extends React.Component {
static propTypes = {
investment: React.PropTypes.object.isRequired,
size: React.PropTypes.array,
@gilbarbara
gilbarbara / machine.js
Last active January 2, 2020 16:48
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
@gilbarbara
gilbarbara / randomID.js
Last active November 28, 2019 21:16
Generate a random alphanumeric string
function randomID(size = 6) {
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let text = '';
for (let i = 0; i < size; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}