Skip to content

Instantly share code, notes, and snippets.

describe "counter caches" do
it "increments associations when created" do
user = User.create(first_name: "David", last_name: "Moore", email:"david@moore.com")
#creating a thread with the user
user.forum_threads.create(name:"First thread")
expect(user.forum_threads_count).to eq 1
#create a thread with its own class and associating it to the user
require 'rails_helper'
describe 'ruby 2.3.0' do
context "Integer methods" do
describe "positive?" do
it "checks if an array value is greater than zero" do
some_array = [2,3,4]
expect(some_array.first.positive?).to eq true
require 'rails_helper'
describe 'ruby 2.2.0' do
context "Enumerable methods" do
# slice_before, slice_after and slice_when return Enumerable
describe "#slice_before" do
it "slices before a matched singular value" do
a = ["a", "b", "c"]
require 'lhm'
class AddDateTimeColumnsToNpsSurveys < ActiveRecord::Migration
def up
Lhm.change_table :nps_surveys do |m|
m.add_column :survey_created_at, 'DATETIME AFTER `survey_created_at_epoch`'
m.add_column :survey_updated_at, 'DATETIME AFTER `survey_created_at_epoch`'
end
end
def down
class Benchwarmer
attr_reader :results
class << self
def run(options = {gc: :enable})
if options[:gc] == :disable
GC.disable
elsif options[:gc] == :enable
# collect memory allocated during library loading
# and our own code before the measurement
@davidimoore
davidimoore / index.html
Created December 1, 2017 18:39
video promises
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<video controls class="handsome"></video>
<body>
<script>
const video = document.querySelector('.handsome');
@davidimoore
davidimoore / package.json
Last active May 11, 2018 00:11
jest-webpacker-setup
{
"scripts": {
"test": "NODE_PATH='./app/javascript/node_modules:./app/javascript' jest",
"test:watch": "yarn test --watch",
"test:coverage": "test --coverage"
},
"jest": {
"roots": [
"./app/javascript"
],
@davidimoore
davidimoore / gamedata.json
Created December 3, 2018 21:06
gamedata.json
This file has been truncated, but you can view the full file.
{
"id": "5748e073-d838-4100-bce5-8d41df5a38a2",
"status": "closed",
"reference": "57752",
"number": 186,
"scheduled": "2018-12-03T01:20:00+00:00",
"attendance": 61069,
"utc_offset": -5,
"entry_mode": "INGEST",
"weather": "Clear Temp: 57 F, Humidity: 55%, Wind: From S 8 mph",
@davidimoore
davidimoore / nbagamesummary.json
Created December 13, 2018 22:54
nba game summary
{
"id": "bbbc557d-3ff5-44cb-a48c-f3033740ddf7",
"status": "closed",
"coverage": "full",
"neutral_site": false,
"scheduled": "2018-12-13T03:30:00+00:00",
"duration": "2:08",
"attendance": 19596,
"lead_changes": 4,
"times_tied": 1,
@davidimoore
davidimoore / nbasimulated-schedule.json
Created December 14, 2018 19:28
nba-simulated-schedule
{
"league": {
"id": "4353138d-4c22-4396-95d8-5f587d2df25c",
"name": "NBA",
"alias": "NBA"
},
"season": {
"id": "3652b3d6-55f7-44f5-b69d-7c607b9be26b",
"year": 2017,
"type": "SIM"