Skip to content

Instantly share code, notes, and snippets.

View justsml's full-sized avatar
🔥
#BLM

Dan Levy justsml

🔥
#BLM
View GitHub Profile
dialog {
position: fixed;
top: 50%;
left: 50%;
right: auto;
padding: 30px;
transform: perspective(500px) translate(-50%, -50%);
background: linear-gradient(to bottom, #FFF, #F4F4F4) #FFF;
border: none;
border-radius: 3px;
@justsml
justsml / PinchZoomPan.js
Last active October 4, 2017 14:09 — forked from iammerrick/PinchZoomPan.js
React Pinch + Zoom + Pan
import React from 'react';
const MIN_SCALE = 1;
const MAX_SCALE = 4;
const SETTLE_RANGE = 0.001;
const ADDITIONAL_LIMIT = 0.2;
const DOUBLE_TAP_THRESHOLD = 300;
const ANIMATION_SPEED = 0.04;
const RESET_ANIMATION_SPEED = 0.08;
const INITIAL_X = 0;
const makeRequest = () => {
return getJSON()
.then(data => data.needsAnotherRequest
? makeAnotherRequest(data)
: data)
.then(data => console.log(data) || data)
}
@justsml
justsml / events.js
Last active October 28, 2016 03:03 — forked from dhigginbotham/events.js
const EventEmitter = require('events');
class Eventry extends EventEmitter {
constructor(type = 'none', ...args) {
super(args);
this.type = type;
}
// overload .on and .emit func to
// support special event syntax
on(ev, fn) {
// transformy is an object mapping tool to
// transform objects to another object defaults
function transformy({ mutate = {}, input = {}, schema = {}, omit = [], loose = true }) {
return Object.keys(input).map((key) => {
const mutated = {};
const tkey = mutate.hasOwnProperty(key) ? mutate[key] : null;
if (omit.indexOf(key) !== -1) return mutated;
if (typeof input[key] !== 'undefined' && schema.hasOwnProperty(tkey)) {
mutated[tkey] = input[key];
} else if (typeof schema[key] !== 'undefined') {
@justsml
justsml / README.md
Created July 14, 2016 21:42 — forked from joshdover/README.md
Idiomatic React Testing Patterns

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

@justsml
justsml / fun-with-bluebird-promise-patterns.js
Last active February 4, 2016 02:15 — forked from domenic/not-bad-code.js
Avoiding explicit promise construction antipattern. Added bluebird.js secret sauce.
// Promises are great, but bluebird covers :allthethings
var Promise = require('bluebird');
var appContext = {ready: false, error: false};
const INVALID_CTX = {ready: false, error: true, message: 'App or User not initialized'};
// Bluebird-ify around `fetch` API
function getUser(username) {return Promise.resolve('users/' + username + '.json').then(fetch);}
function initApp(username) {
// Use bluebird to do some real-world-ish code:
@justsml
justsml / test.js
Last active January 8, 2016 01:46 — forked from dhigginbotham/adobeAnalyticsInspection.js
sometimes I need to know what vars/events/props are getting sent off to omniture / sitecatalyst / adobe analytics or whatever they renamed themselves to again :neckbeard: I got the awesome list of params from http://www.cheatography.com/dmpg-tom/cheat-sheets/adobe-analytics-omniture-sitecatalyst-parameters/pdf/
var tap = require('tap');
var locationify = require('..');
tap.test('full URLs', function (t) {
t.similar(locationify('https://github.com/justsml#top'), {
host: 'github.com',
hash: '#top',
path: '/justsml',
});
// call t.end() when you're done
@justsml
justsml / virustotal_upload
Last active November 9, 2015 00:59 — forked from luca-m/virustotal_upload
Upload a sample to VirusTotal and pretty print the report. All in a handy alias.
#!/bin/bash
# Upload a sample to VirusTotal and pretty print the report. All in a handy alias.
#
# Dependecies:
#
# * python > 2.7
# * pip install Pygments==1.4
# * curl
# * VirusTotal API key
@justsml
justsml / object-watch.js
Created April 1, 2012 22:48 — forked from eligrey/object-watch.js
object.watch polyfill
// Cross-browser object.watch and object.unwatch
// object.watch
if (!Object.prototype.watch) {
Object.prototype.watch = function (prop, handler) {
var oldval = this[prop], newval = oldval,
getter = function () {
return newval;
},
setter = function (val) {