Skip to content

Instantly share code, notes, and snippets.

Avatar

Nigel Earle NigelEarle

  • NWRE Development
  • San Diego, CA
View GitHub Profile
@NigelEarle
NigelEarle / regex.md
Last active Jun 18, 2021
A Guide To Regex in JS
View regex.md

What is a Regular Expression?

A regular expression is a sequence of characters that forms a search pattern. The search pattern can be used for text search and text replace operations.

When you search for data in a text, you can use this search pattern to describe what you are searching for. A regular expression can be a single character, or a more complicated pattern. Regular expressions can be used to perform all types of text search and text replace operations.

String Modifiers

@NigelEarle
NigelEarle / gulpfile.example.js
Last active Jun 29, 2016
Boilerplate gulp file compile js and sass, running node server along with livereload.
View gulpfile.example.js
const gulp = require('gulp'),
uglify = require('gulp-uglify'),
pump = require('pump'),
sass = require('gulp-sass'),
nodemon = require('gulp-nodemon'),
livereload = require('gulp-livereload');
gulp.task('serve', function(){
nodemon({
script: 'server.js',
@NigelEarle
NigelEarle / express-fb-oauth.js
Last active Feb 18, 2017
Express fb oauth example using the passport.js library.
View express-fb-oauth.js
const express = require('express');
const passport = require('passport');
const Strategy = require('passport-facebook').Strategy;
const CLIENT_ID = process.env.CLIENT_ID || require('./config/facebook.json').ClientId;
const CLIENT_SECRET = process.env.CLIENT_SECRET || require('./config/facebook.json').ClientSecret;
const PORT = process.env.PORT || 3000;
const app = express();
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",
@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,
@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);
}
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 / 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 py-gitignore
# Created by https://www.gitignore.io
.Python
bin/
include/
lib/
pip-selfcheck.json
*.py[cod]
*.DS_Store
@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;
})
}