Skip to content

Instantly share code, notes, and snippets.

View bradoyler's full-sized avatar
👋
say hi

brad oyler bradoyler

👋
say hi
View GitHub Profile
@bradoyler
bradoyler / hideAddressBar.js
Created December 1, 2013 03:53
hack to get rid of ios address bar
// hack to get rid of ios address bar.
function hideAddressBar()
{
if (!window.location.hash) {
if (document.height < window.outerHeight) {
document.body.style.height = (window.outerHeight + 50) + 'px';
}
setTimeout( function(){ window.scrollTo(0, 1); }, 50);
}
}
(function(i,s,o,g,r,a,m){
i['GoogleAnalyticsObject']=r;
i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)
},
i[r].l=1*new Date();
a=s.createElement(o),m=s.getElementsByTagName(o)[0];
a.async=1;
a.src=g;
/*
* Date Format 1.2.3
* (c) 2007-2009 Steven Levithan <stevenlevithan.com>
* MIT license
*
* Includes enhancements by Scott Trenda <scott.trenda.net>
* and Kris Kowal <cixar.com/~kris.kowal/>
*
* Accepts a date, a mask, or a date and a mask.
* Returns a formatted version of the given date.
@bradoyler
bradoyler / array_sorting.js
Last active August 29, 2015 13:56
JS console lesson : sorting numbers in Array : the functional nature of js
// figure out how this works and why it's important
// array
var arr =[2,3,5,5,1,99,22,44];
// sort ascending
arr.sort(function(n1,n2){
return n1 - n2;
}); //output: [1, 2, 3, 5, 22, 44, 99]
@bradoyler
bradoyler / declaring.js
Last active August 29, 2015 13:56
JS console Lesson #1: declaring functions.
// 1. declare a "named" function
function myNamedFunction(){ return true; }
// assertions
console.log(typeof window.myNamedFunction === "function"); // true
console.log(myNamedFunction.name === "myNamedFunction"); // true
// 2. declare anonymous function
var myAnonymousFunction = function(){ return true; };
//assertions
console.log(typeof window.myAnonymousFunction === "function"); // true
@bradoyler
bradoyler / strings.js
Last active August 29, 2015 13:56
Lesson #2: string manipulation and counting
//reverse characters in string
console.log('test string'.split('').reverse().join('')); // output: gnirts tset
// count characters in a string
function Char_Counts(str1) {
var uchars = {};
str1.replace(/\S/g, function(l){
uchars[l] = (isNaN(uchars[l]) ? 1 : uchars[l] + 1);
});
@bradoyler
bradoyler / recursive_math.js
Last active August 29, 2015 13:56
JS console lesson : recursive math
// get factorial of a given number
// ie. 4 = (4 * 3 * 2 * 1) = 24
function factorial(x) {
if(x==0) {
return 1;
}
return x * fact(x-1);
}
@bradoyler
bradoyler / number_array_manipulation.js
Last active August 29, 2015 13:56
JS console lesson : manipulating numeric arrays
// return 2nd highest and lowest numbers
function Second_Greatest_Lowest(arr_num)
{
arr_num.sort(function(x,y)
{
return x-y;
});
var uniqa = [arr_num[0]];
var result = [];
@bradoyler
bradoyler / array_filter.js
Last active August 29, 2015 13:56
JS console lesson : array filtering
// filter words with a RegEx
var startsWithA = new RegExp(/^a/i); // filter by first letter A
var arr = ['Apple','avocado','Banana','Cherry'];
var filtered = arr.filter(function(item){
return startsWithA.test(item);
});
@bradoyler
bradoyler / find_longest_word.js
Created February 22, 2014 22:24
JS console challenge : find the longest word
function LongestWord(sen) {
sen = sen.split(' '); // creates array
var nonAlpha = new RegExp('[^a-zA-Z\d\s:]');
var filtered = sen.filter(function(item){
return !nonAlpha.test(item);
});
var sorted = filtered.sort(function(n1,n2){