Skip to content

Instantly share code, notes, and snippets.

View MikeRogers0's full-sized avatar
🚂

Mike Rogers MikeRogers0

🚂
View GitHub Profile
@MikeRogers0
MikeRogers0 / binding.php
Created June 16, 2012 17:16
PDO (PHP Data Objects) – Starter Guide
<?php
$query = $db->prepare('SELECT * FROM `users` WHERE `ID` = :ID: AND `email` = :email: ORDER BY ID DESC LIMIT 0,1;');
$query->execute(array(':ID:' => '3', ':email:' => '[email protected]'));
$result = $query->fetchAll(PDO::FETCH_ASSOC);
?>
@MikeRogers0
MikeRogers0 / getElementsByClassName.html
Created June 16, 2012 17:14
JavaScripts Selector Methods
<p id="myElem1" class="classExample">My First paragraph</p>
<p id="myElem2" class="classExample">My Second paragraph</p>
<script>
if(!document.querySelectorAll){ // If the user does not have querySelectorAll()
var classExample = document.getElementsByClassName('classExample'); // Get all the elements with class "classExample"
}else{ // Otherwise do it the HTML5 way
var classExample = document.querySelectorAll('.classExample');
}
for(i=0; i<classExample.length; i++) {// Cycle through them
@MikeRogers0
MikeRogers0 / ctypes-alpha-alnum.php
Created June 16, 2012 17:10
PHP's Ctype Functions
<?php
// Check if input is alphanumeric (letters and numbers)
ctype_alnum('abcdef1234'); // This returns TRUE
ctype_alnum('£%^&ab2'); // This on the otherhand returns FALSE
// check if input is alpha (letters)
ctype_alpha('dssfsdf'); // returns TRUE
ctype_alpha('12345dssfsdf'); // Returns FALSE
?>
@MikeRogers0
MikeRogers0 / validate-email.php
Created June 16, 2012 17:09
How to validate an email address with PHP
<?php
function validEmail($email){
// Check the formatting is correct
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
return FALSE;
}
// Next check the domain is real.
$domain = explode("@", $email, 2);
return checkdnsrr($domain[1]); // returns TRUE/FALSE;
@MikeRogers0
MikeRogers0 / weather-class.inc.php
Created June 16, 2012 17:04
Getting the Weather in PHP
<?php
class Weather {
 public $lat, $long, $weather, $location;
 private $weather_data, $location_data;

 public function __construct($lat=0.0, $long=0.0){
  $this->lat = (float) $lat;
  $this->long = (float) $long;
 }

@MikeRogers0
MikeRogers0 / hello.java
Created June 16, 2012 17:02
Hello World in Java
package hellowrold;
/**
*
* @author Mike
*/
public class Main {
/**
* @param args the command line arguments
@MikeRogers0
MikeRogers0 / get-mentions.php
Created June 16, 2012 16:56
Twitter OAuth Class 1.0 Released
<?php
$t->mentions();
?>
@MikeRogers0
MikeRogers0 / shorten.php
Created June 16, 2012 16:54
Shorten URLs using the Google URL Shortener and PHP
<?php
// Coded by Mike Rogers (http://www.fullondesign.co.uk/) 1st October 2010.
function shorten($url, $qr=NULL){
if(function_exists('curl_init')){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, 'http://goo.gl/api/shorten');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'security_token=null&url='.urlencode($url));
@MikeRogers0
MikeRogers0 / add-task.html
Created June 16, 2012 16:16
Task Bar Support for your Website
<meta name="msapplication-task" content="name=Projects;action-uri=http://www.fullondesign.co.uk/projects/;icon-uri=http://www.fullondesign.co.uk/favicon.ico"/>
@MikeRogers0
MikeRogers0 / better-form.html
Created June 16, 2012 16:06
Creating More User Friendly Forms with jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <!– Pull the jQuery base from Google, it has CDN so it should be a little faster. –>
<script type="text/javascript">
$(document).ready(function() {
$("form input, form input, form textarea").css('color', '#484848');
$("form .submit").css('color', '#000');
$("form label").hover(function () {
$("#infobox").html($(this).attr('title'));
});
$("form input, form input, form textarea").focus(function () {
if($(this).val() == $(this).attr('title')){