Skip to content

Instantly share code, notes, and snippets.

@kwijibo
kwijibo / ramda-docs.md
Last active February 8, 2016 19:21
Strawman Ramda docs intro

#Datatypes

##Functions

Curried

When call a function with only some of its arguments, you get back a partially-applied function that only expects the remainding arguments: const add1 = R.add(1) // function add1(){...

Placeholders

@kwijibo
kwijibo / app-submit-example.js
Last active February 6, 2016 22:43
Future that can have a value applied to its map function
// submit :: event -> IO[ HttpGet[ Either [ HttpPost []]]]
const submit = (event) => {
return getFormFields()
.map(incrementVersionNumber)
.map(saveRecord)
}
// getFormFields :: () -> IO
const getFormFields = () => IO(()=>{
return lift()
map(f,g)(x) //map(pipe(f,g), x)
filter(f,g)(x) //filter(allPass(f,g), x)
pipeP(f,g)(handleError)(x) //pipe(pipeP(f,g), p=>p.catch(handleError))(x)
cond([f1,a1], [f2,a2])(x) //cond([[f1,a1], [f2,a2]], x)
// httpGET :: url -> HttpGET
const httpGET = (url) => {
let transform = x => x
const GET = {
url: url,
map: (f) => {
transform = x => f(transform(x))
return GET
},
fork: (reject,resolve) => {
@kwijibo
kwijibo / turtle-serialiser.js
Last active December 3, 2015 18:00
RDF/JSON -> Turtle serialiser w/ Ramda
var prepend = first => second => first + second
, prefix = (item, i) => `@prefix n${i}: <${item}> . \n`
, mapI = R.addIndex(R.map)
, insertIndex = (ns,uri) => ns.push(uri)-1
, nsEnd = uri => Math.max(uri.lastIndexOf('#'), uri.lastIndexOf('/')) +1
, lookup = ns => uri => { const i = ns.indexOf(uri); return 'n' + (i>-1)? i : insertIndex(ns,uri) }
, change0 = R.over(R.lensIndex(0))
, change1 = R.over(R.lensIndex(1))
, literal = ({value,lang,datatype}) => '"'+ value.replace(/("|\n)/g,'\\$1') + '"'+langTag(lang)+dataType(datatype)
, langTag = lang => lang? '@'+lang : ''
@kwijibo
kwijibo / wordcount-app.ttl
Last active December 14, 2015 07:59
functional program as triples in turtle (an ugly reinvention of Prolog?)
@prefix R: <npm:ramda/0.18.0> . #(made up) npm protocol to define the module as a namespace
@prefix r: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix : <#> . #this will be the namespace defining the lang-specific terms like :Text, :Fun1
@prefix owl: <#...> . #whatever the owl prefix is...
#functions are relationships, aka predicates, aka properties, between inputs and outputs
:STDOUT <app> :STDIN .
#owl:propertyChainAxiom is a composition of properties/predicates
<app> owl:propertyChainAxiom (
@kwijibo
kwijibo / equal-tempered-scale-frequencies.json
Created November 8, 2015 22:19
Frequencies for equal-tempered scale, A4 = 440 Hz in JSON
{"C0":16.35," C#0/Db0 ":17.32,"D0":18.35," D#0/Eb0 ":19.45,"E0":20.6,"F0":21.83," F#0/Gb0 ":23.12,"G0":24.5," G#0/Ab0 ":25.96,"A0":27.5," A#0/Bb0 ":29.14,"B0":30.87,"C1":32.7," C#1/Db1 ":34.65,"D1":36.71," D#1/Eb1 ":38.89,"E1":41.2,"F1":43.65," F#1/Gb1 ":46.25,"G1":49," G#1/Ab1 ":51.91,"A1":55," A#1/Bb1 ":58.27,"B1":61.74,"C2":65.41," C#2/Db2 ":69.3,"D2":73.42," D#2/Eb2 ":77.78,"E2":82.41,"F2":87.31," F#2/Gb2 ":92.5,"G2":98," G#2/Ab2 ":103.83,"A2":110," A#2/Bb2 ":116.54,"B2":123.47,"C3":130.81," C#3/Db3 ":138.59,"D3":146.83," D#3/Eb3 ":155.56,"E3":164.81,"F3":174.61," F#3/Gb3 ":185,"G3":196," G#3/Ab3 ":207.65,"A3":220," A#3/Bb3 ":233.08,"B3":246.94,"C4":261.63," C#4/Db4 ":277.18,"D4":293.66," D#4/Eb4 ":311.13,"E4":329.63,"F4":349.23," F#4/Gb4 ":369.99,"G4":392," G#4/Ab4 ":415.3,"A4":440," A#4/Bb4 ":466.16,"B4":493.88,"C5":523.25," C#5/Db5 ":554.37,"D5":587.33," D#5/Eb5 ":622.25,"E5":659.25,"F5":698.46," F#5/Gb5 ":739.99,"G5":783.99," G#5/Ab5 ":830.61,"A5":880," A#5/Bb5 ":932.33,"B5":987.77,"C6":1046.5," C#6/D
@kwijibo
kwijibo / sample-ramda.js
Created June 30, 2015 22:04
Some code I wrote using ramda.js
//getFieldDefinition :: key -> [a] -> a
var getFieldDefinition = r.useWith(
r.find, // #final function :: Relation -> [a] -> a
r.propEq(1), //takes `key` where [1]==key #function for 1st param
r.identity //#placeholder func for 2nd param
)
// getFieldSpec :: String -> Object
// getFieldSpec('duration')
// > {type:'number', max:60, min: 1}

#Dynamic Linked Data

status: DRAFT,EXPERIMENTAL

Traditional Linked Data is not very "browsable" and does not provide a way to get from a resource to a list of things of the same type, or from a page about a book to a list of books by the same author.

SPARQL is a powerful query language, but it is difficult to write queries without knowledge of both the dataset, and SPARQL. It is not always practical to provide a SPARQL endpoint for every dataset that publishes as Linked Data.

This document describes a simple HTTP-based query system for Linked Data to fill the gap between static documents and SPARQL.

@kwijibo
kwijibo / TurtleDataFormat.md
Last active March 21, 2017 02:50
Although Turtle was invented as a way of serialising RDF, it can be thought of as a more general purpose data format, competing with formats like JSON, XML and YAML. It can handle dictionaries, lists, strings, numbers, local identifiers, and URIs.

#Why

##Structure

The basic structure that Turtle is built on is Entity Attribute Value. An entity can be thought of as a named set of key-value pairs.

  • entities are represented by identifiers.
  • attributes (properties) are also represented by identifiers (this allows the semantics of an attribute to be described, if so wished)
  • values may be an identifier (of an entity), a string, a number, or an ordered list.