Skip to content

Instantly share code, notes, and snippets.

View bmorelli25's full-sized avatar
📚
Writing docs

Brandon Morelli bmorelli25

📚
Writing docs
View GitHub Profile
@bmorelli25
bmorelli25 / app.js
Created May 28, 2017 15:13
Twitter Favorite Bot
var Twitter = require('twitter');
var config = require('./config.js');
var T = new Twitter(config);
// Set up your search parameters
var params = {
q: '#nodejs',
count: 10,
result_type: 'recent',
lang: 'en'
@bmorelli25
bmorelli25 / test.js
Created June 7, 2017 00:35
How to test Node.js with Mocha
// Require the built in 'assertion' library
var assert = require('assert');
// Create a group of tests about Arrays
describe('Array', function() {
// Within our Array group, Create a group of tests for indexOf
describe('#indexOf()', function() {
// A string explanation of what we're testing
it('should return -1 when the value is not present', function(){
// Our actual test: -1 should equal indexOf(...)
assert.equal(-1, [1,2,3].indexOf(4));
@bmorelli25
bmorelli25 / testAnswer.js
Last active June 7, 2017 01:04
Mocha Test Answer
// Require the built in 'assertion' library
var assert = require('assert');
// Create a test suite (group) called Math
describe('Math', function() {
// Test One: A string explanation of what we're testing
it('should test if 3*3 = 9', function(){
// Our actual test: 3*3 SHOULD EQUAL 9
assert.equal(9, 3*3);
});
// Test Two: A string explanation of what we're testing
@bmorelli25
bmorelli25 / app.js
Last active June 7, 2017 12:57
Mocha Testing - v1
cToF = function(celsius) {
if(!Number.isInteger(celsius)) return undefined;
return celsius * 9 / 5 + 32;
}
fToC = function(fahrenheit) {
if(!Number.isInteger(fahrenheit)) return undefined;
return (fahrenheit - 32) * 5 / 9;
}
@bmorelli25
bmorelli25 / app.js
Created June 8, 2017 17:18
Mocha Testing - v2
let convert = {};
convert.cToF = function(celsius) {
if(!Number.isInteger(celsius)) return undefined;
return celsius * 9 / 5 + 32;
}
convert.fToC = function(fahrenheit) {
if(!Number.isInteger(fahrenheit)) return undefined;
return (fahrenheit - 32) * 5 / 9;
@bmorelli25
bmorelli25 / test.js
Created June 8, 2017 17:21
Mocha Testing - v2
let convert = require('../app.js')
let assert = require('assert');
describe('Temperature Conversion', function() {
describe('cToF', function() {
it('should convert -40 celsius to -40 fahrenheit', function() {
assert.equal(-40, convert.cToF(-40));
});
it('should convert 0 celsius to 32 fahrenheit', function() {
assert.equal(32, convert.cToF(0));
@bmorelli25
bmorelli25 / index.css
Last active July 4, 2017 00:02
Minimalist Flexbox Card
body {
font-family: 'Open Sans', sans-serif;
}
.card {
width: 150px; /* Set width of cards */
display: flex; /* Children use Flexbox */
flex-direction: column; /* Rotate Axis */
border: 1px solid #EF9A9A; /* Set up Border */
border-radius: 4px; /* Slightly Curve edges */
@bmorelli25
bmorelli25 / index.html
Created June 12, 2017 22:29
Minimalist HTML Card
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
<div class="card">
<div class="card-header">Night</div>
<div class="card-main">
<i class="material-icons">hot_tub</i>
<div class="main-description">Hot Tub</div>
</div>
</div>
@bmorelli25
bmorelli25 / index.js
Last active April 24, 2018 19:17
Node.js Weather App - part 1
let request = require('request');
let apiKey = '*****************************';
let city = 'portland';
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${apiKey}`
request(url, function (err, response, body) {
if(err){
console.log('error:', error);
} else {
@bmorelli25
bmorelli25 / index.js
Created June 19, 2017 20:06
Node.js Weather App - part 2
let request = require('request');
let apiKey = '***********************************';
let city = 'portland';
let url = `http://api.openweathermap.org/data/2.5/weather?q=${city}&units=imperial&appid=${apiKey}`
request(url, function (err, response, body) {
if(err){
console.log('error:', error);
} else {