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 / getType.js
Last active August 29, 2015 13:56
JS console lesson : detect datatype
function getType(value)
{
var dtypes = [Function, RegExp, Number, String, Boolean, Object], x, len;
if (typeof value === "object" || typeof value === "function") {
for (x = 0, len = dtypes.length; x < len; x++)
{
if (value instanceof dtypes[x])
{
function LetterChanges(str) {
var letters = str.split('');
for (var i = 0; i < letters.length; i++) {
var letter = letters[i];
if(/[a-yA-Y]/.test(letter)){
letters[i] = String.fromCharCode(letter.charCodeAt(letter.length-1)+1);
}
}
@bradoyler
bradoyler / inheritance.js
Last active February 26, 2022 09:53
JS inheritance. Explained.
// via http://www.klauskomenda.com/code/javascript-inheritance-by-example/
// create constructor function for base "class"
function Vehicle(hasEngine, hasWheels) {
this.hasEngine = hasEngine || false;
this.hasWheels = hasWheels || false;
}
// create constructor function
function Car (make, model, hp) {
this.hp = hp;
@bradoyler
bradoyler / askwiki.rb
Created February 25, 2014 14:33
a terminal script (Ruby) to query Wikipedia
## Setup steps via terminal:
# 1. create a .rb file : $ touch askwiki.rb
# 2. open file: $ open askwiki.rb
# 3. copy/paste below in file and close/save
# 4. run it: $ ruby askwiki.rb
require 'open-uri'
require 'json'
language = 'en'
@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