Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Crownoble adamcrown

View GitHub Profile
@adamcrown
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
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 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. http://bluefletch.com/blog/domain-agnostic-letsencrypt-ssl-config-for-elastic-beanstalk-single-instances/
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!
Resources:
sslSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
IpProtocol: tcp
ToPort: 443
@adamcrown
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
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: 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 / 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
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="{{ req.id }}"
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)"
i.fa.fa-times.text-danger
button.btn.btn-success.btn-xs type="button" v-on:click="addRequirement()"
i.fa.fa-plus
@adamcrown
adamcrown / elasticsearch-_all-test.sh
Created Jun 22, 2016
Elasticsearch edgengram fields in _all issue
View elasticsearch-_all-test.sh
# 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
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]}!"
end
end
class Shout
def initialize(app)
@app = app
end
@adamcrown
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 'https://rubygems.org'
gem 'rack'
gem 'mail'
gem 'puma'
@adamcrown
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')