Skip to content

Instantly share code, notes, and snippets.

View dgreenway's full-sized avatar

Devon Greenway dgreenway

View GitHub Profile
@dgreenway
dgreenway / html5 starter.html
Last active November 9, 2017 06:26
HTML 5 starter template #html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
@dgreenway
dgreenway / Google Map Snippet.html
Created September 26, 2013 22:24
Map from location to set destination
<form action="http://maps.google.com/maps" method="get" target="_blank">
<label for="saddr">Enter your location</label>
<input type="text" name="saddr" />
<input type="hidden" name="daddr" value="350 5th Ave New York, NY 10018 (Empire State Building)" />
<input type="submit" value="Get directions" />
</form>
@dgreenway
dgreenway / 1px. gif.html
Created September 26, 2013 22:26
Base64 encoded 1px gif
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7">
@dgreenway
dgreenway / Hide Mobile AddressBar.js
Created September 27, 2013 17:25
Hide the address bar in mobile browsers
// When ready...
window.addEventListener("load",function() {
// Set a timeout...
setTimeout(function(){
// Hide the address bar!
window.scrollTo(0, 1);
}, 0);
});
@dgreenway
dgreenway / nozoom.html
Created September 27, 2013 17:26
Prevent zoom on mobile
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
@dgreenway
dgreenway / orientationchange.js
Created September 27, 2013 17:28
Listen for orientation change in mobile browser
// Listen for orientation changes
window.addEventListener("orientationchange", function() {
// Announce the new orientation number
console.log(window.orientation);
// 0 means portrait, 90 means landscape rotated to the left, -90 means landscape rotated to the right
}, false);
@dgreenway
dgreenway / SmoothScroll.js
Created September 27, 2013 18:37
Smooth Scroll to anchor
// HTML:
// <h1 id="anchor">Lorem Ipsum</h1>
// <p><a href="#anchor" class="topLink">Back to Top</a></p>
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
@dgreenway
dgreenway / Password Strength.js
Created September 27, 2013 18:38
Use regex to provide feedback on password strength
$('#pass').keyup(function(e) {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
if (false == enoughRegex.test($(this).val())) {
$('#passstrength').html('More Characters');
} else if (strongRegex.test($(this).val())) {
$('#passstrength').className = 'ok';
$('#passstrength').html('Strong!');
} else if (mediumRegex.test($(this).val())) {
@dgreenway
dgreenway / DataUri.php
Created September 27, 2013 18:41
Create a data URI from a file
function data_uri($file, $mime) {
$contents=file_get_contents($file);
$base64=base64_encode($contents);
echo "data:$mime;base64,$base64";
}
@dgreenway
dgreenway / nth.php
Created September 27, 2013 18:42
Add string to number
function ordinal($cdnl){
$test_c = abs($cdnl) % 10;
$ext = ((abs($cdnl) %100 < 21 && abs($cdnl) %100 > 4) ? 'th'
: (($test_c < 4) ? ($test_c < 3) ? ($test_c < 2) ? ($test_c < 1)
? 'th' : 'st' : 'nd' : 'rd' : 'th'));
return $cdnl.$ext;
}
for($i=1;$i<100;$i++){
echo ordinal($i).'<br>';
}