Skip to content

Instantly share code, notes, and snippets.

View andreypopp's full-sized avatar
🏠
Working from home

Andrey Popp andreypopp

🏠
Working from home
View GitHub Profile
@chenglou
chenglou / gist:40b75d820123a9ed53d8
Last active March 13, 2024 12:14
Thoughts on Animation

Interesting part (unmounting & API) is at the end if you're not interested in the rest =).

Stress Tests

This animation proposal is just an attempt. In case it doesn't work out, I've gathered a few examples that can test the power of a future animation system.

  1. Parent is an infinitely spinning ball, and has a child ball that is also spinning. Clicking on the parent causes child to reverse spinning direction. This tests the ability of the animation system to compose animation, not in the sense of applying multiple interpolations to one or more variables passed onto the child (this should be trivial), but in the sense that the parent's constantly updating at the same time as the child, and has to ensure that it passes the animation commands correctly to it. This also tests that we can still intercept these animations (the clicking) and immediately change their configuration instead of queueing them.

  2. Typing letters and let them fly in concurrently. This tests concurrency, coordination of an array of ch

@gordonbrander
gordonbrander / min-event-behavior.js
Last active August 21, 2018 11:57
Minimal FRP events and behaviors
// Minimal FRP Behaviors and Events.
// An event function is any function of shape `function (next) { ... }` where
// `next(value)` is a callback to be called by event function. Transformations
// of event are accomplished by wrapping event with another event function,
// and consuming original event within (CPS).
// A behavior is any function of shape `function (time) { ... }`, where
// `time` is current time. Behaviors may capture state, return value from time,
// or be constant. Behaviors must always return a value, but value may
@chenglou
chenglou / gist:8701065
Last active August 29, 2015 13:55
CommonJS-style Asset Bundling

The rough underlying implementation is more or less done. Right now we're deciding betwen two forms, require('a.png') vs. requireStatic('a.png').

require('a.png')

  • Pros: more familiar. One single require for assets too.
  • Cons: Doesn't follow the CommonJS specs. Overloads require.

requireStatic('a.png')

  • Pros: isn't tied to CommonJS.
  • Cons: another thing to learn.
@petehunt
petehunt / gist:8396968
Created January 13, 2014 09:14
Sweet.js DSL for making persistent data structures feel imperative
macro := {
rule infix { $obj $([ $key ] ...) | $rval:expr } => {
$obj = mori.assoc_in($obj, [$key (,) ...].reverse(), $rval)
}
}
macro hash_map {
rule {{ $($key : $value) (,) ... }} => {
mori.hash_map($($key, $value) (,) ...)
}
@jpillora
jpillora / di.coffee
Last active April 30, 2018 01:21
Micro JavaScript Dependancy Injection.Written in CoffeeScript / JS.This is *approximately* how AngularJS works.
# Micro JavaScript Dependancy Injection
define = (name, val) ->
#init modules map if missing
define.mods = define.mods or {}
#store 'name'
define.mods[name] = val
inject = (fn) ->
#regex match on function.toString()
@Raynos
Raynos / delayed-computation.md
Last active March 19, 2019 00:01
Delayed computation

Programming with delayed computation

A delayed computation is a function that will do some computation when called. Because of the delayed nature the computation may be asynchronous so the function takes a callback.

Note: the term "delayed computation" is just a temporary name so we can talk about this idea, I do not recommend using this name as it's a) confusing and b) this concept is hard to name.

@lalinsky
lalinsky / ingest.php
Created April 18, 2012 20:34
Simple audio fingerprint matching in PHP
<?php
include "utils.php";
$fp = parse_fp($_GET['fp']);
$dbh = new PDO('mysql:host=localhost;dbname=fingerprint', 'fingerprint');
$dbh->beginTransaction();
$sth = $dbh->prepare("INSERT INTO fp (length) VALUES (?)");
anonymous
anonymous / bootstrap-typeahead-backbone.js
Created February 5, 2012 13:36
bootstrap typeahead with backbone
/* =============================================================
* bootstrap-typeahead-backbone.js v2.0.0
* http://twitter.github.com/bootstrap/javascript.html#typeahead
* https://github.com/twitter/bootstrap/blob/master/js/bootstrap-typeahead.js
* Modified by Marius Andreiana to work with Backbone Collection, Model, View
* - custom results formatting
* - custom behavior on selected item (Model with complex information)
* =============================================================
* Copyright 2012 Twitter, Inc.
*
import reflect.{Manifest, ClassManifest}
import org.scalatest.matchers.{Matcher,MatchResult}
trait CustomMatchers {
/**
* Based on http://daily-scala.blogspot.com/2010/01/overcoming-type-erasure-in-matching-1.html
*/
class ConformMatcher[A](implicit m: Manifest[A]) extends Matcher[AnyRef] {
override def apply(obj: AnyRef) = {
def deepConformance[B,C](desired: Manifest[B], actual: Manifest[C]): Boolean = {
def substract(i:Int)=extension{
//owner represents the object you are extending
owner:Int =>
{
owner-i
}
}
//operator tild ~ instead of . for extensions
1~substract(2)~substract(1)~substract(1)