Skip to content

Instantly share code, notes, and snippets.

@patio11
patio11 / react-flummox-reduce-boilerplate.js
Created June 26, 2015 13:39
Got tired of all the boilerplate with hooking up Stores/Actions so...
// When I was working on our React/Flummox app I got to the point where, per the docs, I had ~100 lines of code
// which were substantially predictable boilerplate, so I used some JS metaprogramming to condense them by 80%.
// Flummox docs: http://acdlite.github.io/flummox
// I use underscore.js below for utility but you can also just do a for loop.
class AppFlux extends Flux {
constructor() {
import * as Ensure from '../../../../utils/lib/Ensure'
import markdownBlockDelimiter from './markdownBlockDelimiter'
import {BlockTypes, BlockTypeRegExps} from './Types'
import {
CharacterMetadata,
ContentState,
ContentBlock,
EditorState,
genKey,
} from 'draft-js'
@aphyr
aphyr / video2gif.sh
Created March 28, 2018 04:07
Video to gif script
#!/bin/bash
# Args: input video file, start time in HH:MM:SS, duration in seconds, output
# gif file.
# Tmpdir
rm -rf /tmp/video2gif
mkdir /tmp/video2gif
mplayer -nosub -ao null -ss "$2" -endpos "$3" "$1" -vo jpeg:outdir=/tmp/video2gif:quality=100
@shrunyan
shrunyan / index.js
Created March 21, 2018 17:20
Take screenshots of urls. Inspired by https://meowni.ca/posts/2017-puppeteer-tests/
const puppeteer = require('puppeteer')
const express = require('express')
const querystring = require('querystring')
const server = express()
/**
* Screenshot a url
* e.g. /screenshot?url=https://www.npmjs.com&width=800&height=600
*/
server.get('/screenshot', async (req, res) => {
#!/usr/bin/env ruby
require 'base64'
require 'nokogiri'
require 'uri'
def main
html = Nokogiri::HTML($stdin.read)
inline_all_images(html)
inline_all_css(html)
@dsherret
dsherret / ensure-public-api-has-tests.ts
Last active September 24, 2018 18:02
Analyzes code to find missing tests.
/**
* Ensure Public API Has Tests
* ---------------------------
* This demonstrates analyzing code to find methods and properties from the public
* api that don't appear in the tests.
*
* This is a very basic implementation... a better implementation would examine more
* aspects of the code (ex. are the return values properly checked?) and report
* statistics about the tests that possibly indicate how they could be improved (ex.
* "this test has a lot of overlap with these other tests"). The goal would be to
@cpojer
cpojer / .gitignore
Last active January 2, 2019 12:27
GitHub RN Issue Parser
node_modules
comments.json
comments.md

architectures and whatnot

  1. plain ol' React
let state = initial
render(view(state), element)
  • view is pure!

Here's a neat trick.

I treat my git clones as disposable between computers, but keep my project-specific dotfiles (usually containing environment variables, individual configurations, and so on) synced across devices in iCloud. Then, this script is just a matter of adding symlinks for each of the dotfiles I've saved for each of my projects to each of their clones.

So if my dotfiles are saved like this:

$ tree -a ~/icloud-drive/dotfiles/project-dotfiles/
/Users/justin/icloud-drive/dotfiles/project-dotfiles/
├── searls
@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 >