Skip to content

Instantly share code, notes, and snippets.


Michael Mahemoff mahemoff

View GitHub Profile
View balance_text.rb
# A rought attempt at balancing text. Injects normal spaces (thus allowing a newline) after too many characters; otherwise
# adds a non-breaking space.
# It works in reverse because we'd rather have longer text on top than on bottom.
def some_non_breaking_spacing(s)
words = s.split(/\s+/).reverse
first_word = words.shift
html_tokens = [first_word]
chars_since_normal_space = first_word.length
mahemoff / center-bootstrap-dialog
Created Oct 22, 2014
Vertically center BootstrapDialog. Put this code in your own application and ensure Bootstrap and BootstrapDialog were already sourced. Credit:
View center-bootstrap-dialog
.centerModal .modal-header{
.centerModal .modal-body{
mahemoff /
Created Oct 26, 2014
Make jQuery Bootstrap popover sticky (don't disappear if you move into the popover) based on
hideTimer = null
$('.launcher').popover(content: getContentHTML())
.on('mouseenter', ->
$this = $(this)
.on('', -> $('.popover') .addClass('the-popover'))
clearTimeout hideTimer
$('.popover').on('mouseleave', -> $this.popover('hide'))
).on('mouseleave', ->
mahemoff / application_helper.rb
Last active Aug 29, 2015
Touch icons, manifests, etc in Ruby
View application_helper.rb
def touch_icons
tags = [tag('link', rel: 'apple-touch-icon-precomposed', href: '/apple-touch-icon-precomposed.png')]
%w(36 48 57 72 76 114 120 144 152 180 192 512).each { |size|
tags += [tag('link', rel: 'apple-touch-icon-precomposed', size:"#{size}x#{size}", href: asset_path("logos/v3/icon#{size}x#{size}.png"))]
mahemoff / bottomVisible.javaScript
Created Nov 17, 2014
Live scrolling calculation - can user see bottom of element (or already scrolled past it)
View bottomVisible.javaScript
elementBottom = $(element).offset().top + $(element).height()
lowestVisiblePointInBrowser = $(window).scrollTop() + $(window).height()
isElementBottomVisible = lowestVisiblePointInBrowser > elementBottom
View application_controller.rb
# "provide" in controller for Rails streaming
# based on
# FORCE to implement content_for in controller
def view_context
super.tap do |view|
(@_provide || {}).each do |name,content|
view.provide name, content
mahemoff / rainbow.rb
Created Jan 5, 2015
Color manipulation - Proof-of-concept Ruby library for color manipulation by building on Sass
View rainbow.rb
class Rainbow
def sass(command)
@@parser ||= Sass::Script::Parser
@@env =
@@parser.parse(command, 0, 0).perform @@env
def saturation(color, amount) # amount is between -1 and 1
sass "change-color(#{color}, $saturation: #{100*amount})"
def lightness(color, amount) # amount is between -1 and 1
mahemoff / gist:46de6bff8cc56780814e
Created Jan 22, 2015
id3 metadata in a No Agenda episode
View gist:46de6bff8cc56780814e
> id3info NA-680-2014-12-21-Final.mp3
│*** Tag information for NA-680-2014-12-21-Final.mp3
│=== TIT2 (Title/songname/content description): 680 NA-680-2014-12-21
│=== TPE1 (Lead performer(s)/Soloist(s)): Adam Curry & John C Dvorak
│=== TALB (Album/Movie/Show title): No Agenda
│=== TCON (Content type): Podcast
│=== TENC (Encoded by): Fission
│=== COMM (Comments): ()[eng]: No Agenda Episode 680 - Sir Thomas Nussbaum presents "Sponsored Content"
│ Executive Producers: Sir RS Bagwell, Sir Oscar Nadal, Sir Barry Hanna, Todd McGreavy, Sir Ted Hosmann
View Sample output (output order of "stored" items is random)
> ./go.rb
before join []
Stored 2
Stored 0
Stored 1
Stored 3
Stored 4
after join [2, 0, 1, 3, 4]
mahemoff / chromeswitch.script
Last active Aug 29, 2015
Automator script to fix Chrome's new user switcher (copied from attachment in
View chromeswitch.script
on run {input, parameters}
tell application "Google Chrome"
tell application "System Events"
tell process "Google Chrome"
set frontmost to true
set firstProfileSelected to (value of attribute "AXMenuItemMarkChar" of menu item 1 of menu "People" of menu bar 1) is "✓"