Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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) {
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 / readme.md
Last active August 29, 2015 14:07
JS Build tool of my dreams

Features desired

(but not necessarily found elsewhere)

Must Have

  1. Native Sourcemap support: JavaScript and CSS often need these for debugging purposses. Managing this manually tends to be a complete PITA. Also we want a way to globally turn these off, if we need better build time (see next).
  2. Native Watch & Serve: Setting up a dev environment should be straightforward, as the build tool should support mutliple environments, but also the abbility to watch source files and serve them from itself.
  3. Lazy: Shouldn't rebuild stuff if it doesn't need to.
  4. Native concurrency: Detect dependencies and parallelize automatically.
@gampleman
gampleman / README.md
Created September 10, 2014 03:08
Algorithm to find a short unique CSS selector from an arbitrary node

This algorithm when passed a DOM node will find a very short selector for that element.

@gampleman
gampleman / tracking_interceptor.md
Last active June 19, 2020 21:34
Adding tracking to emails in Rails

This gist illustrates how you would add Google Analytics tracking into your Rails mailers. Add the tracking_interceptor.rb into your path and enable it for your mailers with:

register_interceptor TrackingInterceptor