Skip to content

Instantly share code, notes, and snippets.

View quantizor's full-sized avatar
🦾
👁️👄👁️

Evan Jacobs quantizor

🦾
👁️👄👁️
View GitHub Profile
@quantizor
quantizor / react-redux.js
Last active October 17, 2016 16:33
react-redux connect() mock for Jest
/*
place this somewhere above where your test files are in a directory called __mocks__, e.g.
__mocks__/
react-redux.js
src/
myTestFile.spec.js
Requires an updated version of node with ES6 Proxy support.
*/
@quantizor
quantizor / parallelize.sh
Created September 26, 2016 03:03
parallelize commands
#!/bin/bash
# adapted from http://stackoverflow.com/questions/10909685/run-parallel-multiple-commands-at-once-in-the-same-terminal
# but this version works in Ubuntu + Windows Subsystem for Linux
PID_LIST=""
for cmd in "$@"; do {
echo "Process \"$cmd\" started";
eval $cmd & pid=$!
@quantizor
quantizor / form.html
Created July 28, 2016 04:58
"Backward" selector example
<style>
form {
display: flex;
}
label {
order: 1;
}
input {
@quantizor
quantizor / thematic-react-redux.md
Last active December 4, 2019 00:11
Thematic project organization for React + Redux projects

Notes:

  1. All actions should go in /actions.js and all constants should go in /constants.js (this is the one place where we deviate from keeping things together, as having all actions in one place makes understanding the entire application's potential state changes very straightforward)

  2. The /index.js should mount the application, set up the store, and contain application routing

  3. The /**/index.js in each child folder should contain that part of the state tree's reducer, action constants, and export /**/component.js wrapped by connect() from react-redux

  4. If using Stylus, /style.styl can glob import all child /**/*.styl files so explicit tracking of them is not necessary

  5. Each child /**/*.styl should only contain styles relevant to that view, without side effects

  6. The child /**/component.js should be as simple and "pure" as possible, preferring stateless syntax where possible

  7. If the child does not need a reducer ("pure" subview), /**/component.js can be skipped and si

Keybase proof

I hereby claim:

  • I am yaycmyk on github.
  • I am esj (https://keybase.io/esj) on keybase.
  • I have a public key whose fingerprint is 2E6C 74B2 FFA5 5643 DF68 4FC7 ADFD 2C75 8979 E7E7

To claim this, I am signing this object:

@quantizor
quantizor / ship.rb
Created May 31, 2016 03:33
Part 2 of 2: Send the assembled JSON payload to Coveralls
require 'coveralls'
# Craft the payload...
payload = {
:service_job_id => ENV['TRAVIS_JOB_ID'],
:service_name => 'travis-pro',
:source_files => source_files,
}
Coveralls::API.post_json('jobs', payload)
@quantizor
quantizor / assemble.rb
Last active May 31, 2016 03:31
Part 1 of 2: Merge Cobertura XML & Read the Source Files for Line Coverage
require 'nokogiri'
require 'digest'
files = ARGV
source_files = []
cwd_prefix = Dir.pwd + '/'
unless files.empty?
files.each do |filename|
xml = Nokogiri::XML(File.open(filename).read, 'r')
@quantizor
quantizor / pack_n_ship_to_coveralls.rb
Last active May 31, 2016 03:34
Cobertura XML -> Coveralls via Ruby + Travis CI
require 'coveralls'
require 'nokogiri'
require 'digest'
# converts cobertura xml output into the necessary coveralls JSON payload
# and sends it on its way
# use like `ruby pack_n_ship_to_coveralls.rb xml1.xml xml2.xml xml3.xml`
# replace `ENV['TRAVIS_JOB_ID']` as needed if you don't use Travis CI
@quantizor
quantizor / gist:fb49faa066c837518af0
Created June 25, 2014 01:54
Mortgage Loan Qualification Equation
Total qualified mortgage amount = ( 0.5 - c(m/(1-(1+m)^-n)) - T(c) - I(c) + R((A-d*12)/12) ) / ( m/(1-(1+m)^-n) + T + I )
A = gross annual income
I = decimal insurance rate
R = decimal maximum allowed payment/income ratio based on creditworthiness (44% -> 0.44, etc.)
T = decimal tax rate / 12
c = down payment
d = gross monthly debt
i = decimal interest rate
@quantizor
quantizor / gist:9393261
Created March 6, 2014 16:18
Available Browserstack Browsers (Mar 6, 2014)
[{"os":"Windows","browser":"opera","device":null,"os_version":"8","browser_version":"12.15"},{"os":"Windows","browser":"opera","device":null,"os_version":"8","browser_version":"12.16"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"22.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"23.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"24.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"25.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"26.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"27.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"28.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"29.0"},{"os":"Windows","browser":"chrome","device":null,"os_version":"8","browser_version":"30.0"},{"os":"Wind