Skip to content

Instantly share code, notes, and snippets.

@maisano
maisano / RouteTransition.jsx
Last active September 15, 2023 07:29
Using react-motion with react-router
import React, { PropTypes } from 'react';
import { TransitionMotion, spring } from 'react-motion';
/**
* One example of using react-motion (0.3.0) within react-router (v1.0.0-rc3).
*
* Usage is simple, and really only requires two things–both of which are
* injected into your app via react-router–pathname and children:
*
* <RouteTransition pathname={this.props.pathname}>
var s = context.selection
var v = context.document.currentView()
var r = v.totalRectForLayers(s)
var artboard = [[MSArtboardGroup alloc] initWithFrame:r];
var page = context.document.currentPage();
[page addLayers:[artboard]];
[artboard setGrid:[page grid]];
@bendc
bendc / recursion.js
Created May 21, 2015 08:17
Functional loop
const loop = (() => {
const recur = (callback, count, i=0) => {
if (i == count-1) return callback(i);
callback(i);
return recur(callback, count, i+1);
};
return (callback, count) => {
if (count > 0) return recur(callback, count);
};
})();
static inline uint8_t RHeight(void)
{
// Assuming probability 1/2 of an element appearing in layer i also appearing in layer i + 1
// We can do the usual toss-the-coin dance, or we can just use RNG once and count the trailing zeros.
// Instead of using a loop to count, we can isolate the rightmost 0-bit, turn off all bits and sets that bit to 1, and then
// just compute count of trailing zeros instead.
const auto r = rand();
const auto v = ~r & (r + 1);
const uint8_t tz = __builtin_ctz(v);
@bomberstudios
bomberstudios / svgo-sketch.sh
Created April 16, 2015 14:07
SVGo options to clean up Sketch's SVG files without destroying them
svgo --pretty --enable=removeTitle --enable=removeDesc --enable=removeDoctype --enable=removeEmptyAttrs --enable=removeUnknownsAndDefaults --enable=removeUnusedNS --enable=removeEditorsNSData -f folder_with_svg_files
@WebReflection
WebReflection / csp
Last active November 11, 2020 00:08
Generates the right sha1 and sha256 for Content Security Policy aware scripts
#!/usr/bin/env bash
echo ''
if [ "$1" = "" ]; then
echo 'csp sha1 and sha256 generatoor'
echo 'csp "code"'
echo 'csp /file-name'
else
if [ -f "$1" ]; then
CONTENT=$(cat $1)
@Couto
Couto / webpack.js
Last active November 11, 2020 17:53
Fetch polyfill with webpack
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var path = require('path');
var folders = {
APP: path.resolve(__dirname, '../app'),
BUILD: path.resolve(__dirname, '../build'),
BOWER: path.resolve(__dirname, '../bower_components'),
NPM: path.resolve(__dirname, '../node_modules')
};
@danharper
danharper / gulpfile.js
Last active April 11, 2024 08:31
New ES6 project with Babel, Browserify & Gulp
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var watchify = require('watchify');
var babel = require('babelify');
function compile(watch) {
var bundler = watchify(browserify('./src/index.js', { debug: true }).transform(babel));
@sebmarkbage
sebmarkbage / Enhance.js
Last active January 31, 2024 18:33
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@bendc
bendc / functional-utils.js
Last active September 15, 2023 12:12
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)