Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mikebucks's full-sized avatar

Mike Bucks mikebucks

View GitHub Profile
@mikebucks
mikebucks / gist:7538408
Created November 19, 2013 01:04
Accelerometer gamma detection.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>device detection</title>
</head>
<body>
<div id="log_motion"></div>
<div id="log_orientation"></div>
@mikebucks
mikebucks / gist:7521064
Last active December 28, 2015 15:19
A simple little script to detect palindromes.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Palindrome Detector</title>
</head>
<body>
<p>This soution splits the value of a text input into an array, reverses it, and then compares the result to the original value. If the two values are identical we have a palindrome. It uses no 3rd party libs and passes JSLint.</p>
<hr>
<form>
@mikebucks
mikebucks / gist:7496187
Last active December 28, 2015 11:49
Converts comma separated key/value pairs to a js object.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Name Counts</title>
</head>
<body>
<p>This solution to the keys problem converts the contents of a textarea into an array by line break, then passes that array to a "convertCommaKeysToObject" method which is where the bulk of the oeration takes place. This method iterates through an array of strings which it expects to contain a single comma. It splits each string at the comma, adding the value left of the comma as a new key and the value right of the comma as a value. If a key already exists in the new object it's value is added to the existing key. It then prints the results to the DOM. It uses no 3rd party libs and (almost) passes JSLint.</p>
<hr>
<form>
@mikebucks
mikebucks / robot.js
Created December 6, 2012 23:32
Mr Tickles
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);
@mikebucks
mikebucks / jq_check.js
Created April 2, 2012 16:48
Check for jQuery and add it if needed
var hasjQuery = false;
jQueryCheck = function() {
if (! window.jQuery) {
if (! hasjQuery) {
hasjQuery = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
document.getElementsByTagName('body')[0].appendChild(script);
}