Skip to content

Instantly share code, notes, and snippets.

const HelpText = (props) =>
<div {...props} style={css`
font-family: Helvetica;
padding: 10px;
background-color: white;
border: 1px inset #ccc;
`} />;
const state = observable({ value: 0 });
// texgen.js - http://github.com/mrdoob/texgen.js
let TG={OP:{SET:function(a,b){return b},ADD:function(a,b){return a+b},SUB:function(a,b){return a-b},MUL:function(a,b){return a*b},DIV:function(a,b){return a/b},AND:function(a,b){return a&b},XOR:function(a,b){return a^b},MIN:function(a,b){return Math.min(a,b)},MAX:function(a,b){return Math.max(a,b)}},Texture:function(a,b){this.color=new Float32Array(4);this.buffer=new TG.Buffer(a,b);this.bufferCopy=new TG.Buffer(a,b)}};
TG.Texture.prototype={constructor:TG.Texture,set:function(a,b){void 0===b&&(b=TG.OP.SET);this.bufferCopy.copy(this.buffer);var c=["var x = 0, y = 0;\nvar array = dst.array;\nvar width = dst.width, height = dst.height;\nfor ( var i = 0, il = array.length; i < il; i += 4 ) {","\t"+a.getSource(),"\tarray[ i ] = op( array[ i ], color[ 0 ] * tint[ 0 ] );\n\tarray[ i + 1 ] = op( array[ i + 1 ], color[ 1 ] * tint[ 1 ] );\n\tarray[ i + 2 ] = op( array[ i + 2 ], color[ 2 ] * tint[ 2 ] );\n\tif ( ++x === width ) { x = 0; y ++; }\n}"].join("\n");
(
const show = (children) =>
<svg style={{border:'1px solid #ccc', height:500}}>{children}</svg>
const circles = _.range(20).map(x => {
return <circle
cx={25 + x * 25}
cy={x % 2 == 0 ? 45 : 20}
fill="black"
r={10} />
});
class Canvas extends React.Component {
componentDidMount() {
this.props.draw(this.refs.a.getContext('2d'));
}
render() {
const { width, height } = this.props;
return <canvas ref='a'
width={width}
height={height}
style={{width, height}}/>
@JakeCoxon
JakeCoxon / index.js
Last active March 26, 2022 20:51
Firebase Mobx
import _ from 'https://npmcdn.com/lodash@4.15.0'
import 'https://npmcdn.com/firebase@3.3.0/firebase.js'
var config = {
apiKey: "AIzaSyCNV9EVtgHpNCHJoRe8xwkCRIpKZ3IFI_M",
authDomain: "example-app-ccfdb.firebaseapp.com",
databaseURL: "https://example-app-ccfdb.firebaseio.com",
storageBucket: "",
@JakeCoxon
JakeCoxon / ramda-bind.js
Last active August 5, 2016 14:56
Wrap ramda to work nice with the bind operator
import ramda from 'ramda'
import Immutable from 'immutable'
const applyWildcard = (array, val) => {
const wildIndex = ramda.findIndex(x => x === __, array);
return wildIndex > -1 ? ramda.update(wildIndex, val, array) : array.concat([val]);
}
const toThisFunction = (func) => {
return _.isFunction(func) ? function(...args) {
Array.apply(null, Array(15))
.map((_, i) => i + 1)
.map(i =>
[i, "Fizz", "Buzz", "FizzBuzz"][!(i % 3) + 2*!(i % 5)]
)
.forEach(::console.log)
a() {
local cmd
cmd="$(alias | sed "s/^alias \(..*\)=\'\(.*\)\'/\1#\2/" | column -t -s $'#' 2> /dev/null | fzf | sed "s/^[^ ]* *//")"
if [ -n "$cmd" ]; then
echo $cmd
eval $cmd
fi
}
ffmpeg -i input.mov -filter:v "setpts=2.0*PTS" -s 187x333 -pix_fmt rgb8 -r 10 -f gif - | gifsicle --optimize=3 > out.gif
# Explanation
ffmpeg -i input.mov \ # Input file
-filter:v "setpts=2.0*PTS" \ # Scale time 2x
-s 187x333 \ # Set pixel size
-pix_fmt rgb24 \ # Pixel format
-r 10 \ # Set framerate
-f gif - | \ # Output gif format
gifsicle \ # Optimize the ffmpeg gif
@JakeCoxon
JakeCoxon / store-component.js
Last active August 29, 2015 14:19
Higher-order Hoverboard Store Component
import React from 'react';
export default Store => ComposedComponent => React.createClass({
getInitialState() {
return Store.getState();
},
componentDidMount() {
this.unsubscribe = Store.getState(state => this.setState(state));