Skip to content

Instantly share code, notes, and snippets.

View moimikey's full-sized avatar
:shipit:
ship it

Michael Scott Hertzberg moimikey

:shipit:
ship it
View GitHub Profile
@moimikey
moimikey / functions.js
Created August 13, 2014 15:51
Firebug lite's useful helper methods condensed
this.arrayInsert = function (array, index, other) {
for (var i = 0; i < other.length; ++i) {
array.splice(i + index, 0, other[i])
}
return array
};
this.createStyleSheet = function (doc, url) {
var style = this.createElement("link");
style.setAttribute("charset", "utf-8");
style.setAttribute("rel", "stylesheet");
@moimikey
moimikey / array_reverse.js
Last active June 14, 2023 17:08
reversing an array, the fast and simple way!
var i, arr = [1, 2, 3, 4, 5, 6, 7, 8];
for(i = 0; i < arr.length / 2; i++) {
var temp = arr[i];
arr[i] = arr[arr.length - i - 1]
arr[arr.length - i - 1] = tmp
}
/*
passes:
@moimikey
moimikey / app.coffee
Last active August 29, 2015 14:05
Basic grunt + browserify + coffeescript + backbone + marionette
'use strict'
$ = require('jquery')
Backbone = require('backbone')
Backbone.$ = $
Marionette = require('backbone.marionette')
View = require('./view')
$ ->
##
# create an insanely tiny placeholder gif
# output in base64
#
# i'm still working the bytes... so this is
# a working proto but it needs to be further
# edited...
#
# as much as possible in accordance to GIF spec.
class Dick
@moimikey
moimikey / konami.coffee
Last active October 3, 2015 22:39
a standalone marionette module you can use in your own app to add a single konami code
@MM.module 'KonamiApp', (KonamiApp, App, Backbone, Marionette, $, _) ->
# up, up, down, down, left, right, left, right, a, enter
KonamiApp.sequence = [38, 38, 40, 40, 37, 39, 37, 39, 65, 13]
KonamiApp.pressed = []
KonamiApp.on
'start': ->
$(window).on 'keyup.konami', KonamiApp.pressedKey
'stop': ->
$(window).off '.konami'
# determine if the supplied array is filled with only
# numbers.
#
# App.Util.isArrayNumbers([1,2,3,4,5,6])
# > true
# App.Util.isArrayNumbers([1, 2, 3, 4, 5, 6, 'a'])
# > false
#
Util.isArrayNumbers = (arr) ->
_.uniq(_.map arr, (num) ->
# reduce an array of numbers and return
# the sum
Util.reduceAddArray = (arr) ->
return unless Util.isArrayNumbers(arr)
_.reduce arr, (a, b) ->
a + b
Util.isElementInViewport = (el) ->
el = el[0] if el instanceof jQuery
return unless el?
rect = el.getBoundingClientRect()
rect.top >= 0 and
rect.left >= 0 and
rect.bottom <= (window.innerHeight or document.documentElement.clientHeight) and
rect.right <= (window.innerWidth or document.documentElement.clientWidth)
Util.isElementInViewOf = (el, parent) ->
el = el[0] if el instanceof jQuery
parent = parent[0] if parent instanceof jQuery
return unless el? and parent?
rect = el.getBoundingClientRect()
rect.top >= 0 and
rect.left >= 0 and
rect.bottom <= parent.clientHeight and
# absolute document height
Util.getDocumentHeight = ->
Math.max document.body.scrollHeight or 0,
document.documentElement.scrollHeight or 0,
document.body.offsetHeight or 0,
document.documentElement.offsetHeight or 0,
document.body.clientHeight or 0,
document.documentElement.clientHeight or 0