Skip to content

Instantly share code, notes, and snippets.


Ernesto García gnapse

View GitHub Profile
gnapse / git-cleanup-repo
Created Jan 19, 2021 — forked from robmiller/git-cleanup-repo
A script for cleaning up Git repositories; it deletes branches that are fully merged into `origin/master`, prunes obsolete remote tracking branches, and as an added bonus will replicate these changes on the remote.
View git-cleanup-repo
# git-cleanup-repo
# Author: Rob Miller <>
# Adapted from the original by Yorick Sijsling
git checkout master &> /dev/null
# Make sure we're working with the most up-to-date version of master.
git fetch
gnapse /
Last active Jul 8, 2020
Promise vs async/await


This one catches errors not only during the ajax request, but during the onSuccess handler execution.

const response = ajax(options).then(onSuccess).catch(onFailure)

The appropriate translation to async/await could be something like this:

gnapse /
Created Dec 19, 2017 — forked from brandonb927/
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see
# Alot of these configs have been taken from the various places
# on the web, most from here

Append the following to the end of this file:


document.addEventListener('DOMContentLoaded', function() {
   url: '',
   success: function(css) {
gnapse / buildPayload.js
Last active Nov 29, 2018
Function to convert objects back to jsonapi format
View buildPayload.js
* Converts a given object to a jsonapi-compliant version of it, suitable to be used in api calls
* Specifying relationship attributes
* Each property in the `relationshipAttrs` argument correspondes to an attribute name in `object`.
* The value should be either a string or a small object specifying `name` (optional) and `type`.
* If the value is a string, this is used both for the name of the relationship in the resulting
* payload object, and for the type of the objects related. However, if the value of a
gnapse / MyComponent.js
Last active Nov 29, 2017
Avoiding calling setState on an unmounted React component
View MyComponent.js
import React, { Component } from ‘react’;
const noop = () => {};
export default class MyComponent extends Component {
state = { data: null, error: null };
handleSuccess = data => {
this.setState({ data });
gnapse /
Created Oct 9, 2016 — forked from oelmekki/
Rails + Browserify + React + es7

1. Gemfile

gem 'browserify-rails', '1.5.0' # until fix:
gem 'react-rails'

Browserify-rails allows to use browserify within assets pipeline. React-rails is here only to allow to use #react_component (and thus, prerendering).

Note that jquery-rails can be removed from Gemfile, the npm version of jquery and jquery-ujs will be used instead.

View Enhance.js
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
componentDidMount() {
this.setState({ data: 'Hello' });
render() {
View on-jsx.markdown

Hi Nicholas,

I saw you tweet about JSX yesterday. It seemed like the discussion devolved pretty quickly but I wanted to share our experience over the last year. I understand your concerns. I've made similar remarks about JSX. When we started using it Planning Center, I lead the charge to write React without it. I don't imagine I'd have much to say that you haven't considered but, if it's helpful, here's a pattern that changed my opinion:

The idea that "React is the V in MVC" is disingenuous. It's a good pitch but, for many of us, it feels like in invitation to repeat our history of coupled views. In practice, React is the V and the C. Dan Abramov describes the division as Smart and Dumb Components. At our office, we call them stateless and container components (view-controllers if we're Flux). The idea is pretty simple: components can'


Switch To Vim For Good

This guide is coming from an email I used to send to newcomers to Vim. It is not intended to be a complete guide, it is about how I did the switch.

Some background: my decision to switch to Vim has been made a long time ago. Coming from TextMate 1, I wanted to learn an editor that is Open Source (so I don’t lose my time learning a tool that can be killed), cross platform (so I can use it everywhere), and powerful enough (so I won’t regret TextMate). For these reasons, Vim has always been the editor I wanted to learn, but it took me several years before I did it in a way that works for me. I tried to switch progressively, using the Janus Vim distribution for a few months, then got back to using TextMate 2 for a time, waiting for the next attempt… here is what finally worked for me.

Non Optional

  1. Watch the Derek Wyatt videos in order (at least the “Novice” ones for now):
  2. Read the first part of this Sta