Skip to content

Instantly share code, notes, and snippets.

# 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
mahemoff / center-bootstrap-dialog
Created October 22, 2014 15:58
Vertically center BootstrapDialog. Put this code in your own application and ensure Bootstrap and BootstrapDialog were already sourced. Credit: http://stackoverflow.com/a/20486657/18706
.centerModal .modal-header{
text-align:left;
}
.centerModal .modal-body{
text-align:left;
}
@mahemoff
mahemoff / popover.coffee
Created October 26, 2014 09:46
Make jQuery Bootstrap popover sticky (don't disappear if you move into the popover) based on http://stackoverflow.com/a/19684440/18706
hideTimer = null
$('.launcher').popover(content: getContentHTML())
.on('mouseenter', ->
$this = $(this)
$this
.on('shown.bs.popover', -> $('.popover') .addClass('the-popover'))
.popover('show')
clearTimeout hideTimer
$('.popover').on('mouseleave', -> $this.popover('hide'))
).on('mouseleave', ->
@mahemoff
mahemoff / application_helper.rb
Last active August 29, 2015 14:08
Touch icons, manifests, etc in Ruby
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"))]
}
tags.join("\n").safe
end
@mahemoff
mahemoff / bottomVisible.javaScript
Created November 17, 2014 16:08
Live scrolling calculation - can user see bottom of element (or already scrolled past it)
elementBottom = $(element).offset().top + $(element).height()
lowestVisiblePointInBrowser = $(window).scrollTop() + $(window).height()
isElementBottomVisible = lowestVisiblePointInBrowser > elementBottom
# "provide" in controller for Rails streaming
# based on https://gist.github.com/hiroshi/985457
# FORCE to implement content_for in controller
def view_context
super.tap do |view|
(@_provide || {}).each do |name,content|
view.provide name, content
end
end
@mahemoff
mahemoff / rainbow.rb
Created January 5, 2015 14:04
Color manipulation - Proof-of-concept Ruby library for color manipulation by building on Sass
class Rainbow
def sass(command)
@@parser ||= Sass::Script::Parser
@@env = Sass::Environment.new
@@parser.parse(command, 0, 0).perform @@env
end
def saturation(color, amount) # amount is between -1 and 1
sass "change-color(#{color}, $saturation: #{100*amount})"
end
def lightness(color, amount) # amount is between -1 and 1
@mahemoff
mahemoff / gist:46de6bff8cc56780814e
Created January 22, 2015 15:24
id3 metadata in a No Agenda episode
> 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
> ./go.rb
before join []
Stored 2
Stored 0
Stored 1
Stored 3
Stored 4
after join [2, 0, 1, 3, 4]
@mahemoff
mahemoff / chromeswitch.script
Last active August 29, 2015 14:14
Automator script to fix Chrome's new user switcher (copied from attachment in https://code.google.com/p/chromium/issues/detail?id=112281)
on run {input, parameters}
tell application "Google Chrome"
activate
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 "✓"