Skip to content

Instantly share code, notes, and snippets.

View qwertypants's full-sized avatar
🧶

Wilkins Fernandez qwertypants

🧶
View GitHub Profile
@qwertypants
qwertypants / check_host.js
Created November 10, 2010 17:39
check for SLL
// Taken from Google. Is that evil?
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
@qwertypants
qwertypants / jQuery_number_only.js
Created November 10, 2010 17:48
Only allow numbers in an input field
$.fn.numOnly = function() {
return this.each( function() {
// backspace(8), dot(.), tab(0) 0-9
var c = [8, 0, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58];
if ($(this).attr('type') === 'text') {
$(this).keypress( function(e) {
if (c.indexOf(e.which, c) == -1) {
e.preventDefault();
}
});
@qwertypants
qwertypants / iCheck.js
Created November 10, 2010 18:04
Check to see if the user is on iPad, iPod, or iPhone
function iCheck(func){
if (!(navigator.userAgent.match(/iPhone/i)) || !(navigator.userAgent.match(/iPod/i)) || !(navigator.userAgent.match(/iPad/i))) {
func(navigator.userAgent);
}
}
// Usage
iCheck(function(agent){
// You can use a case select statement to
// evaluate what actions you want to do
@qwertypants
qwertypants / jQuery_bitlyfi.js
Last active September 24, 2015 04:57
Create a bit.ly URL by passing the URL you want shortened and preforming a function with it
function bitlyfi(url, func) {
var defaults = {
token: '',
longUrl: url
};
// Build the URL to query
var bitly = 'https://api-ssl.bitly.com/v3/shorten?' + '&access_token=' + defaults.token + '&longUrl=' + defaults.longUrl + '&format=json&callback=?';
// Utilize the bit.ly API
$.getJSON(bitly, function (results) {
@qwertypants
qwertypants / month_abb.js
Created November 16, 2010 15:12
Abbreviate a month name based on index param
var monthAbbreviation = function(month_index){
m_names = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
s = m_names[month_index - 1];
return s.substr(0,3).toUpperCase());
};
@qwertypants
qwertypants / load.js
Created December 22, 2010 21:01
Template for loading with LAB.js
/*! LAB.js (LABjs :: Loading And Blocking JavaScript)
v1.2.0 (c) Kyle Simpson
MIT License
*/
(function(p){var q="string",w="head",L="body",M="script",u="readyState",j="preloaddone",x="loadtrigger",N="srcuri",E="preload",Z="complete",y="done",z="which",O="preserve",F="onreadystatechange",ba="onload",P="hasOwnProperty",bb="script/cache",Q="[object ",bw=Q+"Function]",bx=Q+"Array]",e=null,h=true,i=false,k=p.document,bc=p.location,bd=p.ActiveXObject,A=p.setTimeout,be=p.clearTimeout,R=function(a){return k.getElementsByTagName(a)},S=Object.prototype.toString,G=function(){},r={},T={},bf=/^[^?#]*\//.exec(bc.href)[0],bg=/^\w+\:\/\/\/?[^\/]+/.exec(bf)[0],by=R(M),bh=p.opera&&S.call(p.opera)==Q+"Opera]",bi=("MozAppearance"in k.documentElement.style),bj=(k.createElement(M).async===true),v={cache:!(bi||bh),order:bi||bh||bj,xhr:h,dupe:h,base:"",which:w};v[O]=i;v[E]=h;r[w]=k.head||R(w);r[L]=R(L);function B(a){return S.call(a)===bw}function U(a,b){var c=/^\w+\:\/\//,d;if(typeof a!=q)a="";if(typeof b!=q)b="";d=((/^\/\//
@qwertypants
qwertypants / qunit-template.htm
Created December 29, 2010 14:44
Standard template for qUnit testing
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" media="screen">
<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-git.js"></script>
<script type="text/javascript">
// Docs: http://docs.jquery.com/Qunit
</script>
</head>
@qwertypants
qwertypants / modernizr.css
Created December 29, 2010 16:21
Generic structure for Modernizr CSS styles
.js {}
.no-js {}
.flexbox {}
.no-flexbox {}
.canvas {}
.no-canvas {}
.canvastext {}
.no-canvastext {}
.webgl {}
.no-webgl {}
@qwertypants
qwertypants / Interview test
Created December 30, 2010 19:17
A simple test to see if your JS and jQuery skills are up to date. Adapted from and inspired by http://bit.ly/fSuTDx
var a = 1,
b = function a(x) {
x && a(--x);
};
alert(a);
---------------------------------------
@qwertypants
qwertypants / gist:766732
Created January 5, 2011 18:29 — forked from getify/gist:670840
Load a local copy of jQuery if a CDN is not available
function test_jQuery() { jQuery(""); }
function success_jQuery() { alert("jQuery is loaded!");
var successfully_loaded = false;
function loadOrFallback(scripts,idx) {
function testAndFallback() {
clearTimeout(fallback_timeout);
if (successfully_loaded) return; // already loaded successfully, so just bail
try {
scripts[idx].test();