Skip to content

Instantly share code, notes, and snippets.

@FiXato
Last active December 11, 2015 20:59
Show Gist options
  • Save FiXato/4659580 to your computer and use it in GitHub Desktop.
Save FiXato/4659580 to your computer and use it in GitHub Desktop.
Handy Ruby and CSS Snippets
/* Put the href of all anchors after each link. Useful for print stylesheets. */
a:after {content: attr(href);}
/* Get a scrollbar on the left side */
#nav {max-height:150px; width: 100%; overflow: auto; direction: rtl;}
#nav * {direction: ltr}
/* Nicer looking blockquotes */
blockquote {margin-left: 1em;margin-bottom: 1em; border: 1px solid #666; max-width: 800px;}
/* Including nicer quotation marks */
blockquote p:before {content: "\2018"; font-weight: bold; font-size: 1.5em;}
blockquote p:after {content: "\2019"; font-weight: bold; font-size: 1.5em;}
/* or: */
blockquote p { quotes: '\201C' '\201D'; }
blockquote p:before { content: open-quote; font-size: 1.5em;}
blockquote p:after { content: close-quote; font-size: 1.5em;}
/* HTML code for it:
<blockquote cite="http://weechat.org/files/doc/devel/weechat_user.en.html#key_bindings">
<p>Without completion: do a partial completion, with pending completion: complete with previous completion.</p>
<footer>— <a href="http://weechat.org/files/doc/devel/weechat_user.en.html#key_bindings">WeeChat Default Keybindings:</a></footer>
</blockquote>
*/
/* In more details and with more examples, including nested <q> quotes: http://html5doctor.com/blockquote-q-cite/ */
#!/usr/bin/env ruby
#encoding: utf-8
# Convert your MatchData to a Hash when using Named Captures.
class MatchData
def to_hash
Hash[self.names.map{|n|n.force_encoding('utf-8')}.zip(self.captures)]
end
end
# msg = "[1-7] Porto Mojada: Foxtrot Tango [Work your alphabets]"
# regexp = /(\[SOLVED: (?<solution>.+?)\] )?\[(?<num1>\d+)(-(?<num2>\d+))?\] (?<title>.+?)( \[(?<hint>.+?)\])?\z/
# puts msg.match(regexp).to_hash
# {"solution"=>nil, "num1"=>"1", "num2"=>"7", "title"=>"Porto Mojada: Foxtrot Tango", "hint"=>"Work your alphabets"}
#--------------------------------------------------------------------------------------
# Overview of the difference between the various beginning and ending of line matchers:
# ^ - Matches beginning of line
# $ - Matches end of line
# \A - Matches beginning of string.
# \Z - Matches end of string. If string ends with a newline, it matches just before newline
# \z - Matches end of string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment