Skip to content

Instantly share code, notes, and snippets.

View ddavisgraphics's full-sized avatar
🇺🇸
“First, solve the problem. Then, write the code.” – John Johnson

David J. Davis ddavisgraphics

🇺🇸
“First, solve the problem. Then, write the code.” – John Johnson
View GitHub Profile
@ddavisgraphics
ddavisgraphics / docker-pry-rails.md
Created July 19, 2018 18:21 — forked from briankung/docker-pry-rails.md
Using pry-rails with Docker

First, add pry-rails to your Gemfile:
https://github.com/rweng/pry-rails

gem 'pry-rails', group: :development

Then you'll want to rebuild your Docker container to install the gems

@ddavisgraphics
ddavisgraphics / catname.rb
Created July 4, 2018 21:38
How we named our cat
require 'faker'
# Monkey Patch Arrays
class Array
# .mode
# sorts by the most popular and returns the highest frequency
def mode
each_with_object(Hash.new(0)) { |v, h| h[v] += 1 }.max_by(&:last)
end
require 'rails_helper'
RSpec.describe 'Application', type: :request do
describe 'Tests our routes to make sure that the requests actually happen' do
it 'successfully gets the home page' do
get home_path
expect(response).to have_http_status(200)
end
it 'successfully gets the about page' do
@ddavisgraphics
ddavisgraphics / notes.md
Created April 23, 2018 11:07
Rspec Notes

Rspec

Shoulda Matchers

  • Good for testing associations
  • Good for testing validations for presence of the application

Factory Bot

  • Good for making a group of data similar to fixtures, but with non-fixed data.
  • This applies a bit of randomness to the testing to be sure your tests are working properly.
@ddavisgraphics
ddavisgraphics / edu_regex.rb
Created March 15, 2018 12:15
Regex for Edu Emails
$email = "test@mail.com"
$valid_email = "test@mail.school.edu"
$valid_email_2 = "test@mail.edu"
$email_regex = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[edu]+\z/i
$no_match = $email_regex.match $email
$valid_match = $email_regex.match $valid_email
@ddavisgraphics
ddavisgraphics / gist:dc3636c1c64d3c582eb6bdbbd6f99944
Last active January 2, 2018 13:34
Reset Mysql Root Password **Requires Root**

Recover MySQL root password

You can recover a MySQL database server password with the following five easy steps:

  1. Stop the MySQL server process.
  2. Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for a password.
  3. Connect to the MySQL server as the root user.
  4. Set a new root password.
  5. Exit and restart the MySQL server.
@ddavisgraphics
ddavisgraphics / benchmark_tests.rb
Last active September 18, 2017 18:07
sum_numbers and benchmarking
#!/usr/bin/env ruby
# require lib folder
Dir['./lib/*.rb'].each {|file| require file }
require 'benchmark'
@sum = Sum.new(1234)
avg_time = []
@ddavisgraphics
ddavisgraphics / benchmark_tests.rb
Last active September 18, 2017 18:03
Trying to figure out the reverse vowels problem in the best possible ways.
#!/usr/bin/env ruby
# require lib folder
Dir['./lib/*.rb'].each {|file| require file }
# require gems and modules
require 'random-word'
require 'benchmark'
avg_time = []
@ddavisgraphics
ddavisgraphics / aria.js
Created August 29, 2017 00:40
Teaching Aria JavaScript with Cats
class Cat{
constructor(name, color, type, legs = 4){
this.name = name;
this.color = color;
this.type = type;
this.legs = legs;
this.hungry = true;
}
getName(){
@ddavisgraphics
ddavisgraphics / docker-reset.sh
Created August 21, 2017 13:08
Docker Cheat Scripts
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q) --force