Skip to content

Instantly share code, notes, and snippets.

View jgcmarins's full-sized avatar

João Marins jgcmarins

View GitHub Profile
@jgcmarins
jgcmarins / restart-webpack.sh
Last active September 5, 2019 18:30
Keeps restarting Webpack when dying due memory leak
#!/usr/bin/env bash
# Example: sh ./scripts/restart-webpack.sh yarn start
# where `start` is defined as `webpack-dev-server --config webpack.config.js --progress`
# at package.json
# Related issue: https://github.com/webpack/webpack/issues/6929
until $1 $2; do
echo "Webpack crashed with exit code $?. Respawning..." >&2
@jgcmarins
jgcmarins / StyledIcon.tsx
Created March 12, 2019 12:40
Do not emit warning when using styled-components
// do not emit warning
const StyledIcon = styled(({ isOpen, ...rest }) => <Icon {...rest} />)`
margin-left: ${props => (props.isOpen ? 0 : 1)}px;
font-size: 14px !important;
color: ${props => props.theme.primaryBackgroundColor};
`;
// emit warning
const StyledIcon = styled(Icon)<{ isOpen: boolean }>`
margin-left: ${props => (props.isOpen ? 0 : 1)}px;
import mongoose from 'mongoose';
const { ObjectId } = mongoose.Schema.Types;
const Schema = new mongoose.Schema(
{
name: {
type: String,
trim: true,
index: true,
import mongoose from 'mongoose';
import UserModel from './UserModel';
export default async (parentId, leafId) => {
const searchResult = await UserModel.aggregate([
{ $match: { _id: parentId.toString() } },
{
$graphLookup: {
from: 'User',
startWith: '$manager',
@jgcmarins
jgcmarins / Write My Code For Me: Cheating at Developer Experience.md
Created April 4, 2019 19:48 — forked from swyxio/Write My Code For Me: Cheating at Developer Experience.md
some thoughts on adding templating/scaffolding to CLIs and how it can be done well

Write My Code For Me: Cheating at Developer Experience

this is a draft of a blogpost that i'll be posting somewhere. Feedback welcome! also feel free to ping me on twitter

I've recently been working on some CLI that involves printing out a bunch of boilerplate template code for developer convenience. I found that there were a few interesting DX angles to this and figured I should write down the rough problem areas and the stances I chose. Most of us are familiar with CLIs like https://yeoman.io/, this task is variously called "scaffolding" or "templating" or some such similar term, with varying degrees of intelligence in the task. I'll refer to it as "templating" in this essay.

Part 1: Should You?

Caramel, not just Sugar

import { connect, FormikProps, withFormik } from "formik";
import * as React from "react";
import * as yup from "yup";
import Button from "@material-ui/core/Button";
import TextField from "@material-ui/core/TextField";
const _TextField = props => <TextField {...props} />;
const FormikTextField = connect(_TextField);
type Values = {
@jgcmarins
jgcmarins / MyFunctionComponent.test.tsx
Last active May 15, 2019 20:56
Testing functions only called by useEffect
import React from 'react';
import { mount } from 'enzyme';
import formEventEmitter from '../formEventEmitter';
import MyFunctionComponent from '../MyFunctionComponent';
jest.mock('../formEventEmitter');
it('should check if preventCancel is being called', () => {
const dialog = { confirm: jest.fn() };
@jgcmarins
jgcmarins / build.gradle
Last active June 5, 2019 03:20 — forked from rozPierog/build.gradle
Automated AAR build, move to folder and deJetify. Just add this to to end of your build.gradle file and run `prepareAAR` task
def manifest = new XmlSlurper().parse(file("./src/main/AndroidManifest.xml"))
def packageName = [email protected]()
task copyAAR(type: Copy) {
from "$projectDir/build/outputs/aar/"
include 'android.aar'
into "$projectDir/AAR/"
rename 'android.aar', "${packageName}.aar"
doLast {
// https://twitter.com/wongmjane/status/1151680678682976258
const csrfToken = () => window.crypto.getRandomValues(new Uint8Array(32)).reduce(
(acc, n) => `${acc}${n.toString(16).substring(-1)}`, ''
)
// https://twitter.com/wongmjane/status/1152119291338096641
const random = () => (
globalThis.crypto.getRandomValues(
new Uint32Array(1)
)[0] / (0xFFFFFFFF + 1)
)