Skip to content

Instantly share code, notes, and snippets.

Avatar

Stephen Benner SteveBenner

View GitHub Profile
@SteveBenner
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
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]]
end
@SteveBenner
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 = r.zip }
r
end
@SteveBenner
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
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}"
end
@SteveBenner
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="http://www.sitemaps.org/schemas/sitemap/0.9"
- pages.each do |p|
url
loc "http://www.YOUR_WEBSITE_URL/#{p.destination_path.gsub('/index.html','')}"
lastmod = Date.today.to_time.iso8601
changefreq = p.data.changefreq || 'weekly'
priority = p.data.priority || '0.5'
@SteveBenner
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 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video 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
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
%hover-link
background: url(data:image/png) no-repeat 10px center
text-decoration: none
@SteveBenner
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 https://help.disqus.com/customer/portal/articles/1104788-web-integration Official web integration docs
/ @see https://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables 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 Disqus.com (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.