Skip to content

Instantly share code, notes, and snippets.

@RachelSa
RachelSa / maxEventScore.js
Created February 17, 2018 20:43
Find the event with the highest score
let events = [
{title: "lowest scored event", score: "1.23"},
{title: "highest scored event", score: "4.05"},
{title: "middle scored event", score: "3.75"}
]
function maxScoredEvent(events){
return events.reduce((p,c) => {
return p.score > c.score ? p : c
})
@RachelSa
RachelSa / brackets.js
Created February 15, 2018 01:30
checks that brackets are properly closed, in order
function bracketChecker(str){
let match = {"}":"{", "]":"[", ")":"("}
let opening = ["(", "[", "{"]
let toClose = []
for (let i = 0; i < str.length; i++){
if (opening.includes(str[i])){
toClose.push(str[i])
} else {
if (toClose[toClose.length-1] !== match[str[i]]){
return false
const express = require('express')
// import the Express module
const app = express()
// create an Express application that has Express' built-in functionality, such as routing
app.get('/', (req, res) => res.send('Hello World!'))
// define a route (this one is a GET request to 'domainname.com/', in this case, 'localhost:3000/'. When the request is recieved, it will respond with the string "Hello World!")
app.listen(3000, () => console.log('Example app listening on port 3000!'))
// this defines the port that the server should run (3000) and logs that it's running. By running this file (' node filename.js'), the server will start, and you'll see 'Hello World!' by visiting localhost:3000/.
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World!');
});
function concat(first, last){
return `${first} ${last}`
}
function greet(f, l){
console.log(`Hi, ${concat(f, l)}`)
}
greet("Gabi", "Granger")
function eventLoop(){
setTimeout(() => {console.log(3)},0)
console.log(1)
return 2
}
eventLoop()
class ClassroomsController < ApplicationController
def update
@classroom = Classroom.find(params[:id])
if @classroom.update(classroom_params)
redirect_to users_path, :notice => "#{@classroom.name} updated"
else
flash[:notice] = "Classrooms must have a name"
@programs = Program.all
render :edit
class ClassroomsController < ApplicationController
def update
@classroom = Classroom.find(params[:id])
if @classroom.update(classroom_params)
program_ids = classroom_program_params[:program_ids].delete_if {|program| program == ""}
@programs = program_ids.map {|id| Program.find(id)}
@classroom.update(programs: @programs)
redirect_to users_path, :notice => "#{@classroom.name} updated"
else
flash[:notice] = "Classrooms must have a name"
@RachelSa
RachelSa / rails_collection_check_boxes_with_iteration.erb
Created August 12, 2017 23:23
Rails collection checkboxes with iteration
<%= f.collection_check_boxes(:program_ids, @programs, :id, :title) do |b| %>
<div> <%= b.check_box %><%= b.label { b.text } %></div>
<% end %>
<% end %>
@RachelSa
RachelSa / rails_collection_check_boxes.erb
Created August 12, 2017 23:11
Rails collection_check_boxes
<%= f.collection_check_boxes :program_ids, @programs, :id, :title %>