Skip to content

Instantly share code, notes, and snippets.

View kevinchisholm's full-sized avatar

Kevin Chisholm kevinchisholm

View GitHub Profile
@kevinchisholm
kevinchisholm / _node-basic-websocket-server.md
Last active November 29, 2023 10:25
Code Examples for my Blog Post: Create a Node.js Websocket Server in Five Minutes
@kevinchisholm
kevinchisholm / get-script-example-4.js
Last active June 23, 2021 22:03
jQuery.getScript Alternatives - Example 4
function getScript(scriptUrl, callback) {
const script = document.createElement('script');
script.src = scriptUrl;
script.onload = callback;
document.body.appendChild(script);
}
// anonymous function as 2nd argument
getScript('https://bit.ly/get-script-example', function () {
function validatePhoneForE164(phoneNumber) {
const regEx = /^\+[1-9]\d{10,14}$/;
return regEx.test(phoneNumber);
};
validatePhoneForE164('+12125551212'); // true
validatePhoneForE164('12125551212'); // false
validatePhoneForE164('2125551212'); // false
validatePhoneForE164('+1-212-555-1212'); // false
@kevinchisholm
kevinchisholm / scraper-api-ex-2-B.html
Last active October 17, 2020 23:28
Scraper API Example # 2 B
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web Scraping Example</title>
</head>
<body>
<article id="main">
<p>This text was added with JavaScript.</p>
</article>
@kevinchisholm
kevinchisholm / scraper-api-ex-1-b.html
Last active August 29, 2020 20:52
Scraper API Example # 1 B
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Web Scraping Example</title>
</head>
<body>
<article id="main">
<p>I've been scraped!</p>
</article>
@kevinchisholm
kevinchisholm / scraper-api-ex-2-A.js
Last active August 29, 2020 20:51
Scraper API Example # 2 A
const scraperapiClient = require('scraperapi-sdk')(YOUR_API_KEY);
async function scrapePage(){
const scrapeUrl = 'http://examples.kevinchisholm.com/scrape-me/'
const scrapeResponse = await scraperapiClient.get(scrapeUrl, {render: true})
console.log(scrapeResponse);
}
scrapePage();
@kevinchisholm
kevinchisholm / scraper-api-ex-1-a.js
Last active August 29, 2020 20:48
Scraper API Example # 1 A
const scraperapiClient = require('scraperapi-sdk')(YOUR_API_KEY);
async function scrapePage(){
const scrapeUrl = 'http://examples.kevinchisholm.com/scrape-me/'
const scrapeResponse = await scraperapiClient.get(scrapeUrl)
console.log(scrapeResponse);
}
scrapePage();
@kevinchisholm
kevinchisholm / scraper-api-example-package.json
Created August 29, 2020 20:44
Scrape API Example #- package.json
{
"name": "scraper-api-example",
"version": "1.0.0",
"description": "Scraper API Example",
"main": "app.js",
"author": "Kevin Chisholm",
"license": "ISC",
"dependencies": {
"scraperapi-sdk": "^1.0.6"
}
@kevinchisholm
kevinchisholm / App.js
Last active May 26, 2020 12:43
How to show points on a mapbox map with react native
import React, {Component} from 'react';
import {View, Image} from 'react-native';
import MapboxGL from '@mapbox/react-native-mapbox-gl';
MapboxGL.setAccessToken(YOUR_ACCESS_TOKEN);
const coordinates = [
[-73.98330688476561, 40.76975180901395],
[-73.96682739257812, 40.761560925502806],
[-74.00751113891602, 40.746346606483826],