Skip to content

Instantly share code, notes, and snippets.

View AdamBrodzinski's full-sized avatar

Adam Brodzinski AdamBrodzinski

View GitHub Profile
@acdlite
acdlite / app.js
Last active January 20, 2023 08:23
Quick and dirty code splitting with React Router v4
// getComponent is a function that returns a promise for a component
// It will not be called until the first mount
function asyncComponent(getComponent) {
return class AsyncComponent extends React.Component {
static Component = null;
state = { Component: AsyncComponent.Component };
componentWillMount() {
if (!this.state.Component) {
getComponent().then(Component => {
@sikanhe
sikanhe / rethink_query_wrapper.ex
Created January 3, 2016 23:39
Functions to wrap commonly used rehinkdb queries with error handling
defmodule App.Query do
import App.Database, only: [run: 1]
alias RethinkDB.Query
def get(table, id) when is_bitstring(id) do
Query.table(table)
|> Query.get(id)
|> run
|> catch_errors
|> handle_get_response
@tlrobinson
tlrobinson / redux-devtools-separate-window.js
Last active August 20, 2019 23:54
Put the awesome redux-devtools in it's own window so it doesn't obscure or be obscured by your application
// give it a name so it reuses the same window
var win = window.open(null, "redux-devtools", "menubar=no,location=no,resizable=yes,scrollbars=no,status=no");
// reload in case it's reusing the same window with the old content
win.location.reload();
// wait a little bit for it to reload, then render
setTimeout(function() {
React.render(
<DebugPanel top right bottom left >
@mattmccray
mattmccray / AnimationMixin.js
Created March 10, 2015 07:22
React AnimationMixin - for Animate.css
// Extracted from a live application. Known to work with latest Chrome/Firefox
// and Animate.css. (IE untested)
export let AnimationMixin= {
playAnimation( animation='pulse', speed=1000) {
if(! this.isMounted()) {
log.warn( "Trying to call .playAnimation() on an unmounted component!")
return
}

Folder Structure

Please note

While this gist has been shared and followed for years, I regret not giving more background. It was originally a gist for the engineering org I was in, not a "general suggestion" for any React app.

Typically I avoid folders altogether. Heck, I even avoid new files. If I can build an app with one 2000 line file I will. New files and folders are a pain.

@mseeley
mseeley / webworker-preloader.html
Created March 3, 2014 09:29
WebWorker Image preloader proof of concept (Tested in Mobile Safari 6.0/IOS 6.1.3 and Chrome 33)
<!DOCTYPE html>
<html>
<head>
<title>WebWorker image preloading</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
</head>
<body>
<div id="output"></div>
<script id="imgloader" type="javascript/worker">
// Not race proof or robust. Proof of concept.
@xpressivecode
xpressivecode / iron-router-resource.js
Last active December 24, 2015 14:38
Sample for routing resources using IronRouter
IronRouter.prototype.mapResource = function(resource){
var router = this;
var _routes = [
{ name: resource, path: '/' + resource, action: 'index' },
{ name: 'show' + resource, path: '/' + resource + '/:id', action: 'show' }
];
_.each(_routes, function(route, index){
router.map(function(){
this.route(route.name, {
@zol
zol / gist:6643666
Created September 20, 2013 20:45
Restore a dumped mongodb into local meteor development db
mongorestore --port 3002 --drop --db meteor ./dump/verso/
@thomassuckow
thomassuckow / karma.js
Last active June 18, 2017 13:26
Using karma to load requirejs tests with the .spec.js suffix. Note the base url needs the / otherwise karma-requirejs will whine about no timestamp (paths will differ) We mangle the files list to be relative, otherwise using relative paths in the form of "./bar" will fail. In my use case I have a shared config.js file that has more configuration…
var tests = Object.keys(window.__karma__.files).filter(function (file) {
return /\.spec\.js$/.test(file);
}).map(function(file){
return file.replace(/^\/base\/src\/js\/|\.js$/g,'');
});
require.config({
baseUrl: '/base/src/js',
paths: {
"lib":"../../target/js/lib"
@zol
zol / gist:5469228
Created April 26, 2013 18:12
WIP cordova In App Browser wrapper.
IAB = {
closed: true, //for meteor to detect closed state
open: function(url, cb, goalURL) {
var that = this;
cordova.exec(function(params) {
switch (params.type) {
case 'loadstart':
console.log('IAB: loadstart url, ' + params.url);