Skip to content

Instantly share code, notes, and snippets.

View gnapse's full-sized avatar

Ernesto García gnapse

View GitHub Profile
@gnapse
gnapse / MyComponent.js
Last active November 29, 2017 20:57
Avoiding calling setState on an unmounted React component
import React, { Component } from ‘react’;
const noop = () => {};
export default class MyComponent extends Component {
state = { data: null, error: null };
handleSuccess = data => {
this.setState({ data });
};
@gnapse
gnapse / README.md
Created December 12, 2017 22:55
Dark Slack

Append the following to the end of this file:

/Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js

document.addEventListener('DOMContentLoaded', function() {
 $.ajax({
   url: 'https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css',
   success: function(css) {
 $("").appendTo('head').html(css);
@gnapse
gnapse / osx-for-hackers.sh
Created December 19, 2017 13:30 — forked from brandonb927/osx-for-hackers.sh
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.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx
@gnapse
gnapse / buildPayload.js
Last active November 29, 2018 14:14
Function to convert objects back to jsonapi format
/**
* 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
gnapse / index.md
Last active July 8, 2020 15:51
Promise vs async/await

then(onSuccess).catch(onFailure)

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
gnapse / git-cleanup-repo
Created January 19, 2021 15:20 — 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.
#!/bin/bash
# git-cleanup-repo
#
# Author: Rob Miller <rob@bigfish.co.uk>
# 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
function debugFocus(turnOn) {
if (turnOn && window.debugFocusInterval) {
console.log("debugFocus: already on");
return;
}
if (!turnOn && !window.debugFocusInterval) {
console.log("debugFocus: already off");
return;
}