Skip to content

Instantly share code, notes, and snippets.

@ArthurClemens
ArthurClemens / sphinx.hs
Created November 17, 2012 22:34
Yesod Sphinx search example
{-
Sphinx setup:
---
Download the latest version from http://sphinxsearch.com/downloads/release/
---
Backup the original conf file at /etc/sphinxsearch/sphinx.conf and create a new one with:
source searcher_src {
type = xmlpipe2
xmlpipe_command = curl http://localhost:3000/search/xmlpipe
%% @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:
@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 / 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 / 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."
@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',
// app/redux/action-creators.es6.js
import {SET_ROUTE} from 'app/redux/action-types';
export const setRoute = (route) => {
return {
type: SET_ROUTE,
route
};
};
@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 / multipart-upload.erl
Created September 17, 2016 12:07
Erlang: upload data using multipart/form-data
%% Usage:
%% upload_request(<<"site.com/api/upload">>, <<"path/to/file.png">>, <<"upload">>, <<"image/png">>, [], <<"some-token">>)
%%
%% Usage with RequestData:
%% Payload = [{upload_type, <<"user_picture">>}],
%% PayloadContent = jsx:encode(Payload),
%% RequestData = [
%% {<<"payload">>, PayloadContent}
%% ]
%% upload_request(<<"site.com/api/upload">>, <<"path/to/file.png">>, <<"upload">>, <<"image/png">>, RequestData, <<"some-token">>)
https://flems.io/#0=N4IgZglgNgpgziAXAbVAOwIYFsZJAOgAsAXLKEAGhAGMB7NYmBvAHgBMIA3AAgjYF4AOiABOtWsWEA+FgHoOnKYLTKWcaiIgAHYtzgjqQkCWJa4iWbJEYA7gHMIxfHSyyAgi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