Skip to content

Instantly share code, notes, and snippets.

View tdubs42's full-sized avatar
๐Ÿ˜
constantly coding

tdubs tdubs42

๐Ÿ˜
constantly coding
View GitHub Profile
@tdubs42
tdubs42 / node-class-doubly.js
Last active February 19, 2024 01:29
Node Class for Doubly Linked List - JavaScript
class Node {
constructor(data) {
this.data = data;
this.next = null;
this.previous = null;
}
setNextNode(node) {
if (node instanceof Node || node === null) {
this.next = node;
@tdubs42
tdubs42 / default nginx configuration file
Last active February 19, 2024 01:06 — forked from meetkabeershah/default nginx configuration file
The default nginx configuration file inside /etc/nginx/sites-available/default
# 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.
@tdubs42
tdubs42 / array-methods-for-dicts.ts
Last active February 19, 2024 01:31
Array methods for Dicts (Objects) - TypeScript
// 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
@tdubs42
tdubs42 / valid-anagram.js
Last active February 19, 2024 01:31
Valid Anagram - JavaScript
const isAnagram = (s, t) => {
if (s.split('').sort().join('') == t.split('').sort().join('')) {
return true
}
return false
};
@tdubs42
tdubs42 / two-sum.js
Last active February 19, 2024 01:32
Two Sum - JavaScript
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
@tdubs42
tdubs42 / number-of-islands.js
Last active February 19, 2024 01:32
Number of Islands - JavaScript
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 ||
@tdubs42
tdubs42 / reverse-string.js
Last active February 19, 2024 01:31
Reverse String - JavaScript
/*
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
};
@tdubs42
tdubs42 / js-query.js
Created September 23, 2021 14:44 — forked from samsch/js-query.js
Nested Knex query
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' })
@tdubs42
tdubs42 / package.json
Last active February 19, 2024 01:13
package.json Scripts for Express + Node Backend with Knex and Jest
"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"
},
// 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'
],