Skip to content

Instantly share code, notes, and snippets.

Avatar

Nigel Earle NigelEarle

  • NWRE Development
  • San Diego, CA
View GitHub Profile
@NigelEarle
NigelEarle / Knex-Migrations-Seeding.md
Last active Aug 2, 2021
Migration and seeding instructions using Knex.js!
View Knex-Migrations-Seeding.md

Migrations & Seeding

What are migrations??

Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex command line tool.

To learn more about migrations, check out this article on the different types of database migrations!

Creating/Dropping Tables

View cluster.js
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
// Fork workers.
for (let i = 0; i < numCPUs; i++) {
@NigelEarle
NigelEarle / Knex-Setup.md
Last active Jul 15, 2021
Setup Knex with Node.js
View Knex-Setup.md

Knex Setup Guide

Create your project directory

Create and initialize your a directory for your Express application.

$ mkdir node-knex-demo
$ cd node-knex-demo
$ npm init
@NigelEarle
NigelEarle / palindrome.js
Created Oct 21, 2017
Array of palindromes
View palindrome.js
const arr = ['mom', 'dad', 'abcde', 'racecar', 'momom'];
function namePalindrome(arr) {
return arr.filter((curr, idx, arr) => {
const splitArr = curr.split('');
const reversedString = splitArr.reduceRight((prev, curr) => ( prev + curr ), '');
if (curr === reversedString) return curr;
})
}
View py-gitignore
# Created by https://www.gitignore.io
.Python
bin/
include/
lib/
pip-selfcheck.json
*.py[cod]
*.DS_Store
@NigelEarle
NigelEarle / promise_chain.js
Last active May 14, 2017
Passing resolve along from chained Promises
View promise_chain.js
const cleanRoom = () => {
return new Promise((resolve, reject) => {
resolve('Clean room,');
});
}
const takeTrash = (message) => {
return new Promise((resolve, reject) => {
resolve(message + ' Take out trash,');
})
View client-event-source-listener.js
if (!!window.EventSource) {
const source = new EventSource('/api/bubble-sort');
source.onmessage = (e) => {
const data = JSON.parse(e.data);
// data parsed
};
source.onopen = () => {
console.log('connected!');
};
@NigelEarle
NigelEarle / loop-timeout.js
Created Apr 9, 2017
setTimeout() in for loop
View loop-timeout.js
for (var i = 0;i < 10;i++) {
(function(i) {
setTimeout(function(){
console.log(i);
}, 1000 * i);
})(i);
}
@NigelEarle
NigelEarle / react-navigation-redux-ex.js
Created Mar 4, 2017
react-navigation redux example from `react-navigation/examples/Redux-Example`
View react-navigation-redux-ex.js
/**
* @flow
*/
import React from 'react';
import {
AppRegistry,
AsyncStorage,
Button,
StyleSheet,
View recursive-promise.js
const got = require('got');
const querystring = require('querystring');
const Promise = require('bluebird');
let url = [
"https://newsapi.org/v1/articles?source=cnn&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",
"https://newsapi.org/v1/articles?source=abc-news-au&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",
"https://newsapi.org/v1/articles?source=associated-press&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",
"https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",
"https://newsapi.org/v1/articles?source=bloomberg&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",
"https://newsapi.org/v1/articles?source=business-insider&sortBy=top&apiKey=9f3b3102ab704b7c9a874ee92cdb288f",