Skip to content

Instantly share code, notes, and snippets.

View cobbweb's full-sized avatar

Andrew Bucknall cobbweb

  • QLD, Australia
  • 06:30 (UTC +10:00)
View GitHub Profile
@cobbweb
cobbweb / flatMap.ts
Created November 23, 2018 04:15 — forked from kakajika/flatMap.ts
Array.prototype.flatMap method in TypeScript.
interface Array<T> {
flatMap<E>(callback: (t: T) => Array<E>): Array<E>
}
Object.defineProperty(Array.prototype, 'flatMap', {
value: function(f: Function) {
return this.reduce((ys: any, x: any) => {
return ys.concat(f.call(this, x))
}, [])
},
@cobbweb
cobbweb / lazyload-child.js
Created December 9, 2015 04:43
Lazyload Children
(function(window) {
'use strict';
var raf = window.requestAnimationFrame;
var CLOSESNESS = 2;
function startLoop(fn) {
var running = false;
var lastExit;
(function(window) {
'use strict';
window.SrcSet = {
/**
* Converts srcset value into JS objects
* e.g. './image1.jpg 1100w, ./image1_big.jpg 1500w, ./image1_small.jpg'
* yields:
* [
* { src: './image1.jpg', width: 1100 },
@cobbweb
cobbweb / TodoStore.js
Created February 17, 2015 06:22
Reactive data layers with Flux
var alt = require('../alt');
var TodoActions = require('./TodoActions');
// Reactive data layer
var Todos = alt.Todos;
class TodoStore {
constructor() {
this.bindActions(TodoActions);
@cobbweb
cobbweb / ipdb.sublime-snippet
Created February 5, 2014 08:07
Sublime Text snippet to insert an ipdb breakpoint with set_trace()
<snippet>
<!-- Example: Hello, ${1:this} is a ${2:snippet}. -->
<content><![CDATA[
import ipdb; ipdb.set_trace()
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>ipdb</tabTrigger>
<description>Set an ipdb breakbpoint with ipdb.set_trace</description>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.python, keyword.control.import.python</scope>
@cobbweb
cobbweb / index.html
Created January 16, 2014 03:41
Demonstrating Sir Trevor Format Bar inside a scrolling element/container
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">
@cobbweb
cobbweb / listeners-demo.js
Last active January 2, 2016 10:48
Idea for listening to objects in a view, runs after `initialize` so you can add custom vent objects too.
var MyView = Marionette.ItemView.extend({
listeners: {
model: {
'add': 'modelAdd'
},
collection: {
'reset': 'reset'
},
appVent: {
@cobbweb
cobbweb / nav.js
Created December 20, 2012 04:10
Event-based nav object
MyApp.module('Nav', function(Nav, App) {
'use strict';
var render = Marionette.Renderer.render;
Nav.Navbar = Marionette.ItemView.extend({
template: 'nav/templates/navbar',
initialize: function()
@cobbweb
cobbweb / app.js
Created November 23, 2012 03:26
Queued Triggers in Backbone.Events
App.module('ModuleOne', function(ModuleOne, App) {
var members = new Backbone.Collection();
members.on('reset', function() {
App.vent.queueTrigger('moduleone:members:reset', members);
});
members.fetch();
@cobbweb
cobbweb / backbone.collectioncache.js
Created November 8, 2012 23:38 — forked from tbranyen/backbone.collectioncache.js
Backbone.Collection caching by URL
/*!
* backbone.collectioncache.js v0.0.2
* Copyright 2012, Tim Branyen (@tbranyen)
* backbone.collectioncache.js may be freely distributed under the MIT license.
*/
(function(window) {
"use strict";
// Dependencies