Skip to content

Instantly share code, notes, and snippets.


Adam Crownoble adamcrown

View GitHub Profile
adamcrown / polymorphic_belongs_to_finder.rb
Created Oct 18, 2018
Find polymorphic associations to a model
View polymorphic_belongs_to_finder.rb
# 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
def initialize(old_model_name)
@old_model_name = old_model_name
adamcrown / AWS_Single_LetsEncrypt.yaml
Created Aug 17, 2017 — forked from tony-gutierrez/AWS_Single_LetsEncrypt.yaml
AWS Elastic Beanstalk .ebextensions config for single instance free SSL using letsencrypt certbot and nginx.
View AWS_Single_LetsEncrypt.yaml
# 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!
Type: AWS::EC2::SecurityGroupIngress
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
adamcrown / dmesg-grep-iwl.output
Created Nov 5, 2016
dmesg | grep iwl - Direct firmware load for iwlwifi-7265D-24.ucode failed with error -2
View dmesg-grep-iwl.output
[ 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 / couchdb 2.0 install
Created Oct 29, 2016 — forked from SinanGabel/Cluster setup hints
CouchDB 1.7.0 (1.x.x) / 2.0 (release-candidate) on Ubuntu 16.04
View couchdb 2.0 install
# Tried on Ubuntu 16.04 Desktop
# Refer to:
# (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 / user.rb
Created Oct 25, 2016
couchrest_model User model
View user.rb
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
adamcrown / job_role.html.slim
Last active Sep 15, 2016
Vue.js for accets_nested_attributes_for
View job_role.html.slim
#vue-job-requirements-app data-job-requirements=job_requirements_json(@job_role.job_requirements)
.form-group v-for="req in requirements"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][id]" value="{{ }}"
input type="hidden" name="job_role[job_requirements_attributes][{{ $index }}][_destroy]" value="{{ req._destroy }}"
.input-group v-if="req._destroy != '1'" transition="fade-out"
input.form-control type="text" name="job_role[job_requirements_attributes][{{ $index }}][description]" value="{{ req.description }}"
.input-group-addon v-on:click="removeRequirement($index)"
button.btn.btn-success.btn-xs type="button" v-on:click="addRequirement()"
adamcrown /
Created Jun 22, 2016
Elasticsearch edgengram fields in _all issue
# elasticsearch: Version: 2.3.3, Build: 218bdf1/2016-05-17T15:40:04Z, JVM: 1.8.0_92
# Arch Linux
# Kernel version 4.4.3-1-custom
# Setup a basic index using an edgengram filter
curl -XPUT "http://localhost:9200/test_index?pretty=true" -d'
"settings": {
"analysis": {
"filter": {
adamcrown / middleware-example.rb
Last active Feb 4, 2019
An example of baking our own middleware stack to better understand how Rack middleware works.
View middleware-example.rb
class Talk
def call(env)
"Can I talk to #{env[:name]}!"
class Shout
def initialize(app)
@app = app
adamcrown / Gemfile
Created Nov 5, 2015
A basic mailer API intended to be used as a contact form backend for a static site.
View Gemfile
source ''
gem 'rack'
gem 'mail'
gem 'puma'
adamcrown / add_netid_to_prod_center_accounts
Created Jan 22, 2015
Add NetIDs to CSV for production center accounts
View add_netid_to_prod_center_accounts
#!/usr/bin/env ruby
script_name = File.basename(__FILE__)
file_path = ARGV[0]
abort "No input CSV file provided. Example: #{script_name} ./prod_center_accounts.csv" if file_path.nil?
abort 'File must have a .csv extension' unless file_path =~ /\.csv\Z/
new_file_path = file_path.gsub(/\.csv\Z/, '_with_netids.csv')