Skip to content

Instantly share code, notes, and snippets.


Stephen Benner SteveBenner

View GitHub Profile
SteveBenner / htmlElem.js
Last active Dec 17, 2015
This function constructs an HTML element and returns it, wrapped in a jQuery object
View htmlElem.js
* Constructs and returns an HTML element wrapped in a jQuery object
* @param {String} tag Name of the HTML element
* @param {Object} attr Map of attribute key/value pairs for the HTML element
* @param {String} content Content to be directly inserted inside HTML tags
function htmlElem(tag, attr, content) {
tag = tag || 'div'; attr = attr || ''; content = content || ''; // optional parameters
var htmlString = '<' + tag
SteveBenner / halves.rb
Last active Dec 17, 2015
Divide an array into equal halves
View halves.rb
# @return [Array] Two-member Array containing self evenly split into two sub-arrays
# @example
# [1,2,3,4].halves #=> [[1,2],[3,4]]
# [1,2,3].halves #=> [[1,2],[3]]
def halves
[self[0..(self.size/2.0).round-1], self[(self.size/2.0).round..self.size]]
SteveBenner / zipr.rb
Last active Dec 17, 2015
Recursive zip
View zipr.rb
# @param [Integer] n Number of times to call zip upon self
# @return [#zip] Self, after calling Array#zip upon self given number of times
def zipr(n = self.length)
r = self
n.times { r = }
SteveBenner / subdv.rb
Last active Dec 17, 2015
Subdivide a list into sub-lists of specified length
View subdv.rb
# @param [Array<Integer>] List of sizes of the partitions self will be subdivided into
# @return [Object] Array containing self divided into one or more sub-arrays of size n
# @example
# [1,2,3].subdv [1] #=> [[1]]
# [1,2,3].subdv [3] #=> [[1,2,3]]
# [1,2,3].subdv [1,2] #=> [[1],[2,3]]
# [1,2,3].subdv [1,2] #=> [[1],[2,3]]
# [1,2,3].subdv [1,1,1] #=> [[1],[2],[3]]
# [1,2,3].subdv [1,2,1] #=> [[1],[2,3],[]]
def subdv(arr)
SteveBenner / cap-execute_at.rb
Created Nov 6, 2013
Capistrano DSL addition for executing a command under a specific working directory
View cap-execute_at.rb
# allows one to specify the working directory for command execution
def execute_at(path, cmd)
execute "cd #{path} && #{cmd}"
SteveBenner / sitemap.xml.slim
Last active Apr 24, 2016 — forked from ls-lukebowerman/sitemap.xml.erb
Slim template - generates a sitemap for Middleman
View sitemap.xml.slim
- pages = sitemap.resources.find_all{|p| p.source_file.match(/\.html/) }
doctype xml
urlset xmlns=""
- pages.each do |p|
loc "http://www.YOUR_WEBSITE_URL/#{p.destination_path.gsub('/index.html','')}"
lastmod =
changefreq = || 'weekly'
priority = || '0.5'
SteveBenner / _html5video.slim
Last active Oct 5, 2016
Slim partial - HTML5 video tag
View _html5video.slim
/ Generate an HTML5 video tag with embedded Flash fallback
/ @see HTML5 video tag spec
/ @local [Hash] video Attribute hash for the `video` tag
/ @option video [Integer] :width (320) Width of the video tag in pixels
/ @option video [Integer] :height (240) Height of the video tag in pixels
/ @local [Hash] src Mapping of source file types to URLs for source files
/ @option src [String] :mp4 URL of an MP4 source file for the video
/ @option src [String] :webm URL of a WebM source file for the video
SteveBenner / sass-convert-dir.rb
Created Mar 23, 2014
Recursively convert a directory of SASS files from one syntax to the alternate one
View sass-convert-dir.rb
DIR = '<project-root>'
files = Dir.glob("#{DIR}/**/*.scss")
files.each { |f| `sass-convert #{f} #{f.sub(/\.scss/, '.sass')}` unless File.exist?(f.sub(/\.scss/, '.sass')) }
# one-liner for CLI use
# ruby -e "Dir.glob('<project-root>/**/*.scss').each { |f| `sass-convert #{f} #{f.sub(/\.scss/, '.sass')}` unless File.exist?(f.sub(/\.scss/, '.sass')) }"
View github-readme-markdown-styles.sass
// Github markdown styles
$h1-grey: #dddddd
$h2-grey: #eeeeee
$header-black: #333333
// placeholders
background: url(data:image/png) no-repeat 10px center
text-decoration: none
SteveBenner / _disqus.slim
Last active Aug 29, 2015 — forked from voigt/disqus.js
Slim partial - Disqus comments widget
View _disqus.slim
/ Integrate Disqus comments into your site with this widget (adheres to official API and config spec)
/ @see Official web integration docs
/ @see Configuration docs
/ @local [Hash{Symbol => String}] disqus Key/value pairs corresponding to the Disqus JS configuration variables
/ @option disqus [String] shortname Unique identifier for your forum website registered on (REQUIRED)
/ @option disqus [String] identifier A String or Integer value which identifies the current web page thread
/ @option disqus [String] title Title of the current page; defaults to value of HTML `title` element
/ @option disqus [String] url URL of the current page; defaults to `window.location.href`
You can’t perform that action at this time.