Skip to content

Instantly share code, notes, and snippets.

@bradgessler
bradgessler / oauth_google_controller.rb
Last active September 14, 2023 13:57
OAuth Google controller
class OAuth::GoogleAuthorizationsController < ApplicationController
CLIENT_ID = Rails.application.credentials.google.client_id
CLIENT_SECRET = Rails.application.credentials.google.client_secret
SCOPE = "openid email profile"
AUTHORIZATION_URL = URI("https://accounts.google.com/o/oauth2/v2/auth")
TOKEN_URL = URI("https://www.googleapis.com/oauth2/v4/token")
USER_INFO_URL = URI("https://www.googleapis.com/oauth2/v3/userinfo")
before_action :validate_state_token, only: :show
@dorianmariecom
dorianmariecom / generate-certificate.sh
Last active December 4, 2021 07:50
Generate certificate for HTTPS on localhost macOS / Rails / Puma
#!/bin/bash
set -e
echo "> Removing certificate"
sudo security delete-certificate -c localhost || true
echo "> Generating .key"
sudo openssl genrsa -out config/localhost.key 4096
@hopsoft
hopsoft / Dockerfile
Last active May 17, 2023 19:58
Dockerize your Rails app
FROM ruby:3.0-alpine
RUN apk add --no-cache --update \
ack \
bash \
build-base \
curl \
git \
htop \
less \
@sokhasen
sokhasen / LICENCE SUBLIME TEXT3
Last active November 1, 2023 13:18
Sublime Text 3.1.1 Serial key build is 3176
## Sublime Text 3.1.1 Serial key build is 3176
—– BEGIN LICENSE —–
sgbteam
Single User License
EA7E-1153259
8891CBB9 F1513E4F 1A3405C1 A865D53F
115F202E 7B91AB2D 0D2A40ED 352B269B
76E84F0B CD69BFC7 59F2DFEF E267328F
215652A3 E88F9D8F 4C38E3BA 5B2DAAE4
@mattbrictson
mattbrictson / Gemfile
Created September 11, 2015 15:55
Using vcr with Minitest + Rails (test unit style)
group :test do
gem "minitest"
gem "vcr"
gem "webmock", "~> 1.15.0"
end
# app/views/posts/show.html.erb
<article id="post-<%= @post.id %>" class="post">
<h1><%= @post.title %></h1>
<%= @post.body %>
<small><%= @post.author %></small>
<section class="comments">
<h2>Comments</h2>
<%= render @post.comments %>
</section>
</article>
@aghuddleston
aghuddleston / csv_for_excel.rb
Last active August 10, 2022 19:19
Write a CSV file using Ruby 2.2.2 which can open in Excel, properly displaying accents.
require 'csv'
module DownloadService
OPEN_MODE = "w+:UTF-16LE:UTF-8"
BOM = "\xEF\xBB\xBF" #Byte Order Mark
def student_list
File.open("#{file_name}.tsv", OPEN_MODE) do |f|
csv_file = CSV.generate({:col_sep => "\t"}) do |csv|
# header row
@andypike
andypike / gist:82eb791e948171e6ad4e
Last active October 21, 2022 12:25
Self registering classes that works within a Rails app without turning on eager_loading loading in development
# ./config/environments/development.rb
config.eager_load = false
# ./lib/registry.rb
module Registry
def self.included(base)
base.send(:extend, ClassMethods)
end
module ClassMethods
@andypike
andypike / gist:6fd735862302b09f5259
Last active October 21, 2022 12:25
Self registering ruby classes
class Toolbox
@tools = {}
def self.register(tool)
@tools[tool.material] = tool
end
def self.tool_for(material)
@tools.fetch(material) { BareHands }
end
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end