Skip to content

Instantly share code, notes, and snippets.

View NigelEarle's full-sized avatar

Nigel Earle NigelEarle

  • NWRE Development
  • San Diego, CA
View GitHub Profile
@NigelEarle
NigelEarle / Knex-Migrations-Seeding.md
Last active March 23, 2024 09:04
Migration and seeding instructions using Knex.js!

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

@NigelEarle
NigelEarle / cluster.js
Created November 9, 2017 17:20
Node.js cluster
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 March 28, 2024 09:11
Setup Knex with Node.js

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 October 21, 2017 18:23
Array of palindromes
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;
})
}
# 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 00:35
Passing resolve along from chained Promises
const cleanRoom = () => {
return new Promise((resolve, reject) => {
resolve('Clean room,');
});
}
const takeTrash = (message) => {
return new Promise((resolve, reject) => {
resolve(message + ' Take out trash,');
})
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 April 9, 2017 05:53
setTimeout() in for loop
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 March 4, 2017 22:04
react-navigation redux example from `react-navigation/examples/Redux-Example`
/**
* @flow
*/
import React from 'react';
import {
AppRegistry,
AsyncStorage,
Button,
StyleSheet,
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",