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
Util.encodeRFC5987 = (string) ->
encodeURIComponent(string)
# Note that although RFC3986 reserves "!", RFC5987 does not,
# so we do not need to escape it
.replace(/['()]/g, escape)
.replace(/\*/g, '%2A')
# The following are not required for percent-encoding per RFC5987,
# so we can allow for a little better readability over the wire: |`^
.replace(/%(?:7C|60|5E)/g, unescape)
 ⌘ ★ “ ” ‘ ’ ❝ ❞ ✔ × ✖ ✗ ✕ ⓧ ⊗ ⊕ ⊖ ⊙ ⊠ ⊡ ≠ ℻ © ® ← ↑ ↓ → ❮ ❯ ◄ ◂ ▸ ▷ ▹ ⌃ ¹ ² ³ ⁂ ▣ ⬚ Ⓜ ⓜ ⒨ ꟿ ṃ ♻ ♺
# Hide elements via selectors.
#
# Works wonderfully to block facebook ads which are
# pre-loaded ;o zomg
#
# Probably won't often update this gist, but selectors
# simply need to be added to @patterns
#
# You can avoid the transpile if you run this using
# the Injector, chrome extension. s'what I use.
# Converts a data image uri to canvas image
#
# reader = new FileReader()
# reader.onload = (evt) =>
# App.Util.dataToCanvas evt, el: @ui.thumb, width: 80, height: 40
# reader.readAsDataURL(...)
#
# @ui.thumb = jquery selector
# ultimately the jquery dependency can be 86ed from this...
#
# Returns an object with a new width and height
# constraining the proportions of the given max width
# and max height
#
# examples:
# Util.scaleProportion(200, 200, 2000, 2000);
# > Object {width: 200, height: 200}
# scaleProportion(200, 200, 2582, 2394)
# > Object {width: 200, height: 185}
#
# Convert int|float from seconds into formatted
# duration timestamp
#
# deps: underscore or lodash or any other library
# that takes over window._ and provides a
# #.compact() method. dep could ultimately
# be removed...
#
# uses double bitwise not `~~` as `Math.floor`
# uses `+` as type coercion to `int`
@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
# 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