Skip to content

Instantly share code, notes, and snippets.

View dotfold's full-sized avatar

James McNamee dotfold

  • NVIDIA
  • Mountain View, CA
View GitHub Profile
exports.watch = function(patterns, excludes, fileList, watchEvents) {
var options = {
ignorePermissionErrors: true,
ignored: createIgnore(excludes)
};
var chokidarWatcher = new chokidar.FSWatcher(options);
watchPatterns(patterns, chokidarWatcher);
var bind = function(fn) {
@dotfold
dotfold / hasPropertiesMatcher.js
Last active December 17, 2015 03:39
jasmine object introspection matcher
beforeEach(function() {
this.addMatchers({
//
// ### function hasProperties expected
// #### @expected Array of Object or single Object with expected key value pairs.
// Custom matcher to verify that the actual object under test contains given
// properties with corresponding values.
//
// The matcher will fail if either the property does not exist, or the values do not match.
(function() {
var debounce = function (callback, wait) {
var timeout,
thisObj;
return function() {
var later = function() {
timeout = null;
callback.apply(thisObj);
@dotfold
dotfold / bsmt.js
Last active December 17, 2015 13:29
binary searchy matchy thingy
(function() {
// Given an array of values, find all exact matches.
// If no matches are found, find the closest match.
//
// Returns an array of indices where matches occur
// If no exact match, a closest match is performed and returned as an array with one element
//
function search(values, desired) {
@dotfold
dotfold / ps.yml
Created June 18, 2013 00:24
project structure
- script
- build
- conf
- app
- css
- images
- js
- dashboard
- media
- controller
@dotfold
dotfold / fix-your-shit.sh
Created May 9, 2014 00:13
overwrite the horrible and unfortunately prevalent "Initial Commit" message
# checkout the root commit
git checkout <sha1-of-root>
# amend the commit
git commit --amend
# rebase all the other commits in master onto the amended root
git rebase --onto HEAD HEAD master
- (void)animateProductImagesIn
{
[self reset];
CGFloat delayAmount = 0.2;
NSUInteger num = [self.productImages count];
for (int i=0; i < num; i ++)
{
UIImageView *view = [self.productImages objectAtIndex:i];
@dotfold
dotfold / RACReplay
Created August 7, 2014 11:46
RAC - replay and multicast resources
Best design pattern for starting only one async operation and share signal result
https://github.com/ReactiveCocoa/ReactiveCocoa/issues/828
http://stackoverflow.com/questions/14066651/how-to-using-reactivecocoa-to-transparently-authenticate-before-making-api-calls/14072445#14072445
http://stackoverflow.com/questions/15075075/when-to-use-racreplaysubject-vs-racmulticastconnection
http://spin.atomicobject.com/2014/06/29/replay-replaylast-replaylazily/
#!/bin/bash
result=$(curl "http://www.gitignore.io/api/$1" 2>/dev/null)
if [[ $result =~ ERROR ]]; then
echo "Query '$1' has no match. See a list of possible queries with '$(basename "$0") list'"
elif [[ $1 = list ]]; then
echo "$result"
else
if [[ -f .gitignore ]]; then
@dotfold
dotfold / videoended-rx.js
Last active August 29, 2015 14:08
Some versions of Android don't dispatch a video ended event. Monitor timeupdate and ended events using Rx.js to determine when either one happens.
//
// Android you suck. Some of your versions don't dispatch
// a video ended event. So the player just hangs on the last frame.
//
// Observables from video element events
var timeObs = Rx.Observable.fromEvent(videoEl, 'timeupdate');
var endedObs = Rx.Observable.fromEvent(videoEl, 'ended');
var endOfVideoByTimeObs = timeObs