Skip to content

Instantly share code, notes, and snippets.

View vinnymac's full-sized avatar
🤓

Vincent Taverna vinnymac

🤓
View GitHub Profile
import ReactDOM from 'react-dom/server'
import React from 'react'
import Typography from '../../src/'
import GoogleFont from '../../src/components/GoogleFont'
import theme from '../../src/themes/us-web-design-standard'
const typography = new Typography(theme)
// Hot reload typography in development.
@darylenriquez
darylenriquez / method_chain_to_prepend.rb
Last active July 22, 2017 13:21
changing alias_method_chain to prepend
# A simplified explanation for moving alias_method_chain to prepend
# Sample class
class Note
def show_id
puts self.object_id
end
end
# using alias_method_chain:
@joshma
joshma / WhyDidYouUpdateMixin.js
Last active May 9, 2018 06:17
Performance Engineering with React (Part 2)
/* eslint-disable no-console */
import _ from 'underscore';
/*
Drop this mixin into a component that wastes time according to Perf.getWastedTime() to find
out what state/props should be preserved. Once it says "Update avoidable!" for {state, props},
you should be able to drop in React.addons.PureRenderMixin
React.createClass {
mixins: [WhyDidYouUpdateMixin]
@oakley808
oakley808 / saga-polling.js
Created October 6, 2016 15:47
A recipe for polling an API in redux-saga
export function* main() {
const { payload } = yield take(SOME_START_SIGNAL);
const watcherInstance = yield fork(updateResource, payload);
// cancel task instance on location change
yield take(LOCATION_CHANGE);
yield cancel(watcherInstance);
}
function* updateResource(id) {
@danharper
danharper / 1-sleep-es7.js
Created February 8, 2015 16:55
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()
@dannvix
dannvix / electron-main.js
Created June 24, 2015 15:44
Create Electron's BrowserWindow with dynamic HTML content
// main.js for Electron
var app = require("app"),
BrowserWindow = require("browser-window");
app.on("window-all-closed", function() {
app.quit();
})
var mainWindow = null;
app.on("ready", function() {
@acdlite
acdlite / coordinating-async-react.md
Last active March 20, 2022 12:27
Demo: Coordinating async React with non-React views

Demo: Coordinating async React with non-React views

tl;dr I built a demo illustrating what it might look like to add async rendering to Facebook's commenting interface, while ensuring it appears on the screen simultaneous to the server-rendered story.

A key benefit of async rendering is that large updates don't block the main thread; instead, the work is spread out and performed during idle periods using cooperative scheduling.

But once you make something async, you introduce the possibility that things may appear on the screen at separate times. Especially when you're dealing with multiple UI frameworks, as is often the case at Facebook.

How do we solve this with React?

@MarkMurphy
MarkMurphy / README.md
Last active March 25, 2022 21:47
ActiveRecord: Store Milliseconds (or Microseconds) in Timestamps with Rails / MySQL

ActiveRecord: Store Milliseconds (or Microseconds) in DateTimes or Timestamps with Rails / MySQL

Milliseconds in your DateTimes or Timestamps.

We got 'em, you want 'em.

NOTE: only MySQL 5.6.4 and above supports DATETIME's with more precision than a second. For reference see MySQL 5.6.4 Changelog

Why

Shit needs to be PRECISE

@danro
danro / remove-video.js
Created June 6, 2013 23:33
Remove HTML5 video and clear src attribute to prevent leaks.
// remove audio + video + stop all the downloadin’
// assumes $video and $audio are jQuery selectors for <video> and <audio> tags.
var removeMedia = function () {
_.each([$video, $audio], function ($media) {
if (!$media.length) return;
$media[0].pause();
$media[0].src = '';
$media.children('source').prop('src', '');
$media.remove().length = 0;
});
@TravelingTechGuy
TravelingTechGuy / ChromeExtensionGulp.js
Created April 5, 2014 19:22
Gulp file for building a Chrome Extension
'use strict';
//npm install gulp gulp-minify-css gulp-uglify gulp-clean gulp-cleanhtml gulp-jshint gulp-strip-debug gulp-zip --save-dev
var gulp = require('gulp'),
clean = require('gulp-clean'),
cleanhtml = require('gulp-cleanhtml'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
stripdebug = require('gulp-strip-debug'),