Skip to content

Instantly share code, notes, and snippets.

if yes?("Add devise?")
gem 'devise'
after_bundle do
rails_command 'generate devise:install'
rails_command "generate devise #{model}"
end
end
@rubyconvict
rubyconvict / scanval.go
Created May 20, 2020 12:24 — forked from husobee/scanval.go
scanner valuer example
package main
import (
"database/sql"
"database/sql/driver"
"errors"
"fmt"
_ "github.com/mattn/go-sqlite3"
)
@rubyconvict
rubyconvict / set-access-point.sh
Created April 15, 2019 10:31 — forked from archy-bold/set-access-point.sh
Script to find the access points for the given network SSID and set the BSSID for that network to the MAC of the access point with the highest strength
#!/bin/bash
# Usage: ./set-access-points.sh [network SSID] [network interface id = wlan0]
# Read in the arguements
ssid=$1;
interface=$2;
# SSID is required
if [ -z "$ssid" ]; then
require "money"
class Decorator < BasicObject
undef_method :==
def initialize(component)
@component = component
end
def method_missing(name, *args, &block)
@rubyconvict
rubyconvict / activity_finder.rb
Last active August 23, 2017 07:24 — forked from sqrtsanta/activity_finder.rb
Preload associations of polymorphic objects
# http://api.rubyonrails.org/classes/ActiveRecord/EagerLoadPolymorphicError.html
# https://github.com/chaps-io/public_activity/issues/297
# https://ksylvest.com/posts/2017-08-23/eager-loading-polymorphic-associations-with-ruby-on-rails
class ActivityFinder
attr_reader :activities, :user
def initialize(user)
@user = user
@activities = Activity.all.where(:user_id => user_ids).
@rubyconvict
rubyconvict / bulk_reindexer.rb
Last active February 15, 2023 21:42 — forked from VvanGemert/bulk_reindexer.rb
Asynchronous bulk reindexing module for Searchkick with Sidekiq
# https://medium.com/rubyinside/asynchronous-elasticsearch-bulk-reindexing-with-rails-searchkick-and-sidekiq-26f2f9aa8513
# https://github.com/ankane/searchkick
# 2.3.2 [unreleased]
# - Added wait option to async reindex
# Searchkick.reindex(async: {wait: true})
# This code has been ported to searchkick.
require 'sidekiq/api'
# BulkReindexer
module BulkReindexer
@rubyconvict
rubyconvict / comment.rb
Last active July 26, 2017 05:14
NullObject
class Comment < ActiveRecord::Base
delegate :email, to: author, prefix: true, allow_nil: true
end
#! /usr/bin/env ruby
require 'dotenv'
Dotenv.load
require 'aws-sdk'
# USAGE:
# Put credentials in .env file, wrapped in single quotes. DO NOT COMMMIT this file to git!
# Wrap values in single quotes and escape all quotes inside strings with \.
# bundle exec ruby script/dev/example_s3.rb
#! /usr/bin/env ruby
require 'dotenv'
Dotenv.load
require 'redis'
# USAGE:
# Put credentials in .env file, wrapped in single quotes. DO NOT COMMMIT this file to git!
# Wrap values in single quotes and escape all quotes inside strings with \.
# bundle exec ruby script/dev/example_redis-rb.rb
#! /usr/bin/env ruby
# USAGE:
# sudo port install pwgen
# bundle exec ruby script/dev/bash_friendly_password.rb nil 49
def bash_friendly_password(password=nil, length=128)
password ||= `pwgen -syv #{length} 1`
password.size.times do |i|
password = password.