Skip to content

Instantly share code, notes, and snippets.

@isabellachen
isabellachen / filterObjectById.js
Last active April 8, 2018 09:58
Given an array of ids to keep, filter an object whoes keys match the ids in the array
const travisRepos = {
'1995928': {name: "tp-yarra", slug: 'codeworksbcn/tp-yarra'},
'2208412': {name: "tp-paint-fill", slug: 'codeworksbcn/tp-paint-fill'},
}
const firebaseRepos = {
'1995928': {active: false, name: "tp-yarra", time: 60},
'2208412': {active: false, name: "tp-paint-fill", time: 60},
'1983769': {active: false, name: "tp-two-adds", time: 60},
'2451579': {active: false, name: "tp-diamond", time: 60},
'2451589': {active: false, name: "tp-evented-thing", time: 60},
@isabellachen
isabellachen / promise-all-pokemons.js
Created February 20, 2018 12:31
Using Promise.all to fetch using an array of pokemon ids and returning an array of pokemons
const pokemonIds = [1,2,3]
const pokemons = pokemonIds.map(id => {
return fetch(`https://pokeapi.co/api/v2/pokemon/${id}`)
.then(res => res.json())
.then(json => {
console.log(json)
return json
})
})
@isabellachen
isabellachen / underline-underscore-every-some.js
Last active February 23, 2018 12:13
Implementation of underscoreJS every and some functions
const someEven = [1,2,3,4,5]
const allEven = [2,4,6,8,10]
const isEven = (n) => {
if (n % 2 ===0) return true
return false
}
const every = (collection, predicate, context) => {
if (Array.isArray(collection)) {
@isabellachen
isabellachen / underscore-every-with-reduce.js
Last active February 24, 2018 10:35
implementing underscore's every function using reduce.
const allEven = [2,4,6,8,10]
const isEven = (el) => {
if (el % 2 === 0) return true
return false
}
const _each = function (collection, iteratee, context) {
if (Array.isArray(collection)) {
for (let [i, el] of collection.entries()) {
iteratee.call(context, el, i, collection)
@isabellachen
isabellachen / package-json-mocha-tests.js
Created February 27, 2018 18:54
basic config for mocha package json
{
"name": "unit-testing",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha './tests/*.test.js'"
},
"author": "",
"license": "ISC",
@isabellachen
isabellachen / factorial-javascript.js
Last active March 2, 2018 14:46
factorial function in JS two ways
function factorial (n) {
let product = 1
for (let i=n; i>0; i--) {
product = product * i
}
return product
}
console.log(factorial(5))
@isabellachen
isabellachen / unstage-node_modules.md
Last active March 10, 2018 10:01
unstage node modules

add 'node_modules' to .gitignore file

git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@isabellachen
isabellachen / postgres-getting-started.md
Last active September 10, 2024 11:51
How to get up and running with postgres

Get up and running with Postgres sql

brew install postgresql

Make sure Postgres is installed by checking what version is installed

postgres -V

Start up Postgres

@isabellachen
isabellachen / promisify.js
Created March 20, 2018 18:14
promisify a function
//excercise to promisify a function
const readFilePromise = promisify(fs.readFile);
const writeFilePromise = promisify(fs.writeFile);
readFilePromise(url)
.then(data => {})
.catch(e => {})
@isabellachen
isabellachen / knex-postgres.md
Last active March 23, 2018 14:23
Setting Knex up with Postgres