Skip to content

Instantly share code, notes, and snippets.

View omniosi's full-sized avatar

Ornette Coleman omniosi

View GitHub Profile
@omniosi
omniosi / Jquery Cloud and local
Created May 13, 2012 17:11
JQuery CDN hosted with local fallback
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="path/to/your/jquery"><\/script>')</script>
@omniosi
omniosi / browser audio target script
Created May 16, 2012 16:22
target audio format and deliver correct format to HTML audio
var ispeech;
var message;
var canPlayOgg = !!(new Audio().canPlayType('audio/ogg; codecs="vorbis"'));
if(canPlayOgg == true){
ispeech = "http://api.ispeech.org/api/rest?apikey=developerdemokeydeveloperdemokey&action=convert&voice=usenglishmale&format=ogg&text=";
} else{
ispeech = "http://api.ispeech.org/api/rest?apikey=developerdemokeydeveloperdemokey&action=convert&voice=usenglishmale&text=";
}
$("#submit").click(function(){
message = $("#text").val();
@omniosi
omniosi / Capitalize input text value
Created May 31, 2012 00:11
Capitalize input text value
/*Add to your script:*/
jQuery.fn.capitalize = function() {
$(this[0]).keyup(function(event) {
var box = event.target;
var txt = $(this).val();
var start = box.selectionStart;
var end = box.selectionEnd;
$(this).val(txt.replace(/^(.)|(\s|\-)(.)/g, function($1) {
return $1.toUpperCase();
}));
@omniosi
omniosi / HTML5 skeleton
Created June 19, 2012 21:53
an HTML5 skeleton page with HTML5shiv, jQuery and fallback, and normalise styling
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>GREYnyc boilerplate</title>
<link rel="stylesheet" href="css/normalize.css" type="text/css" media="screen"> <!-- Cross browser styling standardization -->
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"> <!-- Custom styling for this page -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <!-- Cloud hosted jQuery code -->
<script type="text/javascript">window.jQuery || document.write('<script type="text/javascript" src="path/to/your/jquery"><\/script>')</script> <!-- Local jQuery file fallback -->
<script src="js/script.js" charset="utf-8"></script> <!-- Custom scripts for this page -->
@omniosi
omniosi / smooth scrolling
Last active December 12, 2015 09:19
animated scrolling to links in jQuery
The function for the horizontal scrolling effect is the following:
$(function() {
$('ul.nav a').bind('click',function(event){
var $anchor = $(this);
/*
if you want to use one of the easing effects:
$('html, body').stop().animate({
scrollLeft: $($anchor.attr('href')).offset().left
}, 1500,'easeInOutExpo');
@omniosi
omniosi / svg-png-swap
Last active December 20, 2015 04:59
use modernizr to swap PNGs for SVG files depending on device/browser support
/*SVG CHECK*/
function svgCheck(){
if (!Modernizr.svg) {
$('img.svg').each(function () {
svg = $(this).attr('src');
svg = svg.replace('svg', 'png');
$(this).attr('src', svg);
});
}
}
@omniosi
omniosi / parallax-scrolling
Last active December 20, 2015 09:19
parallax scrolling
$(document).ready(function(){
$(window).bind('scroll',function(e){
parallax();
});
});
function parallax(){
var scrollPosition = $(window).scrollTop();
$('#stars').css('top',(0 - (scrollPosition * .2))+'px');
$('#images').css('top', (0 - (scrollPosition * .5)) + 'px');
}
@omniosi
omniosi / namespacing
Created August 1, 2013 23:03
explaining how to lock your variables and functions to this code alone to make sure there is no interference with other code on the page or site.
<!DOCTYPE html>
<html>
<head>
<title>Name spacing</title>
</head>
<body>
<script type="text/javascript">
var namespace = {
firstname: 'Ornette',
@omniosi
omniosi / clearfix-break
Created September 9, 2013 20:55
a clearfix to create a break using css styling. see: http://css-tricks.com/snippets/css/clear-fix/
.group:after {
content: "";
display: table;
clear: both;
}
@omniosi
omniosi / JS-code-timer
Last active December 23, 2015 00:19
You can use the console.time() and console.timeEnd() methods to measure how long a function or operation in your code takes to complete. You call console.time() at the point in your code where you want to start the timer and console.timeEnd() to stop the timer. The elapsed time between these two calls is displayed in the console. see: https://de…
console.time("Array initialize");
// code to measure
var array= new Array(1000000);
for (var i = array.length - 1; i >= 0; i--) {
array[i] = new Object();
};
console.timeEnd("Array initialize");
// console results = Array initialize: 461.127ms