Skip to content

Instantly share code, notes, and snippets.

Important note

Use Replit or write code in a local JS file to complete these challenges. JS Bin doesn't handle callbacks well (it throws SyntaxError: Unexpected token { even though the code works elsewhere), and Code Pen has a finnicky console: https://repl.it/languages/nodejs

For a version of these questions with hints, use this gist: https://gist.github.com/SnoopSqueak/26824b4bde4071f967100ae3f9628798

Conditionals and operators

  1. Write a function getIsWordOdd that takes in a string and returns true if the word contains an odd number of characters or false if the word contains an even number of characters.

Sample calls:

@SnoopSqueak
SnoopSqueak / bacon_data.rb
Created March 18, 2019 20:27
Use this code to test your Graph's `find_kevin_bacon` method
graph = Graph.new
kevin_bacon = Node.new('Kevin Bacon')
james_mcavoy = Node.new('James McAvoy')
michael_fassbender = Node.new('Michael Fassbender')
jennifer_lawrence = Node.new('Jennifer Lawrence')
steve_carell = Node.new('Steve Carell')
ryan_gosling = Node.new('Ryan Gosling')
emma_stone = Node.new('Emma Stone')
morgan_freeman = Node.new('Morgan Freeman')
@SnoopSqueak
SnoopSqueak / react-boilerplate.js
Created February 19, 2019 19:21
React implementation of Hello World
<!DOCTYPE html>
<html lang="en">
<head>
<title>My First React app</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.1.0/umd/react.development.js"></script>
@SnoopSqueak
SnoopSqueak / Employee Schema and Data
Created August 30, 2018 20:34
For PostgreSQL 9.6
CREATE TABLE employees(
"id" INTEGER,
"name" VARCHAR(32),
PRIMARY KEY("id")
);
CREATE TABLE shifts(
"id" INTEGER,
"date" VARCHAR(16),
@SnoopSqueak
SnoopSqueak / Library Schema and Data
Last active August 30, 2018 20:34
For PostgreSQL 9.6
CREATE TABLE books (
"isbn" VARCHAR(16),
"title" VARCHAR(64),
"author" VARCHAR(32),
PRIMARY KEY ("isbn")
);
CREATE TABLE patrons (
"id" INTEGER,

Serializers

Why Serialize?

API's either receive data-modifying requests (post, put, delete) or data-accessing requests (get), and in either case, their response can involve retreiving data, serializing that data into JSON, and returning it.

In Rails, this serialization could be done manually, by, say, creating a serializer method:

# User.rb
def serialize
 hash = {}

Stripe Integration

Stripe's popularity is due largely to its developer-friendliness. Stripe removes much of the messiness from the payment integration process. It verifies credit card information for you, shielding you from the actual data so that your users are secure. It charges the cards for you, and routes the money wherever you want (with some restrictions). But payment gateways are complicated by nature, and even with Stripe, stringing together a payment system for your app can be difficult to conceptualize.

So let's take a look at a basic Stripe integration. There are countless ways to integrate Stripe into your app; we'll cover a simpler method here.

Getting Started

As with many Rails common problems, gems are a great place to start. The Stripe Gem greatly simplifies working with the Stripe API. Add the gem to your Gemfile:

Gemfile

Selecting the Firebase app:

In my case, I would click Bloc Chat Angular, since that's the database I set up specifically for this Bloc Chat app.

Finding the database:

For each problem, copy the code to a JS Bin. The only tabs needed are Javascript and Console. Try to complete the entire program before hitting "run" to check your work.

1.

// Write a function above these comments called
//  "processReplies" which takes in an array of
//  comments (strings). For each comment, if it
//  is longer than 10 characters, log "Approved"
//  to the console. Otherwise, log "Rejected".

1. Explain what a variable is and why we use them.




2. What is the DOM?