Full Stack Dev. Data Scientist. Ruby, Python, JavaScript, AWS. Toronto. Ruby/Rails mentor/consultant for hire. Contact: chris.i.the.data.guy “at” gmail.com

Updated thoughts on why you should use factories instead of classes in JavaScript

Image for post
Image for post
Photo by Pixabay from Pexels

Public properties on class instances present a security concern (and how to avoid it)

class Car {
constructor(maxSpeed){
this.maxSpeed = maxSpeed;
}
drive(){
console.log(`driving ${this.maxSpeed} mph!`)
}
honk(){
console.log(`honk!!!`) …


The best way to create a type attribute on your ruby on rails models

Image for post
Image for post
Photo by Karolina Grabowska from Pexels

Enums are constant mappings of values to integers

An enum example, as defined in a model

enum item_type: {
fruit: 0,
vegetable: 10,
meat: 20,
bread: 30
}

An alternative: constant hashes


Skip the library and roll your own hot keys

Image for post
Image for post
Photo by Pixabay from Pexels

Add an event listener

window.addEventListener(
'keyup',
hideDisplay
)

Write a function to be called by the listener


From infinite scrolling to manipulating the DOM to printing variables

Image for post
Image for post
Photo by fauxels from Pexels
  • Represents the current tab of a browser.
  • Includes the document and screen objects, which represent a site’s content and the shape of a device’s screen.
  • Contains global variables and functions.


Learn why you should use JavaScript factories over classes with an example

Image for post
Image for post
Photo by Pixabay from Pexels

Build a Class-Based Rocket Ship


Do you know when to use Ruby’s each, select, map and collect methods?

Image for post
Image for post
Photo by Edmond Dantès from Pexels

Each

[1,2,3].each {|x| puts x + 1 }
=> 2
=> 3
=> 4
a = [1,2,3].each {|x| x + 1}
puts a.inspect


What you need to know and what you can do with “..” and “…”

Image for post
Image for post
Photo by Archie Binamira from Pexels

We’ll cover:

  1. What you need to know about ranges
  2. The most common ways to use ranges

What you need to know about ranges

Inclusive vs exclusive ranges

puts (1..5).to_a.inspect
=> [1, 2, 3, 4, 5]
puts (1...5).to_a.inspect
=> [1, 2, 3, 4]

A range is not an array

puts (1..5)
=> 1..5
puts (1..5).class
=> Range


Know when to use each, depending on the situation

Image for post
Image for post
Photo by Negative Space from Pexels

Case 1: On arrays in memory

arr = ['a','b','c','c']
puts arr.length #=> 4
puts arr.count #=> 4
puts arr.size #=> 4
$ arr.count('c') #=> 2
$ arr2 = [1,2,3,4,5,6,7]
$ arr2.count …


3 algorithm questions you may be asked in Ruby interviews

Image for post
Image for post
Photo by Christina Morillo from Pexels

Question 1: FizzBuzz

Instructions:

  1. Given n, return a list of all integers from 1 through n.
  2. If an integer is divisible by 3, return “Fizz” instead of the integer. …


A tutorial on deploying a ReactJS frontend and Rails API backend on the same dyno

Image for post
Image for post

Create and setup the app

$ rails new fe-be-app --api --database=postgresql -T
$ cd fe-be-app
$ bundle install
$ rake db:create
$ rails s -p…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store