Skip to content

Instantly share code, notes, and snippets.

View erineland's full-sized avatar
🎯
Focusing

Erin erineland

🎯
Focusing
  • Apple
  • London, UK
View GitHub Profile

A simple utility (node module) that can be used to order a list of objects that have both name and rank, as well as finding the average rank.

See tests for examples like the one below:

const rankingTool = require('../src/object-ranking-tool');

const rankObjects = [
    {
 name: 'The Battle of The Bastards',
@erineland
erineland / README.md
Created July 5, 2019 10:33
Small utility to create a customisable utility for filtering an array of people objects.

This is a small utility designed to take an array of people objects, each with name, age and gender as well as an optional set of rules for filtering those objects, and return the filtered list, grouped by the genders of the people.

By default, if no custom rules are passed in, only people between the ages of 30 and 40 will be returned.

Run and read the tests to see different inputs and outputs.

Here's an example:

const peopleFilter = require('../src/people-filter');
@erineland
erineland / arrayReconcilerKata.js
Created June 25, 2019 23:49
A small Node util done as a coding exercise to find the unique values in 2 (or more!) arrays. Should have O(n) space and time complexity so is scalable.
// I wrote this in a local IDE (VSCode FTW) so that I could test it before writing it here, as there is limited tooling
// Only maps through each array once, and then the object (dictionary of elements and locations) once.
// Hence, this has linear O(n) time complexity and and O(n) space complexity. This is OK, could be better.
const reconcileHelpers = (firstArray, secondArray) => {
var elementLocations = {}; // empty dictionary for super fast O(1) lookups.
const arrayParser = (element, arrayName) => {
var existingLocations = elementLocations[element];
if (existingLocations) {
elementLocations[element].push(arrayName);
@erineland
erineland / shipment-costs-express-server.js
Created June 25, 2019 16:40
A small Express servlet to work out shipping costs!
var express = require('express');
// Helper libraries are supplied if needed
// const _ = require('lodash')
// const r = require('ramda')
const router = express.Router()
// Same state uses the base rate on the weight;
// Different state shipments have a fixed 20% cost increase on top of the previous value (rate on weight);
// Packages can have distinct weight units, either pounds or kilograms.
// Weight needs to be validated on pounds, thus requiring conversion from kg;
@erineland
erineland / README.md
Last active June 4, 2019 12:47
A small tool/exercise for flattening arrays

For this code exercise I went with a simple recursive solution to drill down into each array element, compiling a master array of the individual elements, aiming for elegant code which is readable and functional and ready to ship as it has tests and was written in a TDD manner (as I try to do for all of my tests).

The tests give you examples of how you would run this tool/code for it's desired effect.

E.g.

const ArrayFlattenerTool = require('./array-flattener.js');
const flatArray = ArrayFlattenerTool([1, [1, [2, [3, 4]]], 5]);
@erineland
erineland / object-is-polyfill-kata.js
Last active April 26, 2019 15:41
Object.is() polyfill - A small coding exercise to use JavaScript types and coercion to write my own Object.is().
// TODO: define polyfill for `Object.is(..)`
if (!Object.is || true) {
Object.is = function(firstValue, secondValue) {
// Take NaN into account
if (typeof(firstValue) === 'number' && typeof(secondValue) === 'number') {
if (firstValue.toString() === 'NaN' && secondValue.toString() === 'NaN') {
return firstValue.toString() === 'NaN' && secondValue.toString() === 'NaN'
}
}
@erineland
erineland / made-pdf-look-scanned.sh
Created August 28, 2018 13:00
[macOS] A Bash script to use the imagemagick library to make a PDF file look like it has been scanned!
#!/bin/bash
brew upgrade imagemagick
convert -density 200 $1 -rotate 0.3 +noise Multiplicative -format pdf -quality 85 -compress JPEG -colorspace gray $2
@erineland
erineland / The Technical Interview Cheat Sheet.md
Created October 29, 2015 11:06 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@erineland
erineland / ionic.app.scss
Created May 23, 2015 12:07
How to add custom styles to multiple tab bars in ionic, publishing because it took me a while to figure out how to do it!
//To apply different styles nested tabs, you have to use the respective DOM positions
ion-nav-view {
ion-tabs {
/*Styling bottom nav bar */
.tab-nav.tabs {
background-color: $ygi-green !important;
.tab-item-active {
background-color: white !important;
color: black !important;
}
@erineland
erineland / exportsafarireadinglist.sh
Last active January 19, 2020 00:58
Export Safari's Reading List to Pocket/Evernote (or any service with an "email content in" feature)
#!/bin/bash
# Script to export Safari's reading list into a text file, then import this into Pocket or Evernote (or any service with a "email in content" feature).
# First take all of Safari's Reading List items and place them in a text file.
/usr/bin/plutil -convert xml1 -o - ~/Library/Safari/Bookmarks.plist | grep -E -o '<string>http[s]{0,1}://.*</string>' | grep -v icloud | sed -E 's/<\/{0,1}string>//g' > readinglistlinksfromsafari.txt
# Now loop over each of those URls within that text file and add them to pocket.
while IFS= read -r line
do
echo $line