Skip to content

Instantly share code, notes, and snippets.

@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:
@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 / 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 / PHPUnit_GenericException.php
Created December 15, 2012 19:20 — forked from anonymous/PHPUnit_GenericException.php
Generic Exception Support for PHPUnit < v3.7 - A full test suite is included.
<?php
/**
* Generic Exception Support for PHPUnit < v3.7
*
* These classes help you test generic exceptions in PHPUnit versions less than
* v3.7, avoiding the 'You must not expect the generic exception class' error.
*
* We create a new exception to represent the generic exception, and provide
* multiple ways to incorporate the functionality into your tests:
*
@iNamik
iNamik / is_scalar_array.php
Last active December 10, 2015 02:58
I Present several PHP functions for determining if an array is 'scalar', with differing levels of strictness.
<?php
/**
* Since PHP stores all arrays as associative internally, there is no proper
* definition of a scalar array.
*
* As such, developers are likely to have varying definitions of scalar array,
* based on their application needs.
*
* In this file, I present 3 increasingly strict methods of determining if an
* array is scalar. I feel these methods cover the majority, if not all, of the
@iNamik
iNamik / llrb.go
Created June 23, 2013 07:25
A base implementation of Robert Sedgewick's Left-Leaning Red-Black Tree (LLRB), written in Go (GOLANG). LLRB Trees are a variant of red-black trees with the aim of reducing the complexity of Insert and Delete functionality. They are self-balancing, maintaining the balance characteristics of a 2-3 tree, while retaining the Get(Key) performance of…
/*
package llrb implements a Left-Leaning Red-Black Tree (2-3 Variant),
as described by Robert Sedgewick:
* http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf
* http://en.wikipedia.org/wiki/Left-leaning_red%E2%80%93black_tree
The goal of this implementation is a one-to-one correlation to the ideas
@iNamik
iNamik / svnCleanUpdate.sh
Created April 16, 2014 06:10
Bash Script to Cleanup an SVN checkout, Revert local changes and Update to @Head - Does not generate any output unless something is changed.
#!/bin/bash
##
# svnCleanUpdate
#
# Cleanup an SVN checkout, Revert local changes and update to @HEAD
# Does not generate any output unless something is changed.
# NOTE: This script destroys all local mods - run it with caution!
#SVN_AUTH="--username user --password passwd"
@iNamik
iNamik / keybase.md
Created February 9, 2017 19:21
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@iNamik
iNamik / chrome.sh
Created May 11, 2017 21:46
Launch Multiple Chrome Instances on MAC
#
# Add the below chrome() function to your ~/.bash_profile
#
# Launch an anonymous instance - Profile is stored in /tmp with random name
# $ chrome
#
# Launch/relaunch a temporary named instance - Profile is stored in /tmp with specified name
# $ chrome name_in_all_lowercase
#
# Launch/relaunch a permanent named instance - Profile is stored in ~/Documents/ChromeProfiles with specified name
@iNamik
iNamik / rpi_backlight_brightness.sh
Last active April 26, 2018 00:14
Bash Script to Set The Brightness on the Raspberry Pi Touch Screen
#!/bin/bash
FILE="/sys/class/backlight/rpi_backlight/brightness"
if [ $# = 0 ]; then
cat ${FILE}
exit 0
fi
if [ $# -eq 1 ] && [[ $1 =~ ^[0-9]{1,3}$ ]] && [ $1 -ge 0 ] && [ $1 -le 255 ]; then