Skip to content

Instantly share code, notes, and snippets.

@kevinhq
kevinhq / has_many_through_with_includes_inside_scope.rb
Last active June 7, 2018 15:30
Confirm Rails 5.1.6 behavior for includes inside has_many scope
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '5.1.6'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@kevinhq
kevinhq / has_many_through_with_includes_inside_scope_rails4.rb
Last active June 7, 2018 15:29
Confirm Rails 4 behavior for includes inside has_many scope
unless File.exists?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', '4.2.10'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@kevinhq
kevinhq / minimal-analytics-snippet.js
Created December 21, 2018 09:29 — forked from DavidKuennen/minimal-analytics-snippet.js
Minimal Analytics Snippet
(function (context, trackingId, options) {
const history = context.history;
const doc = document;
const nav = navigator || {};
const storage = localStorage;
const encode = encodeURIComponent;
const pushState = history.pushState;
const typeException = 'exception';
const generateId = () => Math.random().toString(36);
const getId = () => {
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", "6.0.2.2"
gem "sqlite3"
@kevinhq
kevinhq / migrate_paperclip_to_s3.rake
Created April 21, 2020 11:35 — forked from awd/migrate_paperclip_to_s3.rake
Migrate local paperclip assets to Amazon S3.
##
# Use this behind the scenes to migrate files from your filesystem to Amazon S3
# %: rake paperclip_migration:migrate_to_s3
##
namespace :attachments do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
require 'aws/s3'
@kevinhq
kevinhq / migrate_paperclip_to_s3.rake
Created April 21, 2020 11:36 — forked from awd/migrate_paperclip_to_s3.rake
Migrate local paperclip assets to Amazon S3.
##
# Use this behind the scenes to migrate files from your filesystem to Amazon S3
# %: rake paperclip_migration:migrate_to_s3
##
namespace :attachments do
desc "migrate files from filesystem to s3"
task :migrate_to_s3 => :environment do
require 'aws/s3'
@kevinhq
kevinhq / README.md
Created April 25, 2020 11:20 — forked from soxofaan/README.md
Simple pretty CSV and TSV file viewer.
@kevinhq
kevinhq / clean.sh
Created May 26, 2020 09:22 — forked from Iman/clean.sh
Free up disk space on Ubuntu - clean log, cache, archive packages/apt archives, orphaned packages, old kernel and remove the trash
#!/bin/sh
#Check the Drive Space Used by Cached Files
du -sh /var/cache/apt/archives
#Clean all the log file
#for logs in `find /var/log -type f`; do > $logs; done
logs=`find /var/log -type f`
for i in $logs
@kevinhq
kevinhq / Gemfile
Last active August 11, 2022 15:20
How to implement two-factor authentication for Rails app by using Devise gem, Google authenticator, and ActiveModel::Otp gem
gem 'devise', '~> 4.7.1'
gem 'active_model_otp', '~> 2.0.1'
gem 'rqrcode', '~> 1.1.2'
@kevinhq
kevinhq / activate_2fa.html.erb
Created June 23, 2020 11:43
Two-Factor authentication form with QR code
<# /app/views/users/activate_2fa.html.erb %>
<%= @svg.html_safe %>
<%= form_for(@user, url: activate_2fa_update_path) do |f| %>
<%= f.text_field :otp_response_code %>
<%= f.submit %>
<% end %>