Skip to content

Instantly share code, notes, and snippets.

View magalhini's full-sized avatar

Ricardo Magalhães magalhini

View GitHub Profile

Files

The basic structure of a React+Flux application (see other examples)

 - /src/actions/AppActions.js     - Action creators (Flux)
 - /src/components/Application.js - The top-level React component
 - /src/constants/ActionTypes.js  - Action types (Flux)
 - /src/core/Dispatcher.js        - Dispatcher (Flux)
 - /src/stores/AppStore.js        - The main store (Flux)
@magalhini
magalhini / SassMeister-input-HTML.html
Last active August 29, 2015 14:25
Generated by SassMeister.com.
<div class="logo">
<svg width="81px" height="81px" viewBox="0 0 81 81" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns">
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd" sketch:type="MSPage">
<g id="logo" sketch:type="MSLayerGroup" fill="#0AB3C4">
<path d="M62.4,7.4 C66,7.4 68.9,10.3 68.9,13.9 C68.9,16 68.6,49.7 71.9,71.7 C53,69.1 21.5,68.9 14.4,68.9 L13.9,68.9 C10.3,68.9 7.4,66 7.4,62.4 L7.4,13.9 C7.4,10.3 10.3,7.4 13.9,7.4 L62.4,7.4 L62.4,7.4 Z M62.4,0 L13.9,0 C6.2,0 0,6.2 0,13.9 L0,62.4 C0,70.1 6.2,76.3 13.9,76.3 L14.4,76.3 C19.7,76.3 63.8,76.4 78.7,80.5 C78.8,80.5 79,80.6 79.1,80.6 C80.1,80.6 80.9,79.6 80.6,78.6 C75.8,58.8 76.2,13.9 76.2,13.9 C76.3,6.2 70.1,0 62.4,0 L62.4,0 Z" id="Shape" sketch:type="MSShapeGroup"></path>
</g>
</g>
</svg>
<div class="logo-bars">
@magalhini
magalhini / bookmarket.js
Last active August 29, 2015 14:26
Flux in Browser
javascript:(function()%7B(function(doc)%20%7Bvar%20css%20%3D%20document.createElement('style')%3Bcss.appendChild(doc.createTextNode(''))%3Bdoc.head.appendChild(css)%3Bvar%20styles%20%3D%20%22body%3Abefore%20%7Bcontent%3A%20''%3B%20z-index%3A%20999%3B%20background%3A%20%23C1AE34%3B%20left%3A%200%3B%20right%3A%200%3B%20pointer-events%3A%20none%3B%20top%3A%200%3B%20bottom%3A%200%3B%20position%3A%20fixed%3B%20opacity%3A%20.4%3B%20width%3A%20100%25%3B%7D%22%3Bcss.sheet.insertRule(styles%2C%200)%3B%7D(document))%7D)()
@magalhini
magalhini / external-requests-time.js
Created August 6, 2015 11:35
Displays total time spent loading external assets in the client
/**
* From Google Developers; Collect all third party requests using the Performance API.
* Source: https://developers.google.com/web/updates/2015/07/measuring-performance-in-a-service-worker
*
*/
var getThirdPartyRequests = function() {
var thirdPartyRequests = [];
var requests = window.performance.getEntriesByType("resource");
var currentHost = window.location.host
// Kinda pseudo code
// This script will download and resize each image to half
// Because the images can be RRREAAALLY big
// the download and resize is done sequentially (in my case, inside a child_process)
// to ensure that memory is released after each image.
// We dont know how many images there are
let images = [
'https://flickr.com/photo/1',
'https://flickr.com/photo/2'
@magalhini
magalhini / webpack.js
Created October 14, 2015 12:42 — forked from Couto/webpack.js
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@magalhini
magalhini / TemplateStore.js
Last active October 27, 2015 14:53
Testing a Flux Store using Mocha and Sinon. It uses rewire to fetch a new copy of the Store every time, as to maintain a clean state before each test. Also includes a sample for the Gulp task to run it in proper TDD fashion.
// Mock our global environment using JSDOM
require('../dom-mock')('<html><body></body></html>');
let jsdom = require('mocha-jsdom');
import {
React,
sinon,
assert,
expect,
@magalhini
magalhini / advent-day1.js
Created December 3, 2015 16:17
Advent O fCode
const fs = require('fs');
const file = fs.readFileSync('./1.txt').toString('utf8');
let level = 0;
let findWay = (char) => {
if (char === '(') return 1;
else if (char === ')') return -1;
}
@magalhini
magalhini / promise-pipe-post
Created June 3, 2013 11:07
$promise for a piped POST
var asking = new $.Deferred();
var feedback = asking.pipe(function (res) {
console.log('Sending:', res);
return $.post('/echo/json', res);
});
// Simulate form submit...
asking.resolve('my details');
@magalhini
magalhini / placeholderShim.js
Last active December 19, 2015 02:39
Tiny gist to mimic placeholder behaviour in old IEs. To do: remove partial jQuery dependency.
/* Add Event Shim */
var addEvent = (function () {
var filter = function(el, type, fn) {
for (var i = 0, len = el.length; i < len; i++) {
addEvent(el[i], type, fn);
}
};
if (document.addEventListener) {
return function (el, type, fn) {
if ( el && el.nodeName || el === window ) {