Skip to content

Instantly share code, notes, and snippets.

@gperrin01
gperrin01 / backbone_walkthrough
Created June 30, 2015 22:09
Basic Backbone Walkthrough - example of a todo app
Walkthrough - example of a todo app
w10/d2_todo_app
Note all along - Each time you write things on a new file, link it on the html with a script tag
Create our “seed data” with a few todos that we gather in a collection
On script.js (main js file)

Javascript Calculator (without Functions)

Instructions

Create a calculator that takes input from the browser. The calculator should display the results using alert.

The calculator should do the basic arithmetic operations.

Basic Calculator

@gperrin01
gperrin01 / Sinatra App Homework (w5d3).md
Last active September 9, 2015 15:40
Sinatra App Homework (w5d3)

Sinatra App

Introduction

To practice everything we've learned over the last couple days, your task is to build a full blown Sinatra app from scratch. It should have full CRUD for a single model with a RESTful controller and corresponding views.

What can you make? You're welcome to be creative, but if you need some ideas:

  • An app to help organize your fancy scotch collection
  • An app for a library to know which books are currently lent out

#Brokerage App - Requirements

Create your own brokerage and map your associations to respect the following hierarchy:
  • Your brokerage can have many clients
  • A client can have many stocks
  • Many clients can have the same stocks so you need to know everyone's holdings (e.g. Bob owns 15 Google Stocks but Joe owns 23 of them)
var text = 'hello';
var url = "https://translate.yandex.net/api/v1.5/tr.json/translate?key=trnsl.1.1.20150703T111847Z.50bb7b40984bcbfe.c87f5b960dc2613c413df68cdced5360645c6f81&lang=en-it&text=";
var translation;
function isCiao (text) {
console.log(text);
text === 'ciao' ? console.log('translation succesful') : console.log('translation FAIL');
}
@gperrin01
gperrin01 / hackernews asyncawait.js
Created May 22, 2017 18:34
Scrape Hacker News first page - Sample code to show async/await coding
nick.newTab().then(async (tab) => {
await tab.open("news.ycombinator.com")
await tab.untilVisible("#hnmain") // We make sure we have loaded the page
await tab.inject("../injectables/jquery-3.0.0.min.js") // We're going to use jQuery to scrape
const hackerNewsLinks = await tab.evaluate((arg, callback) => {
const data = []
$(".athing").each((index, element) => {
data.push({
title: $(element).find(".storylink").text(),
url: $(element).find(".storylink").attr("href")
// Declare the async function
async function addInFourSeconds(x) {
// In 2 seconds, this Promise will be resolved with the value 10
// Nothing else will be executed until these 2 seconds are over
var y = await resolveAfterTwoSeconds(10);
// print 10, since the above Promise has been resolved
console.log(y);
// In 2 seconds, this Promise will be resolved with the value 10
// Nothing else will be executed until these 2 seconds are over
var z = await resolveAfterTwoSeconds(20);
// Phantombuster configuration {
"phantombuster command: casperjs"
"phantombuster package: 3"
"phantombuster transform: babel"
"phantombuster flags: save-folder"
import "babel-polyfill"
import Buster from "phantombuster"