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 / 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
# 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 / rust_api_certificate.rs
Created August 30, 2023 13:55
Add certificate and key in Rust API request
//https://www.reddit.com/r/learnrust/comments/y5qm0y/certificates_in_reqwest_crate/
let mut headers = HeaderMap::new();
headers.insert(ACCEPT, "application/json".parse().unwrap());
headers.insert("X-Application", "someKey".parse().unwrap());
// Format body
let login_params = [("username", "myusername"), ("password", "password")];
// create a certificate identity
let mut buf = Vec::new();
@harssh
harssh / ractors.rb
Created August 26, 2023 19:54 — forked from Kukunin/ractors.rb
Ruby Ractors vs Threads benchmark
require 'benchmark'
require 'etc'
Ractor.new { :warmup } if defined?(Ractor)
def fibonacci(n)
return n if (0..1).include? n
fibonacci(n - 1) + fibonacci(n - 2)
end
@harssh
harssh / iam_fog.rb
Created August 17, 2023 18:40 — forked from zapnap/iam_fog.rb
Using Amazon IAM with Fog (example)
require 'fog'
username = 'testuser'
bucket = 'uniquebucketname1234'
aws_credentials = {
:aws_access_key_id => 'YOUR-ACCESS-KEY-ID',
:aws_secret_access_key => 'YOUR-SECRET-ACCESS-KEY'
}