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 / module1.js
Created March 11, 2014 13:05
JS lesson: module example #1 - a self-contained module
var testModule = (function () {
var counter = 0;
return {
incrementCounter: function () {
return counter++;
},
@bradoyler
bradoyler / EmberNewsSiteRoutes.js
Last active August 29, 2015 13:57
example routes and controllers
App.Router.map(function() {
this.route("news", {
path: "/news"
}), this.route("entertainment", {
path: "/entertainment"
}), this.route("fashionBeauty", {
path: "/fashion-beauty"
}), this.route("lifestyle", {
path: "/lifestyle"
}), this.route("books", {
@bradoyler
bradoyler / PR.md
Created March 28, 2014 17:16
PR template

For:

Reviewers:

  • @
  • @

Test steps:

if (window.location.href.indexOf('://custom.me') === 0) {
window.location.replace('http://projectname.io' + window.location.pathname);
}
@bradoyler
bradoyler / promise.js
Created July 3, 2014 21:01
lame attempt at promise queue
function Promise() {
this.callbackQ = [],
this.errorQ = [],
this.then = function(callback, error){
this.callbackQ.push(callback);
this.errorQ.push(error);
},
@bradoyler
bradoyler / infinite_scroll.js
Last active August 29, 2015 14:03
infinite scroll jquery [scroll() -> get() -> insertAfter()]
$(window).scroll($.debounce(50), function() {
if ($(window).scrollTop() === $(document).height() - $(window).height()) {
var nextId = $('.article:last').data('next'); // gets the id of 'next' article from markup.
$.get('/ajax-article/' + nextId, function(content) { // gets the html
$($('.article', content)).insertAfter('.article:last'); //insert html after last article
@bradoyler
bradoyler / debounce.js
Last active August 29, 2015 14:03
debounce javascript function
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this,
args = arguments;
clearTimeout(timeout);
timeout = setTimeout(function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
@bradoyler
bradoyler / ackermann.js
Last active August 29, 2015 14:04
Ackermann function: In the 1920s, Wilhelm Ackermann demonstrated a computable function that was not primitive-recursive, settling an important argument in the run-up to the theory of computation. There are several versions of his function, of which the most common is defined over non-negative integers m and n. The function grows very rapidly, ev…
function ack(m,n) {
return (m == 0) ?
n + 1 :
(m > 0 && n==0) ?
ack(m-1,1) :
(m > 0 && n > 0) ?
ack(m - 1, ack(m,n-1)) :
undefined;
}
package main
import (
"fmt"
)
func main() {
fmt.Println("ack(3, 4):", ack(3, 4))
}
@bradoyler
bradoyler / findIds.js
Created August 2, 2014 15:38
filter array & display time it occured
function findIds(arr, filterFn) {
var results = arr.filter(filterFn);
results.timestamp = new Date();
return result;
}
var ids = [0, 1, 2, 8, 4, 4, 5, 6, 7, 8, 9];
var filtered = findIds(ids, function(x) {
return (x == 8);