Skip to content

Instantly share code, notes, and snippets.

View adamcrown's full-sized avatar

Adam Crownoble adamcrown

View GitHub Profile
@adamcrown
adamcrown / white_pages-template.html
Created January 5, 2013 01:18
A simple Liquid template for "White Pages" reports with the applyfor app
<html>
<head>
<title>RA White Pages</title>
<style type="text/css">
* {
font-family: Arial, sans-serif;
font-size: 10pt;
}
# We save a series of custom events when a student takes a quiz. These events
# give us interesting insights into quiz-taking behavior.
#
# We want to write code that uses these events to answer questions
# about a particular quiz attempt.
#
## The Events
# We store the events in a series of records stored as JSON. There are
# six different types of events:
# - `start_quiz`: The student started taking the quiz
@adamcrown
adamcrown / .irbrc
Last active November 7, 2023 06:34
My Bundler proof .irbrc file including wirble, awesome_print, hirb, console logging and route helpers
require 'rubygems' unless defined? Gem # rubygems is only needed in 1.8
def unbundled_require(gem)
loaded = false
if defined?(::Bundler)
Gem.path.each do |gems_path|
gem_path = Dir.glob("#{gems_path}/gems/#{gem}*").last
unless gem_path.nil?
$LOAD_PATH << "#{gem_path}/lib"
@adamcrown
adamcrown / Gemfile
Created November 5, 2015 07:03
A basic mailer API intended to be used as a contact form backend for a static site.
source 'https://rubygems.org'
gem 'rack'
gem 'mail'
gem 'puma'
@adamcrown
adamcrown / middleware-example.rb
Last active February 4, 2019 03:55
An example of baking our own middleware stack to better understand how Rack middleware works.
class Talk
def call(env)
"Can I talk to #{env[:name]}!"
end
end
class Shout
def initialize(app)
@app = app
end
@adamcrown
adamcrown / polymorphic_belongs_to_finder.rb
Created October 18, 2018 06:36
Find polymorphic associations to a model
# Finds all column that reference a certain model name via a polymorphic association.
# This is helpful when renaming a table, because if you don't update the model names
# in these polymorphic belongs_to associations they will break.
class PolymorphicBelongsToFinder
POLYMORPHIC_COLUMN_MATCH = /_type\Z/.freeze
def initialize(old_model_name)
@old_model_name = old_model_name
end
@adamcrown
adamcrown / AWS_Single_LetsEncrypt.yaml
Created August 17, 2017 08:30 — forked from tony-gutierrez/AWS_Single_LetsEncrypt.yaml
AWS Elastic Beanstalk .ebextensions config for single instance free SSL using letsencrypt certbot and nginx. http://bluefletch.com/blog/domain-agnostic-letsencrypt-ssl-config-for-elastic-beanstalk-single-instances/
# Dont forget to set the env variable "certdomain", and either fill in your email below or use an env variable for that too.
# Also note that this config is using the LetsEncrypt staging server, remove the flag when ready!
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
@adamcrown
adamcrown / couchdb 2.0 install
Created October 29, 2016 09:50 — forked from SinanGabel/Cluster setup hints
CouchDB 1.7.0 (1.x.x) / 2.0 (release-candidate) on Ubuntu 16.04
# Tried on Ubuntu 16.04 Desktop
# Refer to: http://couchdb.apache.org/release-candidate/2.0/
# (1) Install npm and nodejs
# Run this command and if it says “install” in the right column - “node” is on your system:
pkg --get-selections | grep node
# To remove eventual old node package, run:
apt-get remove --purge node
@adamcrown
adamcrown / dmesg-grep-iwl.output
Created November 5, 2016 15:08
dmesg | grep iwl - Direct firmware load for iwlwifi-7265D-24.ucode failed with error -2
[ 2.280067] iwlwifi 0000:02:00.0: enabling device (0000 -> 0002)
[ 2.280492] iwlwifi 0000:02:00.0: Direct firmware load for iwlwifi-7265D-24.ucode failed with error -2
[ 2.280655] iwlwifi 0000:02:00.0: Direct firmware load for iwlwifi-7265D-23.ucode failed with error -2
[ 2.284498] iwlwifi 0000:02:00.0: loaded firmware version 22.361476.0 op_mode iwlmvm
[ 2.334381] iwlwifi 0000:02:00.0: Detected Intel(R) Dual Band Wireless AC 7265, REV=0x210
[ 2.336473] iwlwifi 0000:02:00.0: L1 Enabled - LTR Disabled
[ 2.336680] iwlwifi 0000:02:00.0: L1 Enabled - LTR Disabled
[ 2.403059] ieee80211 phy0: Selected rate control algorithm 'iwl-mvm-rs'
[ 2.419105] iwlwifi 0000:02:00.0 wlp2s0: renamed from wlan0
[ 3.905727] iwlwifi 0000:02:00.0: L1 Enabled - LTR Disabled
@adamcrown
adamcrown / user.rb
Created October 25, 2016 03:19
couchrest_model User model
class User < CouchRest::Model::Base
self.database = server.database('_users')
def self.model_type_value() 'user' end
property :name
property :password
property :roles
property :_id
before_save :generate_id, :assign_admin_role