Skip to content

Instantly share code, notes, and snippets.

View quantizor's full-sized avatar
🦾

Evan Jacobs quantizor

🦾
View GitHub Profile
@quantizor
quantizor / placeholderPoof.js
Created April 8, 2013 21:00
Make placeholders disappear on focus, instead of when you start typing. (jQuery)
;(function($){
$(document).ready(function(){
var x = $('[placeholder]');
for( var i=0, len=x.length; i<len; i++ ){
x.eq(i).attr('data-placeholder', x.eq(i).attr('placeholder'));
}
x.on('focus', function(){ $(this).attr('placeholder', ''); })
@quantizor
quantizor / videoIDExtractor.js
Last active October 30, 2018 12:49
Javascript regex to extract the ID out of YouTube, Vimeo and Instagram video URLs.
// Interactive breakdown at: https://www.debuggex.com/r/6zmlYhT6GVcEn-rh
var re = /^.*?(?:youtube\.com\/(?:watch\?v=|embed)/?|\/vimeo\.com\/|player\.vimeo\.com\/video\/|instagram\.com\/p\/)(.*?)\/?$/;
@quantizor
quantizor / angular-aspected-dfd.js
Last active August 29, 2015 13:56
Aspected DFD - get before & after functionality for your Angular $http requests
/*
This function allows you to define things happen before and after the receiving
controller actually gets its data.
Useful for caching the result set locally in a service.
After comes prior to before because we want don't want to delay return of data to the
controller unless absolutely necessary.
Requires access to $q.
@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
@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 / 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 / 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 / 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)

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 / 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