Skip to content

Instantly share code, notes, and snippets.

View jlittlejohn's full-sized avatar

Josh Littlejohn jlittlejohn

View GitHub Profile
@jlittlejohn
jlittlejohn / gist:5753872
Created June 11, 2013 01:19
RegEx: Hex Color
^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$
@jlittlejohn
jlittlejohn / gist:5751570
Created June 10, 2013 19:37
RoR: Add Image Link with Attributes
=link_to image_tag("image.png", :alt => 'The Alt Tag'), 'http://google.com', :title => 'Title'
@jlittlejohn
jlittlejohn / gist:5717814
Created June 5, 2013 22:21
JS: Rock, Paper, Scissors
var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
@jlittlejohn
jlittlejohn / gist:5700280
Created June 3, 2013 18:39
RoR: Adding a Data-Attribute
.icon{:data => {:comments => 1}}
@jlittlejohn
jlittlejohn / gist:5687830
Created May 31, 2013 20:41
JS: Konami Code
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(e) {
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
$(document).unbind('keydown',arguments.callee);
@jlittlejohn
jlittlejohn / gist:5685473
Last active May 1, 2019 16:05
PHP: array_map
<?php
$alphabet=array();
/* Create lower Case Alphabet */
for($i=97;$i<123;$i++) $alphabet[]=chr($i);
/* Convert to Uppercase */
$upperCaseAlphabet = array_map('strtoupper',$alphabet);
?>
@jlittlejohn
jlittlejohn / gist:5685457
Created May 31, 2013 14:43
PHP: glob Function
<?php
/* Find all image files in image folder */
$images = glob($imagePath.'*.{gif,jpeg,jpg,png}',GLOB_BRACE);
?>
@jlittlejohn
jlittlejohn / gist:5685454
Created May 31, 2013 14:41
PHP: SimpleXML Class
<?php
/* Load flickr Public Feed */
$xml = simplexml_load_file('http://api.flickr.com/services/feeds/photos_public.gne');
if(is_object($xml)){
/* Get each entry and echo the content tag */
foreach($xml->entry as $photo) echo $photo->content;
}
?>
@jlittlejohn
jlittlejohn / gist:5685447
Created May 31, 2013 14:41
PHP: Hashing API
<?php
$hash = password_hash($password, PASSWORD_BCRYPT, ['cost' => 20]);
?>
@jlittlejohn
jlittlejohn / gist:5685387
Created May 31, 2013 14:33
PHP: Usorting
<?php
$successful = usort($students, function ($a, $b) {
return $a['age'] - $b['age'];
});
?>