Skip to content

Instantly share code, notes, and snippets.

View LB-Digital's full-sized avatar

Lucas Bowers LB-Digital

View GitHub Profile
@LB-Digital
LB-Digital / ai.py
Last active December 10, 2019 22:17
A Convolutional neural Network in Python using Keras on TensorFlow
# importing libraries
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras.preprocessing import image
from keras import backend as K
from keras.models import load_model
import numpy as np
/*------EXTRACT FORM INPUTS------
* Returns Object of name:value pairs in .data
* .error will contain invalid input name on Error (e.g: empty required input)
*/
function extractFormInputs( formEl ){
// get all inputs from form
var inputs = formEl.querySelectorAll('input,textarea');
// convert inputs to array
var inputsArr = Array.from(inputs);
@LB-Digital
LB-Digital / email_regex.txt
Created July 10, 2019 23:58
Email regex for JavaScript, based on https://emailregex.com/
^(?:[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+\/=?^_`{|}~-]+)*|\"(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21\\x23-\\x5b\\x5d-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])*\")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|\\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x21-\\x5a\\x53-\\x7f]|\\\\[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f])+)\\])$
@LB-Digital
LB-Digital / handler.js
Created June 29, 2019 17:40
AWS DynamoDB simple scan/put operations
// leads/read.read
'use_strict';
const uuid = require('uuid');
const AWS = require('aws-sdk');
const IsEmail = require('isemail');
const dynamoDb = new AWS.DynamoDB.DocumentClient();
module.exports.create = function(event, context, callback) {
@LB-Digital
LB-Digital / get-jwt-payload.js
Created February 12, 2019 18:24
Retrieve the Payload data section of a JSON Web Token.
function getJwtPayload(){
//retrieve JsonWebToken from cookies
var cookies = document.cookie.split(";"),
jwt;
for (cookie of cookies){
var keyValue = cookie.trim().split('=');
if (keyValue[0] === "jwt"){
jwt = keyValue[1];
}
}
@LB-Digital
LB-Digital / php-url-request.php
Last active February 4, 2019 16:29
Sending URL requests (POST/GET) in PHP using curl
$url = 'https://example.com/api.json';
$fields = array(
'key1'=>urlencode('value 1'),
'key2'=>urlencode('value 2'),
'key3'=>urlencode('value 3')
);
//url-ify the data for the POST
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
@LB-Digital
LB-Digital / send-pushover-notif.js
Created February 4, 2019 16:13
A function for sending Pushover Notifications ( https://pushover.net/ )
function sendPushoverNotif(token, target, message, title){
message = encodeURIComponent(message); // make url friendly
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://api.pushover.net/1/messages.json", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(`token=${token}&user=${target}&message=${message}&title=${title}`);
}
@LB-Digital
LB-Digital / random-int.js
Created December 21, 2018 13:14
Random integer between min, max values
/**
* Using Math.round() results in an uneven distribution, as mentioned here...
* https://stackoverflow.com/questions/1527803/generating-random-whole-numbers-in-javascript-in-a-specific-range
*/
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
@LB-Digital
LB-Digital / subdomain-basic-auth.js
Created December 12, 2018 21:07
Basic auth header of a subdomain on NodeJS with Express
/** Password protect a subdomain on ExpressJS
* Uses HTTP Basic authorization... https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization
* with the WWW-Authenticate header... https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate
*
* By then checking if the user is visting from the given subdomain, you know they are authorized.
* I use this concept to password protect beta site features that aren't yet released publicly, on which
* certain pages are only accessible via the password protected 'beta.domain.com' url
*/
const config = {
@LB-Digital
LB-Digital / Array.prototype.isEqualTo.js
Created October 30, 2018 03:30
An array method to check if one array is equal to another. NOTE: this is only built for simple arrays with singular values, e.g: ['a','b','c'], not complex arrays, e.g: ['a', {this:'that',up:'down'}]
Array.prototype.isEqualTo = function(arr2){ // defining the Array method
var arr1 = this; // accesing the first array
if (arr1.length==arr2.length){ // if they have the same length
arr1 = arr1.filter(item=>{ // filter through arr1
if (arr2.indexOf(item) > -1){ // if item from arr1 is in arr2
return false; // remove from arr1 so we know its been accounted for
}
return true; // keep in arr1 as not in arr2
});