Skip to content

Instantly share code, notes, and snippets.

View Witanday's full-sized avatar

Witanday Kyanga Witanday

View GitHub Profile
@Witanday
Witanday / Setting up an SQL Project
Created April 10, 2019 23:17
Setting up an Knex SQLite3 project from scratch
Configuring the setup
1. Setting up the dependices
yarn init -y (Initalises a packag.json with the default values)
yarn add knex sqlite3 (Add knex sqlite module)
yarn add jest --dev (Add jest to dev dependices)
2. Adding scripts to the package.json file
const flatten = (arr) => {
//construct new array so as to not mutate original array
let newArr = []
//iterate through each item in the array
for(let i = 0; i < arr.length; i++){
if(arr[i].constructor === Array){
//if next item in array is an array, recursively call flatten on that array and concat the array returned from that to our new array
newArr = newArr.concat(flatten(arr[i]))
} else {
//if not push value into new array
@Witanday
Witanday / LICENSE
Created August 17, 2018 22:10 — forked from ourmaninamsterdam/LICENSE
Arrayzing - The JavaScript array cheatsheet
The MIT License (MIT)
Copyright (c) 2015 Justin Perry
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@Witanday
Witanday / slim-redux.js
Created August 17, 2018 21:07 — forked from gaearon/slim-redux.js
Redux without the sanity checks in a single file. Don't use this, use normal Redux. :-)
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {