Skip to content

Instantly share code, notes, and snippets.

View dearshrewdwit's full-sized avatar
🤖
17 is my number.

Edward Withers dearshrewdwit

🤖
17 is my number.
View GitHub Profile
@dearshrewdwit
dearshrewdwit / simple-news-headlines.js
Created September 21, 2020 10:41
A simple approach building a component that request data from an API
// --------------------------------------------------------------------------------
// Headlines.test.js
// --------------------------------------------------------------------------------
import React from 'react'
import { render, screen, waitForElement } from '@testing-library/react'
import Headlines from './Headlines'
import mockResponse from './__mocks__/guardian-response.json'
@dearshrewdwit
dearshrewdwit / stateful-stateless-components.js
Created September 15, 2020 10:01
Comparing Class and Functional components in React
// DiceRoll.js
import React, { Component } from 'react'
import Die from './Die'
class DiceRoll extends Component {
constructor(props) {
super(props)
this.state = {dice: [4,5,6]}
}
@dearshrewdwit
dearshrewdwit / secret_diary_demo.rb
Created August 26, 2020 12:20
Secret Diary demo
# -------------------------------------------------------
#
# spec/diary_spec.rb
describe 'Diary' do
it 'can add entry' do
diary = Diary.new
expect(diary.add('hello')).to eq :ok
end
# NB: this example uses a test-framework called m-spec
# https://github.com/dearshrewdwit/m-spec
# Follow along with the screen recording here: https://youtu.be/c5dg-LPQp2E
# ---------------------------------------------------------------------------
# ./lib/todo_list.rb
require_relative "todo.rb"
# CEO executes a method make_company_efficient. This delegates to COO's method find_company_savings.
# The COO's method does a couple of things like sell_old_equipment and reduce_entertainment_budget.
# It then calls HRManager's method reduce_payroll.
# HRManager's method reduce_payroll iterates through employees and calls employee.fire if employee.performance < 7.
# In this example, neither the CEO nor the COO are responsible for firing employees, and both have plausible deniability.
# That responsibility has been delegated to the HR Manager, who will have to handle the angry letters herself.
class Ceo
def initialize(coo = Coo.new)
@coo = coo
@dearshrewdwit
dearshrewdwit / working_with_multiple_classes.rb
Created August 9, 2020 07:57
Working with multiple classes
class AssertionList
# write a method #run that iterates through a list of assertions
# and asks each one to run its #check method and then #puts the result.
end
class Equal
def initialize(val1, val2)
@val1 = val1
@val2 = val2
end

Welcome to Makers!

If you have any questions, just ask!

Cohort Zoom

The cohort has its own zoom link that will always be available, and where we'll hang out together. You can find yours in the topic of your cohort's slack channel - right at the top.

We'll meet for Welcome to Makers Parts 1 & 2 on zoom for 6pm - see you there!

Part 1 (Monday)

Using plain old Ruby, make this work:

expect(1).to eq 1
expect(['hi', 'there'].length).to eq 2
expect('howdy!'.upcase).to eq 'HOWDY!' 
character, value
, m
a, X
b, p
c, M
d, *
e, D
f, 3
g, £
h, §
@dearshrewdwit
dearshrewdwit / interview-extension4.md
Last active June 26, 2020 15:34
Letter Number encryption part 5

Details

We have a new requirement!

  1. Build a letter-letter substitution cipher.

Let's take this opportunity to refactor to take advantage of OOP's polymorphism. The public interface to all our ciphers should be methods #encrypt and #decrypt.

  • NB: Use character_set1 for the Letter Number cipher and character_set2 for the Letter Letter cipher
  • NB: Ciphers should assume a valid character set