Turns out yaml_parse() in PHP automatically parses a front matter block out of a markdown based post.
Sander van Dragt's Notes
-
-
Entry titles aren't optional in Atom feeds, how to micro blogs deal with that? Update: it seems by making the title an empty element.
-
The AI evolution seems scary until you realise most of the applications are summarised as a wrapper around the OpenAI API that does all the work, with the context provided by a prompt prefix. So with half a day's study most programmers can participate. #technology
-
Ubuntu's minimal installation appears to be the standard installation plus the removal of some packages! That's unexpected as I was trying to save installation time. #ubuntu #technology #linux
-
Map Eject to Multitasking View
So I use ElementaryOS and in version 7 you are no longer able to map just the Eject key. I like to map this to the Multitasking View (something like the macOS Expose).
The solution is to use the DConf Editor application and search for
show-desktop. ElementaryOS repurposes the show desktop to the multitasking view. Simply set the value to['Eject']Alternatively you can set the left-super key (windows/command) to the Multitasking View. This seems better supported.
-
Lamb 0.2
I've released Lamb 0.2, my micro blogging app that's powering this site.
What's new?
- Posts! Posts are statuses with a title. The title can be added in the front matter (front matter is parsed as an ini-string). Posts have a slug based on the title when the post was created.
- Individual statuses / posts have opengraph tags for improved sharing fidelity.
- The text editor grows to accommodate the input.
-
0.2.0
Originally written on lamb-releases:
Via lamb-releasesPosts! Posts are statuses with a title. The title can be added in the front matter (front matter is parsed as an ini-string) Posts have a slug based on the title when the post was created. Individual statuses / posts have opengraph tags for improved sharing fidelity. Fixed several XSS, thanks @cameronterry
-
Basic routing using REQUEST_URI
So for nginx it is not straightforward to setup PHP-FPM so that
PATH_INFOis correctly populated. Lamb uses the following/index.php/some/othertype routing, where/some/othershould be thePATH_INFO. Instead I want to make setup for a variety of web-servers straightforward, so I've switched to the more robustREQUEST_URI. This simplifies nginx configuration and Caddy and the PHP built-in web-server are compatible.REQUEST_URIcontains everything after the domain name, including the query string, so that needs to be removed:$request_uri = '/home'; if ( $_SERVER['REQUEST_URI'] !== '/' ) { $request_uri = strtok( $_SERVER['REQUEST_URI'], '?' ); }We can see that for a request for the root of the site,
REQUEST_URIreturns/whereasPATH_INFOwould be empty, so the code above takes that into account. We can then deduct a router action as follows:$action = strtok( $request_uri, '/' );Once the
$actionis known, it can be checked against an allowed list of actions:switch ( $action ) { case 'edit': ... break; default: respond_404(); break; -
0.1.0
Originally written on lamb-releases:
Via lamb-releasesInitial release! Full Changelog: https://github.com/svandragt/lamb/commits/0.1.0
-
Godot simplified drag n drop tutorial
I was "following" Generalist Programmer's Godot drag and drop tutorial and I made a few refinements that I wanted to share. Please read the tutorial and then follow along.
Drop-in behaviour
Wouldn't it be cool to give a node drag and drop behaviour simply by dropping in a node with the script, independent of any other scripting?
We can do this by creating a new child node (here called Drag-and-drop Dropin), and attaching the script to it. It must extend from the dropin Node2D.

In the script itself we make two changes:
- Disconnect the KinematicBody2D's input_event signal, and write it in code in the dropin's _ready function. Call it on it's parent:
get_parent().connect("input_event", self, "_on_KinematicBody2D_input_event"). We want to process theinput_eventof the KinematicBody2D, not the dropin. - In the
_processfunction, assign the mouse position to the parent of the dropin:get_parent().position = Vector2(mousepos.x, mousepos.y). - Same for the last line in the script where we set the position of the parent.
The script then reads as follows:
extends Node2D var dragging = false signal dragsignal func _ready(): connect("dragsignal", self, "_set_drag_pc") get_parent().connect("input_event", self, "_on_KinematicBody2D_input_event") func _process(delta): if dragging: var mousepos = get_viewport().get_mouse_position() get_parent().position = Vector2(mousepos.x, mousepos.y) func _set_drag_pc(): dragging = !dragging func _on_KinematicBody2D_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT and event.pressed: emit_signal("dragsignal") elif event.button_index == BUTTON_LEFT and !event.pressed: emit_signal("dragsignal") elif event is InputEventScreenTouch: if event.pressed and event.get_index() == 0: get_parent().position = event.get_position()Simplifying the script
I was refactoring this, and it turns out we can simplify this further.
- We don't need a dragsignal because the signal is both emitted and consumed within the same script. We can just replace the
emit_signalcalls with calls to_set_drag_pc(). We can then remove theconnect()call in the_readyfunction, and thesignal dragsignal. - The same function is called when the left mouse button is both pressed and not pressed, so we can remove that conditional and remove the
elifstatement in the input event handler. - As there is only one invocation of
_set_drag_pc()we can inline it.
The final script becomes:
extends Node2D var dragging = false func _ready(): get_parent().connect("input_event", self, "_on_KinematicBody2D_input_event") func _process(delta): if dragging: var mousepos = get_viewport().get_mouse_position() get_parent().position = Vector2(mousepos.x, mousepos.y) func _on_KinematicBody2D_input_event(viewport, event, shape_idx): if event is InputEventMouseButton: if event.button_index == BUTTON_LEFT: dragging = !dragging elif event is InputEventScreenTouch: if event.pressed and event.get_index() == 0: get_parent().position = event.get_position()So this dropin can now be added to any node to add Drag-and-Drop behaviour. I think the script can be improved a little so that the node is not centered under the mouse cursor but takes account the offset where it is picked up.
Let me know your thoughts! #godot
- Disconnect the KinematicBody2D's input_event signal, and write it in code in the dropin's _ready function. Call it on it's parent: