Skip to content

Instantly share code, notes, and snippets.

Feature: Facebook Connect
Scenario: Sign in with Facebook
When I go to the sign in page
And I press "Sign in with Facebook"
And Facebook returns uid:"123", nickname:"chunky.bacon", first_name:"Chunky", last_name:"Bacon", email:"bacon@mysite.co.nz"
Then I should see "Your mysite account was successfully created"
...
gem 'devise',
:git => 'https://github.com/plataformatec/devise.git',
:branch => 'omniauth'
gem 'oa-oauth', :require => 'omniauth/oauth'
...
@harssh
harssh / omniauth_macros.rb
Created May 16, 2024 21:30 — forked from kinopyo/omniauth_macros.rb
Integration test with Omniauth. This example is using twitter, and assume you've installed rspec and capybara. Official document is here: https://github.com/intridea/omniauth/wiki/Integration-Testing
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
module Devise
module Models
# Registerable is responsible for everything related to registering a new
# resource (ie user sign up).
module Registerable
extend ActiveSupport::Concern
module ClassMethods
# A convenience method that receives both parameters and session to
# initialize a user. This can be used by OAuth, for example, to send
@harssh
harssh / free_memory.txt
Created October 14, 2014 05:05
free up memory in ubuntu
Check Memory Usage in Real-Time
You can check your current memory usage using this command:
watch -n 1 free -m
This command will also display in real-time your system memory usage:
@harssh
harssh / warning.rb
Created February 28, 2024 20:40
warning.rb
# Define a "warnings" validation bucket on ActiveRecord objects.
#
# @example
#
# class MyObject < ActiveRecord::Base
# warning do |vehicle_asset|
# unless vehicle_asset.description == 'bob'
# vehicle_asset.warnings.add(:description, "should be 'bob'")
# end
# end
@harssh
harssh / table_list.rb
Created November 20, 2013 04:35
List all tables in rails app using console
# This command will list all table in a rails app in rails console
ActiveRecord::Base.connection.tables
# requires :password_reset_token and :password_reset_token_expires_at fields
module PasswordResetable
extend ActiveSupport::Concern
included do
before_validation do
if password_reset_token_expires_at && password_reset_expires_at.past?
expire_password_reset!
end
end
@harssh
harssh / README.md
Created September 26, 2023 02:58 — forked from noelbundick/README.md
Optimizing Rust container builds

Optimizing Rust container builds

I'm a Rust newbie, and one of the things that I've found frustrating is that the default docker build experience is extremely slow. As it downloads crates, then dependencies, then finally my app - I often get distracted, start doing something else, then come back several minutes later and forget what I was doing

Recently, I had the idea to make it a little better by combining multistage builds with some of the amazing features from BuildKit. Specifically, cache mounts, which let a build container cache directories for compilers & package managers. Here's a quick annotated before & after from a real app I encountered.

Before

This is a standard enough multistage Dockerfile. Nothing seemingly terrible or great here - just a normal build stage, and a smaller runtime stage.

@harssh
harssh / validate_unique_combination_of_multiple_columns_in_rails.rb
Created October 27, 2013 16:33
Rails: Validate unique combination of multiple columns
The validation syntax where multiple columns combination is validated for uniqueness is :
validates_uniqueness_of :column_namae1, :scope => [:column_name2, :column_name3]
or even shorter in ruby 1.9.x:
validates_uniqueness_of :column_name1, scope: [:column_name2, :column_name3]