Skip to content

Instantly share code, notes, and snippets.

View adamcrown's full-sized avatar

Adam Crownoble adamcrown

View GitHub Profile
# 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 / 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 / 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 / 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 / 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
@adamcrown
adamcrown / job_role.html.slim
Last active September 15, 2016 16:48
Vue.js for accets_nested_attributes_for
#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 June 22, 2016 02:59
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
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 / 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'