This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(data) { | |
this.data = data; | |
this.next = null; | |
this.previous = null; | |
} | |
setNextNode(node) { | |
if (node instanceof Node || node === null) { | |
this.next = node; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# You should look at the following URL's in order to grasp a solid understanding | |
# of Nginx configuration files in order to fully unleash the power of Nginx. | |
# http://wiki.nginx.org/Pitfalls | |
# http://wiki.nginx.org/QuickStart | |
# http://wiki.nginx.org/Configuration | |
# | |
# Generally, you will want to move this file somewhere, and start with a clean | |
# file but keep this around for reference. Or just disable in sites-enabled. | |
# | |
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From Frontend Masters Typescript Fundamentals v3 course | |
// Array.prototype.map, but for Dict | |
function mapDict<T, U>( | |
input: Dict<T>, | |
mappingCb: (arg: T, key: string) => U | |
): Dict<U> { | |
const output: Dict<U> = {} | |
// for-of loop is for an iterable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isAnagram = (s, t) => { | |
if (s.split('').sort().join('') == t.split('').sort().join('')) { | |
return true | |
} | |
return false | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const twoSum = (nums, target) => { | |
// given an array, return pair of indices corresponding to numbers in array that equal target | |
// there is exactly 1 solution per array of nums | |
// need variable to store indices of solution | |
const solution = [] | |
// need variable to store count to leverage while loop | |
let count = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const numIslands = grid => { | |
// need variable to count islands | |
let islands = 0 | |
// create a function to search for 1 and use recursion to search surrounding cells | |
const findIslands = (row, col, grid) => { | |
// first check if row and col exist on grid and if grid[row][col] 0 | |
if ( | |
row < 0 || | |
col < 0 || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This challenge is slightly misleading, as it says to reverse a string but inputs an array and expects an | |
array as output. If you need to return this as a string, use the String.join() method | |
*/ | |
const reverseString = s => { | |
const reverseArray = s.reverse() | |
return reverseArray | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
knex | |
.select([ | |
'users.*', | |
knex.raw('json_agg("posts") as posts') | |
]) | |
.from('users') | |
.leftJoin(function () { | |
this.select(['posts.*', knex.raw('json_agg("comments") as comments')]) | |
.from('posts') | |
.leftJoin('comments', { 'posts.id': 'comments.post' }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"scripts": { | |
"start": "node index.js", | |
"server": "nodemon index.js", | |
"migrate": "knex migrate:latest", | |
"rollback": "knex migrate:rollback", | |
"seed": "knex seed:run", | |
"test": "cross-env NODE_ENV=test jest --runInBand --verbose --watch --setTimeout=500" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// always use as first seed file to clean db | |
const cleaner = require('knex-cleaner') | |
exports.seed = function (knex) { | |
return cleaner.clean(knex, { | |
mode: 'truncate', // resets ids | |
ignoreTables: [ | |
'knex_migrations', | |
'knex_migrations_lock' | |
], |