Skip to content

Instantly share code, notes, and snippets.

View jamsesso's full-sized avatar

Sam Jesso jamsesso

  • Fredericton, Canada
  • 22:20 (UTC -03:00)
View GitHub Profile
void outchar(char ch) {
volatile int* JTAG_UART = (int*) 0x00008840;
*JTAG_UART = ch; // Write char to display.
}
char bin2hex(char hex) {
hex &= 0x0F; // Mask last 4 bits.
return hex <= 9 ? hex + '0' : hex - 10 + 'A';
}
@jamsesso
jamsesso / routing.js
Created August 30, 2014 20:24
Versioned API routing example
var express = require('express');
var http = require('http');
var app = express();
// Simple user controller implementation.
var users = [
{ username: 'jamsesso', age: 20, gender: 'M' },
{ username: 'bettycrocker', age: 20, gender: 'F' }
];
@jamsesso
jamsesso / UserAssembler.php
Created May 16, 2014 16:11
Assembler Layer
<?php
/**
*
*/
App::uses('UserEDM', 'Entity');
use Facebook\GraphObject;
class UserAssembler implements EntityAssembler {
const FB_FIRST_NAME = 'first_name';
@jamsesso
jamsesso / webserver.go
Created August 21, 2013 18:57
Very simple webserver for serving static HTML content.
package main
import (
"fmt"
"strconv"
"net/http"
"io/ioutil"
)
const (
@jamsesso
jamsesso / validate_password.js
Created June 6, 2013 11:43
Validate a password field based on regular expression tests.
/**
* jQuery validatePassword plugin. Fire a callback function if the password passes the test or if it fails the tests.
* @param expressions Object with a key => value pair of label => regex expression.
* @param success_callback Function the callback to fire when the user passes all of the tests.
* @param error_callback Function the callback to fire when the user fails any of the tests.
* @return Object
*
* Example: http://jsfiddle.net/WXqUZ/5/
* $('input[type=password]').validatePassword({
* 'Uppercase': /([A-Z]+)/,
@jamsesso
jamsesso / typing_finished.js
Last active December 18, 2015 00:38
jQuery plugin to detect when a user has finished typing in a field. Fires a callback function when typing is complete & has configurable timeout.
/**
* jQuery typingFinished plugin. Fire a callback function when the user is finished typing.
* @param timeout The timeout in milliseconds per interval.
* @param callback The callback function to fire when the user finishes typing.
* @return Object
*
* Example:
* $('input').typingFinished(500, function(e) {
* console.log('Done typing. Last key pressed: '+ e.keyCode);
* });
<?php
namespace Scarf\Views;
class Introduction
{
public function main()
{
write("Scarf is a modern, fast, maintainable,
easy-to-use rapid development PHP framework.");
}
}
<?php
namespace Scarf\Views;
use Scarf\Models\Contacts;
use Scarf\Library\Layout\Templates;
/* Creates a URL at http://.../contacts */
class Contacts
{
/* The main page when /contacts is visited. */
@jamsesso
jamsesso / mysql.php
Created July 23, 2011 16:57
Class to manage multiple MySQL server connections in an application.
<?php
class mysql extends mysqli
{
public static $servers = array();
public static function ignite_server($name, $host, $username, $password, $db, $port = null, $socket = null)
{
if(is_null($port))
$port = ini_get('mysqli.default_port');
<?php
require '../engine.php';
system::import('blog');
if(http::get('article'))
{
$article = blog::get_article(http::get('article'));
$article or page_not_found();