Skip to content

Instantly share code, notes, and snippets.

@ArthurClemens
ArthurClemens / m_omdb.erl
Last active August 3, 2016 02:33
Zotonic template model for the OMDB movie database - source code to accompany the documentation
-module(m_omdb).
-behaviour(gen_model).
-export([
m_find_value/3,
m_to_list/2,
m_value/2
]).
-include_lib("zotonic.hrl").
@ArthurClemens
ArthurClemens / bundle.js
Created May 12, 2016 12:30
React JS hello world
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
'use strict';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, stati
@ArthurClemens
ArthurClemens / gist:1b06a661c14bdb369f7c
Last active March 19, 2016 20:24
Mithril simple router wrapper
var router = function(component, name) {
return {
controller: function() {
// Do something generic like calling Google Analytics from here
console.log("router", name);
return new component.controller();
},
view: component.view
};
};
@ArthurClemens
ArthurClemens / github-repos.es6.js
Created September 23, 2015 21:08
Example of mithril-infinite and retrieving json data from a server
'use strict';
import m from 'mithril';
import infinite from 'mithril-infinite';
const item = (data) => {
return m('.item',
{
style: {
background: '#eee',
@ArthurClemens
ArthurClemens / plural
Created June 12, 2015 15:01
Plural rule parser
/*
This code uses a regular expression to make the json safer.
An potentially safer alternative is https://github.com/joewalnes/filtrex (untested) at the cost of 130Kb.
Can be used for example with this JSON structure:
{
"_meta_po_header": "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
"COLLECTION_CONTENTS[0]": "Kolekcja zawiera %@ przepis.",
"COLLECTION_CONTENTS[1]": "Kolekcja zawiera %@ przepisy.",
"COLLECTION_CONTENTS[2]": "Kolekcja zawiera %@ przepisów."
%% @doc
%% Filter module for Zotonic
%% 'foldl' filter, applies foldl to a list
%%
%% Usage:
%% {{ [1,2,3]|foldl:["*", 1] }}
%% {{ [1,2,3]|foldl:["+", 0] }}
%% {{ ["a", "b", "c"]|foldl:["++", ""] }}
%%
%% Pass an attribute to fetch for each item: