Skip to content

Instantly share code, notes, and snippets.

const BLANK_BOARD = [
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]
@dsasse07
dsasse07 / rental_aggregate_refactored.rb
Last active September 3, 2021 03:17
aggregate methods refactored using .send
def self.count_vhs_rentals_by(attribute)
Rental.all.each_with_object({}) do |rental, vhs_hash|
vhs_hash[rental.send(“#{attribute}”)].nil? ? vhs_hash[rental.“#{attribute}”] = 1 : vhs_hash[rental.“#{attribute}”] += 1
end
end
Vhs.count_vhs_rentals_by(“vhs”) #=>
#{<Vhs:0x00007f8d5e2bf0f0 id: 17, serial_number: "MAX-luqovgdk8e7tl", movie_id: 9 => 1,
#<Vhs:0x00007f8d4f81a4a0 id: 29, serial_number: "BABA-t6k24krzqclts", movie_id: 13 =>2,
#<Vhs:0x00007f8d4f854538 id: 11, serial_number: "BABA-begvxe7ai0rc6", movie_id: 13 =>3}
@dsasse07
dsasse07 / maxHeap.js
Last active August 4, 2021 04:42
Javascript Max Heap Implementation
class MaxHeap {
constructor(){
this.values = []
this.size = 0
}
insert(value){
// If no value, do nothing
if (value === undefined) return
// Insert the value, and increment the size of the heap
@dsasse07
dsasse07 / heapify.js
Last active June 22, 2021 19:48
MaxHeap with heapify & Heap sort
class MaxHeap {
constructor(arr = []){
this.size = 0
this.values = this._heapify(arr)
}
insert(value){
// If no value, do nothing
if (value === undefined) return
// Insert the value, and increment the size of the heap
@dsasse07
dsasse07 / socialShare.js
Last active May 19, 2021 14:48
Share Feature Implementation - Share Action Button display Floating Action Buttons with Social Share Links
import "./styles.css";
import styled from "styled-components";
import LinkedInIcon from "@material-ui/icons/LinkedIn";
import FacebookIcon from "@material-ui/icons/Facebook";
import TwitterIcon from "@material-ui/icons/Twitter";
import MailOutlineIcon from "@material-ui/icons/MailOutline";
import SmsIcon from "@material-ui/icons/Sms";
import ShareIcon from "@material-ui/icons/Share";
import { useState } from "react";
@dsasse07
dsasse07 / README.md
Created March 16, 2021 18:57 — forked from ihollander/README.md
Rails API Setup

Rails API Setup

Environment Setup

Make sure you are running a Ruby version supported by Heroku to make your app easier to deploy later. At the time of writing, that is:

  • 2.6.6
  • 2.7.2
  • 3.0.0
@dsasse07
dsasse07 / log-generator.js
Last active March 8, 2021 04:47
Storing functions in Objects for Abstract invocation
// Using Conditionals
const newMessage = {type: "error", message: "You still haven't squished the bugs!"}
const generateLog = newMessage => {
if (newMessage.type === "warn" {
Log.warn(newMessage.message)
} else if (newMessage.type === "error" {
Log.error(newMessage.message)
} else if (newMessage.type === "notify" {
@dsasse07
dsasse07 / JS-variable-object-keys.js
Created March 8, 2021 04:15
Calling Object keys using variables in JS
const greetings = {
english: "hello",
spanish: "hola"
}
const langChoice = "spanish"
greetings.english //=> "hello"
greetings[langChoice] //=> "hola"
@dsasse07
dsasse07 / js-log-class.js
Created March 8, 2021 04:03
Log message generator class
export class Log {
static error(msg){
let date = new Date();
let time = date.toLocaleTimeString();
return {type: 'error', msg: `[${time}] ERROR: ${msg}`}
}
static warn(msg){
let date = new Date();
let time = date.toLocaleTimeString();
@dsasse07
dsasse07 / sudoku-hole-puncher.js
Last active February 24, 2021 17:04
Punch holes in filled sudoku board
const pokeHoles = (startingBoard, holes) => {
const removedVals = []
const val = shuffle( range(0,80) )
while (removedVals.length < holes) {
const nextVal = val.pop()
if (nextVal === undefined) throw new Error ("Impossible Game")
const randomRowIndex = Math.floor(nextVal / 9) // Integer 0-8 for row index
const randomColIndex = nextVal % 9