Skip to content

Instantly share code, notes, and snippets.

angular.module('ui.router').config(['$provide', function($provide) {
$provide.decorator('$controller', [
'$delegate', '$state',
function($delegate, $state) {
// the `later` and `ident` are private angular variables,
// that break the app if not present
return function(expression, locals, later, ident) {
if ($state.$current) {
locals = _.extend(locals, $state.$current.locals.globals);
}
@gampleman
gampleman / lodash-map-tree.js
Last active August 29, 2015 14:14
Lodash map tree
function Tree(label, branches) {
this.label = label;
this.branches = branches || [];
}
_.mixin({
mapTree: function(tree, fn, thisArg) {
var cb = _.callback(fn, thisArg),
agregate = [];
function recurse(tree) {
@gampleman
gampleman / example.js
Created October 20, 2015 12:22
Making a custom repeater directive in Angular.js
app.directive('readableList', function(Repeater) {
return {
restrict: 'E',
transclude: true,
compile: Repeater.compile('repeat', function($scope, $element, $attr, ctrl, $repeat) {
$repeat.$watch(function(inputList) {
$element.empty();
if (inputList.length == 1) {
$repeat.$transclude(1, inputList[0], null, 0, function(clone) {
@gampleman
gampleman / javascript_examples.js
Created January 15, 2016 15:02
Generic Praxis Code Examples Providers
angular.module('DocBrowser', ['PraxisDocBrowser']).config(function(ExamplesProvider) {
ExamplesProvider.register('browser-javascript', 'JavaScript', function($compile, $action, Documentation, $version) {
return Documentation.info($version).then(function(info) {
var code = 'var request = new XMLHttpRequest();\n\n';
if (!info.endpoint) {
throw 'Endpoint not defined in schema';
}
code += 'request.open(\'' + $action.urls[0].verb +'\', \'' + info.endpoint + $action.urls[0].example + '\');\n\n';
code += _.map($action.headers.type.attributes, function(value, key) {
@gampleman
gampleman / chartkit.js
Last active March 1, 2016 10:48
ChartKit
var origModule = angular.module;
angular.module = function() {
var module = origModule.apply(angular, arguments);
module.chart = function(name, factory) {
return module.directive(name + 'Chart', wrapChart(name + 'Chart', factory));
};
return module;
}
var orig = Highcharts.SVGRenderer.prototype.html;
@gampleman
gampleman / ExampleImplementation.elm
Last active October 13, 2016 14:09
Elm embedded language proposal
macro module ExampleImplementation exposing ([|glsl|], [|r|], [|s|], [|css|])
-- ^ not sure this is necessary
import Elm exposing (AST, ParseError, [|quote|])
import Result
import Regex.Parser -- hypothetical module
[|r|] : String -> Result ParseError AST
[|r|] s =
@gampleman
gampleman / readme.md
Created January 13, 2017 17:16
A better SVG Library for Elm

Introduction

Here is the begenning of a proposal for a better SVG library. I introduce some of the motivation and lead with a couple of examples. Then I present the new types that would be used in this library. Finally, I go through a number of SVG attributes to show how they would look and give breif justification to the changes. This last part is not complete, as there are hundreds of these attributes and I wanted to get some feedback on this document before progressing further.

@gampleman
gampleman / FunctionFuzzers.elm
Created August 4, 2017 12:36
Function Fuzzers
module FunctionFuzzers exposing (..)
import Fuzz exposing (Fuzzer)
import Test.Runner exposing (fuzz)
import Shrink
import Random.Pcg as Random
import Murmur3
function : Fuzzer a -> Fuzzer (b -> a)
@gampleman
gampleman / Main.elm
Created March 8, 2018 13:58
VDOM in Pure Elm + Ports
module Main exposing (main)
import MyHtml exposing (program, text, a, onClick, div)
type Msg
= Inc
| Dec
@gampleman
gampleman / Collection.elm
Created March 30, 2018 09:44
A module that abstracts over common collection types
module Collection
exposing
( Collection
, isEmpty
, length
, head
, tail
, take
, drop
, slice