Skip to content

Instantly share code, notes, and snippets.

@jonathanmoore
jonathanmoore / gist:2640302
Created May 8, 2012 23:17
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@bds
bds / gist:2933211
Created June 14, 2012 21:54
Ruby copy string to OSX clipboard
IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts markdown.to_html }
@davidjrice
davidjrice / redcarpet.rb
Created June 29, 2012 00:34
Rails 3.2 Markdown Template Handler
# config/initializers/redcarpet.rb
module ActionView
module Template::Handlers
class Markdown
class_attribute :default_format
self.default_format = Mime::HTML
def call(template)
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
markdown.render(template.source).html_safe.inspect
@bds
bds / gist:3660246
Created September 6, 2012 20:45
Verify CSV has a uniform number of fields
awk -F ',' '{print NF}' foo.csv | uniq -c
@mattconnolly
mattconnolly / gist:4158961
Created November 28, 2012 04:04
RSpec basic authentication helper module for request and controller specs
module AuthHelper
def http_login
user = 'username'
pw = 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
module AuthRequestHelper
#
@bds
bds / gist:4192180
Created December 3, 2012 02:11
Subset an R dataframe by a list of dates
subset(df, sprint.end.date %in% as.Date(c("2012-11-16", "2012-11-30")))
@artm
artm / xmas.rb
Created December 20, 2012 10:25
a derivative work from climagick's "Let It Snow In Your Terminal" (http://climagic.org/coolstuff/let-it-snow.html), see also https://gist.github.com/4344001
require 'set'
rows,columns = `stty size`.scan(/\d+/).map{|x| x.to_i}
# ruby 1.8.x compatible way to say "\u2743"
Flake = ["2743".to_i(16)].pack("U*")
# Shapes from far away to still closer
Snow = ['.','*',Flake]
# flake state descriptor
class Safeware
def initialize(app)
@app = app
end
# This dup pattern is used frequently to avoid race conditions on state stored
# inside this middleware. It's not foolproof, but if you're just using
# single-reference instance variables (instance variables with primitive
# values (not data structures)) then it works well.
require 'addressable/uri'
# Source: http://gist.github.com/bf4/5320847
# Accepts options[:message] and options[:allowed_protocols]
# spec/validators/uri_validator_spec.rb
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
uri = parse_uri(value)
if !uri
@Integralist
Integralist / rules for good testing.md
Last active March 23, 2026 03:03
Sandi Metz advice for writing tests

Rules for good testing

Look at the following image...

...it shows an object being tested.

You can't see inside the object. All you can do is send it messages. This is an important point to make because we should be "testing the interface, and NOT the implementation" - doing so will allow us to change the implementation without causing our tests to break.