Skip to content

Instantly share code, notes, and snippets.

View IvanTorresEdge's full-sized avatar
👨‍💻
full-on building mode and loving every minute of it

Ivan Torres IvanTorresEdge

👨‍💻
full-on building mode and loving every minute of it
View GitHub Profile
@IvanTorresEdge
IvanTorresEdge / setup.tsx
Created March 30, 2020 16:31
Testing Responsive Layouts with Jest+React Testing Library
import matchMediaPolyfill from 'mq-polyfill';
matchMediaPolyfill(window);
window.matchMedia('(max-width: 640px)');
window.matchMedia('(max-width: 768px)');
window.matchMedia('(max-width: 1024px)');
window.matchMedia('(max-width: 1280px)');
window.resizeTo = function resizeTo(width, height): void {
@IvanTorresEdge
IvanTorresEdge / DeepReadOnly.ts
Created September 9, 2019 22:12
Useful TypeScript Snippets
/**
* Recursively convert any data structure to readonly (with handling of privimitives):
*/
type DeepReadonlyObject<T> = { readonly [K in keyof T]: DeepReadonly<T[K]> };
type DeepReadonly<T> = T extends (infer E)[]
? ReadonlyArray<DeepReadonlyObject<E>>
: T extends object ? DeepReadonlyObject<T> : T;
@IvanTorresEdge
IvanTorresEdge / underscore-debounce-example.js
Created December 27, 2017 12:27 — forked from kimmobrunfeldt/underscore-debounce-example.js
Example of using Underscore's _.debounce function
// Example of using Underscore's _.debounce function
// debounce is useful for situations where you get multiple events fired
// from one action. For example resize event is sent multiple times when
// window is resized
var reloadIfResizeChange = _.debounce(function() {
window.location.reload();
}, 200);
window.addEventListener('resize', reloadIfResizeChange);
@IvanTorresEdge
IvanTorresEdge / callModifierForSelectedBlocks.js
Created December 27, 2017 02:40 — forked from johanneslumpe/callModifierForSelectedBlocks.js
Draft.js utilities to inspect/modify selected block ranges
import { EditorState, SelectionState } from 'draft-js';
import getSelectedBlocks from './getSelectedBlocks';
/**
* Calls a provided `modifier` function with a selection for each
* selected block in the current editor selection. Passes through additional
* arguments to the modifier.
*
* Note: At the moment it will retain the original selection and override
@IvanTorresEdge
IvanTorresEdge / gulp_with_incremental_builds.md
Created September 29, 2017 20:46
Incremental builds with Gulp

Incremental rebuilding, including operating on full file sets

(From: https://raw.githubusercontent.com/gulpjs/gulp/master/docs/recipes/incremental-builds-with-concatenate.md)

The trouble with incremental rebuilds is you often want to operate on all processed files, not just single files. For example, you may want to lint and module-wrap just the file(s) that have changed, then concatenate it with all other linted and module-wrapped files. This is difficult without the use of temp files.

Use gulp-cached and gulp-remember to achieve this.

var gulp = require('gulp');
@IvanTorresEdge
IvanTorresEdge / setup-docker-osx-virtualbox.sh
Created February 15, 2017 14:14
Setup Docker on Mac OSX (Homebrew)
# Install Virtualbox from Homebrew (or download and install manually https://www.virtualbox.org/wiki/Downloads)
brew cask install virtualbox
# Install Docker
brew install docker docker-machine docker-compose
# Create your VM
docker-machine create -d virtualbox default --virtualbox-cpu-count "2" --virtualbox-cpu-memory "4096"
docker-machine start
@IvanTorresEdge
IvanTorresEdge / containers.sh
Last active November 29, 2016 04:18
Docker: Delete all containers && images
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)
@IvanTorresEdge
IvanTorresEdge / keyrepeat.shell
Created November 28, 2016 23:24 — forked from rastasheep/keyrepeat.shell
Enable key repeat in Apple Lion for Atom in Vim mode
# Mac OS X Lion introduced a new, iOS-like context menu when you press and hold a key
# that enables you to choose a character from a menu of options. If you are on Lion
# try it by pressing and holding down 'e' in any app that uses the default NSTextField
# for input.
#
# It's a nice feature and continues the blending of Mac OS X and iOS features. However,
# it's a nightmare to deal with in Atom if you're running vim mode,
# as it means you cannot press and hold h/j/k/l to move through your file. You have
# to repeatedly press the keys to navigate.
@IvanTorresEdge
IvanTorresEdge / gulpfile.js
Created April 18, 2016 16:00 — forked from heldr/gulpfile.js
Another way of splitting a gulpfile into multiple files
/*
Another way of splitting a gulpfile into multiple files based on:
http://macr.ae/article/splitting-gulpfile-multiple-files.html
https://github.com/gulpjs/gulp/blob/master/docs/recipes/split-tasks-across-multiple-files.md
*/
'use strict';
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
@IvanTorresEdge
IvanTorresEdge / executeGraphQLQuery.js
Created March 30, 2016 20:10
Execute GraphQL Queries
import {
Source,
parse,
validate,
execute,
formatError,
getOperationAST,
specifiedRules
} from 'graphql';