Skip to content

Instantly share code, notes, and snippets.

Richard Flosi richard-flosi

  • Portland, Oregon
Block or report user

Report or block richard-flosi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@richard-flosi
richard-flosi / stock-profit.js
Created Aug 13, 2018
Find the maximum amount of profit you could have made buying and selling a stock using yesterday's stock prices.
View stock-profit.js
/**
Given a list of stock prices of a stock from yesterday (indices are represent time),
write a function that returns the most profit you could have made if you had bought and sold at the optimal time.
For example, if you had bought at a share price of $5 and sold at $9 you would have made a profit of $4.
Keep in mind you must buy before you can sell.
**/
const yesterdayStockPrices = [10, 7, 5, 8, 8, 9, 2, 4];
function returnMaxProfit(prices) {
let maxProfit = 0;
@richard-flosi
richard-flosi / uniqueArray.js
Created Aug 8, 2018
Function to return a filtered array containing only unique objects in memory
View uniqueArray.js
/*
Please write a JavaScript function that
takes an array of objects and returns a
unique-ified version of the same array.
To be clear, the goal is just to
remove any duplicate objects that reference
the same object in memory. The result can
have multiple objects with the same properties
as long as they are different objects in memory.
@richard-flosi
richard-flosi / flattenArray.js
Created Aug 3, 2018
Javascript Flatten Array Example using reduce and recursion
View flattenArray.js
function reducer(accumulator, currentValue) {
if (Array.isArray(currentValue)) {
// recurse to flatten the nested array
return accumulator.concat(flattenArray(currentValue));
} else {
// otherwise concat the value
return accumulator.concat(currentValue);
}
}
@richard-flosi
richard-flosi / star-wars-planets.html
Last active May 23, 2019
Web Component using Custom Element, Shadow DOM, fetch, async/await, and the Star Wars API
View star-wars-planets.html
<html>
<head>
<script>
customElements.define("star-wars-planets", class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: "open" });
}
static get observedAttributes() { return ["loading", "planets"]; }
View gist:8c4ade400188d1c91e8964ff3211d091
// Created by Derrick Cohodas (dav-)
// Based on the Python example by StackExchange user wwnick from http://gis.stackexchange.com/a/415/41129
// Requires the Mathjs library - http://mathjs.org/
var math = require('mathjs')
/**
* Represents a coordinate with a distance
* @param {Number} lat Latitude
@richard-flosi
richard-flosi / first.js
Last active Aug 29, 2015
This gist is an example of the problem I was having in https://github.com/beatfactor/nightwatch/issues/341
View first.js
// This is the first test in a group
var Test;
Test = {
before: function(browser) {
browser
.sleep()
.url('https://www.google.com/')
.waitForElementVisible('input[name="q"]', 10000);
},
@richard-flosi
richard-flosi / assertions-compareScreenshot.js
Created Aug 27, 2014
Nightwatch with Visual Regression testing
View assertions-compareScreenshot.js
// assertions/compareScreenshot.js
var resemble = require('resemble'),
fs = require('fs');
exports.assertion = function(filename, expected) {
var screenshotPath = 'test/screenshots/',
baselinePath = screenshotPath + 'baseline/' + filename,
resultPath = screenshotPath + 'results/' + filename,
diffPath = screenshotPath + 'diffs/' + filename;
@richard-flosi
richard-flosi / app.js
Created Apr 9, 2014
Spine App example with navigation method
View app.js
module.exports = (function() {
var App,
Spine = require('spine'),
$ = Spine.$;
// extend Spine
require('spine/lib/local');
require('spine/lib/ajax');
require('spine/lib/route');
require('spine/lib/manager');
@richard-flosi
richard-flosi / slug.js
Created Apr 9, 2014
Hem precompiler for nunjucks templates
View slug.js
/* jshint node: true */
var argv = process.argv.slice(2);
var fs = require('fs');
var hem = new (require('hem'))();
hem.compilers.html = function(path) {
var nunjucks = require('nunjucks'),
name = path.split('app/')[1],
opts = {
name: name,
@richard-flosi
richard-flosi / package.json
Created Mar 17, 2014
.html extension compiler for nunjucks templates in hem for spine.
View package.json
# add hem and nunjucks to your package.json
{
...
"dependencies": {
...
"hem": "~0.3.6",
"nunjucks": "~1.0.1"
}
}
You can’t perform that action at this time.