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 / regex.md
Last active August 6, 2023 11:27
A Guide To Regex in JS

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 June 29, 2016 23:19
Boilerplate gulp file compile js and sass, running node server along with livereload.
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 February 18, 2017 22:25
Express fb oauth example using the passport.js library.
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();
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 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,
@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);
}
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 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,');
})
# Created by https://www.gitignore.io
.Python
bin/
include/
lib/
pip-selfcheck.json
*.py[cod]
*.DS_Store
@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;
})
}