Skip to content

Instantly share code, notes, and snippets.

View bergie's full-sized avatar

Henri Bergius bergie

View GitHub Profile
@bergie
bergie / extract.coffee
Created August 18, 2014 10:20
Extract inline FBP graphs to files
fs = require 'fs'
jsdom = require 'jsdom'
writeGraph = (id, content) ->
console.log id
content = content.replace /\&gt\;/g, '>'
content = content.replace /\n[\s]*/g, '\n'
content = content.replace /local\//g, 'ui/'
fs.writeFileSync "graphs/#{id}.fbp", content
@bergie
bergie / noflo.json
Last active August 29, 2015 14:05
NoFlo spring loop
{
"properties": {
"name": "Spring demo",
"id": "esr4k",
"environment": {
"type": "noflo-browser",
"content": "<style>\n img {\n width: 100px;\n height: 100px;\n position: absolute;\n top: 100px;\n left: 150px;\n }\n</style>\n<img src=\"http://nextnature.net/wp-content/uploads/2009/12/mcluhan-5301.jpg\">"
}
},
"inports": {},
@bergie
bergie / my-awesome-styles.gss
Created October 17, 2014 10:48
GSS example
@horizontal .TutorialPage gap(0);
.TutorialPage {
x :>= 0;
y :>= 0;
width:== ::window[width];
height:== ::window[height];
}
import network, util
from util import exceptions
from gettext import lgettext as _
PROTOCOL_INFO = {
"name": "Qaiku",
"version": "1.0",
"config": [
"private:password",
<?php
if (count($argv) != 2)
{
die("Usage: php quick_init.php midgardconffile\n");
}
if (!extension_loaded('midgard2'))
{
die("Midgard2 is not installed in your PHP environment.\n");
}
@bergie
bergie / blog.markdown
Created January 15, 2011 11:08
Blog post in Midgard MVC

A blog in Midgard Create

This is an example of how to create a blog system powered by the Midgard Create web editing tool. This example follows the principles of literate programming, meaning that it is not only a human-readable document but can also be used to construct the full running blog system using the code examples inside this file.

As this blog system is an example application, we will call it net_example_blog. This will be used as a namespace in PHP classes and global variables.

Our blog post

To be able to store and display blog posts we have to first define a persistent storage for them. Midgard MVC itself is not in way tied to any storage solution, but in this case we will use the Midgard2 content repository for our data persistence needs. Midgard2 is an object-oriented content store that can be accessed from various programming languages including PHP, Python and Vala.

@bergie
bergie / evented.php
Created March 4, 2011 13:44
Event-driven programming example with PHP5 and Midgard2
<?php
// Open Midgard connection
$config = new midgard_config();
$config->read_file_at_path(ini_get('midgard.configuration_file'));
// Do stuff when we get a DB connection
midgard_connection::get_instance()->connect('connected', function($connection) {
echo "Connected, Midgard version " . mgd_version() . "\n";
});
if (typeof jQuery == 'undefined') {
var jQ = document.createElement('script');
jQ.type = 'text/javascript';
jQ.onload=loadDeps;
jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js';
document.body.appendChild(jQ);
} else {
loadDeps();
}
function loadDeps() {
@bergie
bergie / README.md
Created December 28, 2011 16:57
Midgard2 GIR examples

Some examples of Midgard2 GIR usage

@bergie
bergie / buildfilename.fbp
Created July 13, 2012 16:35
JSON-LD to Jekyll converter with NoFlo
# We need to process the date into suitable for filename
'dc:date' -> KEY GetDate(GetObjectKey)
'10' -> LIMIT CleanDate(SubStr)
Split(Split) OUT -> IN GetDate() OUT -> IN CleanDate()
# We also need the URL name for the filename
'dc:name' -> KEY GetName(GetObjectKey)
Split() OUT -> IN GetName()
# And finally we need the format