Skip to content

Instantly share code, notes, and snippets.

@iNamik
iNamik / View.php
Created December 12, 2012 02:24
An experiment to create a simple 'view' class based on ob_start()/ob_end_* that still contained some useful functionality, like includes, captures, and the ability to inject content into re-usable layout components.
<?php
/**
* Simple view class
*
* This is the simplest class I could devise that contains the minimum logic
* that I require in a view:
*
* Includes - Ability to include other views
*
* Captures - Ability to easily capture content within your view
@iNamik
iNamik / replace_tags.php
Last active June 4, 2024 19:01
Simple PHP Function to Replace Tags in a String (i.e. "Hello, {{there}}" => "Hello, world")
<?php
/**
* replace_tags replaces tags in the source string with data from the tags map.
* The tags are identified by being wrapped in '{{' and '}}' i.e. '{{tag}}'.
* You may also space your tags like `{{ tag }}` for better readability.
* If a tag value is not present in the tags map, it is replaced with an empty
* string.
* @param string $string A string containing 1 or more tags wrapped in '{{}}'
* @param array $tags A map of key-value pairs used to replace tags.
@iNamik
iNamik / calc.go
Created October 20, 2011 05:44
Calculator Example in GO using my Lexer/Parser API
//
// calc.go implements a simple calculator using the iNamik lexer and parser api.
//
// Input is read from STDIN
//
// The input expression is matched against the following pattern:
//
// input_exp:
// ( id '=' )? general_exp
// general_exp: