Skip to content

Instantly share code, notes, and snippets.

@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
@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")))
@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:3660246
Created September 6, 2012 20:45
Verify CSV has a uniform number of fields
awk -F ',' '{print NF}' foo.csv | uniq -c
@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:2933211
Created June 14, 2012 21:54
Ruby copy string to OSX clipboard
IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts markdown.to_html }
@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

@rstacruz
rstacruz / index.md
Last active May 27, 2026 15:23
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@norman
norman / earthdistance.rb
Last active May 10, 2026 18:08
Geographic Searches With Postgres's Earthdistance and Cube Extensions
#!/usr/bin/env ruby
=begin
= Geographic Searches With Postgres's Earthdistance and Cube Extensions
This program shows how to easily create a Postgres database that uses the Cube
and Earthdistance extensions to perform fast queries on geographic data.
Briefly, the problem this code solves is "show me all places within 50
kilometers of New York City."
@sontek
sontek / snowjob.py
Created December 22, 2011 04:24
Make your terminal snow with python
#!/usr/bin/env python
import os
import random
import time
import platform
snowflakes = {}
try:
# Windows Support