Skip to content

Instantly share code, notes, and snippets.

http://snippets.dzone.com/posts/show/5364
Strftime to get the ISO 8601 (see RFC 3339) full date format for an hEvent Microformat. Doubtless usable in other situations.
strftime('%Y-%m-%dT%H:%M:%S%z');
If you're in Ruby, you can access this the quick way with:
$ irb
>> require 'time'
@guenter
guenter / api.feature
Created June 24, 2010 17:55
Snippets for testing REST APIs with Cucumber and friends
Feature: API
In order to use the service from third party apps
As a user
I want to be able to use an API
Background:
Given a user exists # Pickle
And I login as the user using basic auth
Scenario Outline: Get a ticket
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@zoras
zoras / rmagick.sh
Created August 2, 2011 17:14
Install RMagick on Ubuntu 11.04
sudo apt-get install libdjvulibre-dev libjpeg-dev libtiff-dev libwmf-dev libmagickcore-dev libmagickwand-dev libmagick++-dev rvm
sudo gem install rmagick
ok!
Fetching: rmagick-2.13.1.gem (100%) Building native extensions. This could take a while ... Successfully installed rmagick-2.13.1 1 gem installed
require 'RMagick' #=> true
@CristinaSolana
CristinaSolana / gist:1885435
Created February 22, 2012 14:56
Keeping a fork up to date

1. Clone your fork:

git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git

2. Add remote from original repository in your forked repository:

cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
@rf-
rf- / validator.rb
Created April 6, 2012 19:57
Demonstrate validation of arbitrary fields (e.g., hstore)
#!/usr/bin/env ruby
require 'active_record'
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => ':memory:'
)
ActiveRecord::Schema.define do
@machty
machty / index.html.slim
Created April 7, 2012 14:24
An attempt at Slim/Haml helpers for handlebars
= handlebars_template_named "edit-field" do
= hb %{ if isEditing } do
= hb %{ view BD.TextField valueBinding="value" }
= hb_else
= hb %{ if value } do
= hbb %{ value }
= hb_else
span.no-name empty
/ Outputs
@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

@evanbeard
evanbeard / registrations_controller.rb
Created May 11, 2012 19:53 — forked from jwo/registrations_controller.rb
API JSON authentication with Devise
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user = User.new(params[:user])
if user.save
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>user.email), :status=>201
return
else
@gacha
gacha / tinymce_fill_in.rb
Created November 1, 2012 19:23
Fill in text into tinymce for capybara, using native input for selenium and JS for other
# used as example https://groups.google.com/d/msg/ruby-capybara/XhDAHGjZSjA/VwiW0-2nOIEJ
# IMPORTANT! To do the real simulation you need chrome driver - http://code.google.com/p/selenium/downloads/list, download and add to PATH
def tinymce_fill_in name, options = {}
if page.driver.browser.browser == :chrome
page.driver.browser.switch_to.frame("#{name}_ifr")
page.find(:css, '#tinymce').native.send_keys(options[:with])
page.driver.browser.switch_to.default_content
else
page.execute_script("tinyMCE.get('#{name}').setContent('#{options[:with]}')")
end