Skip to content

Instantly share code, notes, and snippets.

View jamsesso's full-sized avatar

Sam Jesso jamsesso

  • Fredericton, Canada
  • 13:53 (UTC -03:00)
View GitHub Profile
@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);
* });
@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 / 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 / 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 / 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' }
];
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 / thing.txt
Last active December 21, 2015 18:18
create_signature(payload, type, timestamp, public_key, secret_key) {
signature = sprintf("payload=%s&public_key=%s&timestamp=%s&type=%s",
url_encode(payload),
url_encode(public_key),
url_encode(timestamp),
url_encode(type))
return hmac_sha256(signature, secret_key)
}
@jamsesso
jamsesso / app.txt
Last active December 21, 2015 18:18
authenticate_message(message) {
secret_key = get_secret_key(message.public_key)
my_signature = sprintf("payload=%s&public_key=%s&timestamp=%s&type=%s",
url_encode(message.payload),
url_encode(message.public_key),
url_encode(message.timestamp),
url_encode(message.type))
return hmac_sha256(my_signature, secret_key) == message.signature
}
import com.google.gson.Gson;
import java.util.Date;
import lombok.Data;
import com.google.common.collect.Maps;
import java.util.Map;
/**
* The message class.
* This class should be present on both the client as well as the receiving app.
* You can serialize this class to send it over the network. JSON is a good choice.
@jamsesso
jamsesso / dev-server.js
Last active August 24, 2020 13:27
Webpack dev server with a better proxy (http-proxy-middleware)
var express = require('express');
var path = require('path');
var webpackConfig = require('./webpack.config');
var webpack = require('webpack');
var webpackDevMiddleware = require('webpack-dev-middleware');
var webpackHotMiddleware = require('webpack-hot-middleware');
var proxyMiddleware = require('http-proxy-middleware');
var devConfig = webpackConfig.devServer;
var app = express();