Skip to content

Instantly share code, notes, and snippets.

View codeguy's full-sized avatar

Josh Lockhart codeguy

View GitHub Profile
@codeguy
codeguy / gist:2396070
Created April 16, 2012 02:31
Test Gist
<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name!";
});
$app->run();
?>
@codeguy
codeguy / index.html
Last active December 19, 2015 10:59
HTML Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<title>My Document</title>
<!--[if lt IE 9]><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
<link rel="stylesheet" href="/css/all.css"/>
<link rel="shortcut icon" href="/images/favicon.ico"/>
@codeguy
codeguy / console.js
Created July 8, 2013 03:52
A wrapper for `console.log` for browsers that lack support (e.g. IE)
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function () {
log.history = log.history || [];
log.history.push(arguments);
if (this.console) {
console.log(Array.prototype.slice.call(arguments));
}
};
@codeguy
codeguy / round-date.js
Created July 12, 2013 03:57
Round a Date to nearest Nth minute
var roundToNearestMinute = function (date) {
var coeff = 1000 * 60 * 5; // <-- Replace {5} with interval
return new Date(Math.round(date.getTime() / coeff) * coeff);
};
@codeguy
codeguy / mysql-create-table.sql
Created September 20, 2013 13:48
MySQL Create Table
DROP TABLE IF EXISTS table_name;
CREATE TABLE table_name (
) ENGINE=INNODB DEFAULT CHARSET=UTF8 COLLATE=UTF8_UNICODE_CI;
@codeguy
codeguy / csv-iterator.php
Created September 24, 2013 01:31
PHP CSV iterator
<?php
class CsvIterator implements \Iterator
{
const ROW_SIZE = 4096;
/**
* The pointer to the cvs file.
* @var resource
* @access protected
*/
@codeguy
codeguy / html5-csv-parser.js
Created September 24, 2013 01:44
Upload, parse, and iterate CSV file with HTML5 File APIs
/**
* CSV upload and parser
*
* This code will use the HTML5 File and FileReader APIs
* to upload and parse a CSV file.
*
* REQUIREMENTS:
* - jQuery
* - D3.js
* - HTML5 File APIs
@codeguy
codeguy / slugify.js
Created September 24, 2013 13:19
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
@codeguy
codeguy / get-current-location.js
Created September 24, 2013 18:33
Get user's current gelocation with HTML Geolocation API
if ('geolocation' in navigator) {
console.log('Supports HTML geolocation API');
(function () {
var onSuccess = function (location) {
console.log('User location', location);
var userLat = location.coords.latitude,
userLon = location .coords.longitude;
},
@codeguy
codeguy / geocode-address.js
Created September 24, 2013 18:37
Geocode address with Google Maps API
/**
* Geocode address
*
* REQUIREMENTS
* - Google Maps API
* - HTML5 Geolocation API
*/
var geocode = function (address, onSuccess, onError) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ address: address }, function (results, status) {