Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
@lightningdb
lightningdb / goodreads-bookmarklet.js
Last active November 22, 2023 17:36
Add to Goodreads from Amazon.com book page bookmarklet
javascript: var asin_elements, asin;asin_elements = document.getElementsByName('ASIN'); if (asin_elements.length == 0) { asin_elements = document.getElementsByName('ASIN.0'); };if (asin_elements.length == 0) { alert('Sorry, this doesn\'t appear to be an Amazon book page.'); }else { asin = asin_elements[0].value; if (asin.match(/\D/) === null) { var x = window.open('http://www.goodreads.com/review/isbn/'+ asin, 'add_review'); } else { var x = window.open('https://www.goodreads.com/search?q='+ asin); } x.focus();}
@lightningdb
lightningdb / publish.sh
Created April 6, 2012 23:58
Publish documentation to directory reflecting tag or branch in gh-pages branch
#!/bin/sh
# get current branch and tag
branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`;
tag=`git describe --tags`;
# if current tag has annotations showing number of commits since tagging, then use current branch
destination="$tag"
if [[ "$tag" == *-* ]]
then
@lightningdb
lightningdb / OptionExample.rb
Created June 23, 2010 23:11
OptionHashExample.rb
# A method signature such as:
def blah(file, underscore_to_hyphen=true)
# will be called like so:
blah(file, true)
# where true could also be false
# this is a code smell, since it is impossible to tell
# from the call what the boolean does
# rather than
if some_condition
return true
else
return false
end
# you can use
var ||= the_value
many_elements.each do |foo|
dict[foo] ||= expensive_computation
end
# longer and harder to read, with redundant lines
facet_values_after = []
facet_values.each do | facet_value |
facet_value = facet_value.gsub(/\_/, '\-')
facet_values_after << facet_value.gsub(/"/, '\"')
end
return facet_values_after
# can be turned into
# instead of:
if retail_chains && retail_chains.size > 0
return retail_chains[0]
end
# you could write:
retail_chains.first unless retail_chains.blank?
# For Level 16 developers
# Instead of:
if !retailers.empty?
# Use this:
unless retailers.empty?