Skip to content

Instantly share code, notes, and snippets.

View geuis's full-sized avatar

Charles Lawrence geuis

View GitHub Profile
  • readability
  • maintainability
  • consistency
  • exception handling
  • simplicity
  • test coverage
  • side effect
  • reuse of existing code
  • performance
@geuis
geuis / base32decode.js
Last active December 20, 2015 06:29
Base32 decoder
(function(){
"use strict";
//Generate dictionary
var arr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'.split(''),
dict = {};
for(var i=0, len=arr.length; i<arr.length; i++){
dict[arr[i]] = i;
}
@geuis
geuis / clever.html
Created July 11, 2013 21:29
Basic http://getclever.com API accessor. Calculate average number of students per section in dummy data.
<!doctype>
<html>
<head>
<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
<script>
(function(){
window.clever = function(user, pass){
@geuis
geuis / remote-typeahead.js
Created February 16, 2012 22:58
Remote data querying for Twitter Bootstrap 2.0 Typeahead without modifications
<script>
// Charles Lawrence - Feb 16, 2012. Free to use and modify. Please attribute back to @geuis if you find this useful
// Twitter Bootstrap Typeahead doesn't support remote data querying. This is an expected feature in the future. In the meantime, others have submitted patches to the core bootstrap component that allow it.
// The following will allow remote autocompletes *without* modifying any officially released core code.
// If others find ways to improve this, please share.
var autocomplete = $('#searchinput').typeahead()
.on('keyup', function(ev){
ev.stopPropagation();
@geuis
geuis / json.js
Created November 15, 2011 16:01
Better error handling for JSON.parse (javascript)
(function(){
var parse = JSON.parse;
JSON = {
stringify: JSON.stringify,
validate: function(str){
@geuis
geuis / whenthen.js
Created July 30, 2011 04:40
When-Then (pseudo javascript Promise)
var when = function(){
if( !(this instanceof when) ) return new when(arguments); //return new instance of itself
var self = this; //cached so the syntax of code within the function is more readable
self.pending = Array.prototype.slice.call(arguments[0]); //convert arguments passed in to array
self.pending_length = self.pending.length; //cache length of the arguments array
self.results = []; //container for results of async functions
(function(){ // define pass() within this context so that the outer scope of self(this) is available when pass() is executed within the user's async functions
@geuis
geuis / tic-tac-toe.js
Created July 23, 2011 00:24
Simple cross-browser implementation of tic-tac-toe in js
<!DOCTYPE html>
<html>
<head>
<style>
html,body{
padding:0;
margin:0;
font-family:arial;
}
.clearfix:after{