Skip to content

Instantly share code, notes, and snippets.

View jspinella's full-sized avatar
🇺🇦

James Spinella jspinella

🇺🇦
View GitHub Profile
beautifulsoup4==4.9.3
boto3==1.18.30
botocore==1.21.30
bs4==0.0.1
certifi==2021.5.30
charset-normalizer==2.0.4
idna==3.2
jmespath==0.10.0
lxml==4.6.3
numpy==1.21.2
# convert a table from an accdb file to CSV and upload to an AWS S3 bucket
import os, subprocess, urllib.request, requests, zipfile, boto3
from bs4 import BeautifulSoup
from lxml import etree
def handler(event, context): # we aren't using event or context here, but you probably will in your real-world implementation
# cd into Lambda's writable directory (allows up to 512MB of files)
os.chdir('/tmp')
#todo: download the accdb file from S3 or the Internet
FROM public.ecr.aws/lambda/python:3.8
# install dependencies
# mdbtools depends on unixODBC-devel and gcc-c++
# we start by enabling the EPEL package repository, which hosts the mdbtools package
RUN yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y && \
yum update -y && \
yum install -y mdbtools gcc-c++ unixODBC-devel
# add the python code to the Docker image
@jspinella
jspinella / Dockerfile
Last active September 2, 2021 18:21
AWS Lambda container image to convert Access files to CSV files with Python 3
FROM public.ecr.aws/lambda/python:3.8
# install dependencies
# mdbtools depends on unixODBC-devel and gcc-c++
# we start by enabling the EPEL package repository, which hosts the mdbtools package
RUN yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm -y && \
yum update -y && \
yum install -y mdbtools gcc-c++ unixODBC-devel
# add the python code to the Docker image
public async Task<(string token, DateTime expirationDate)> GetToken(User user) // syntactic sugar for the ValueTuple type
{
var response = await "https://api.website.com/oauth2/token/" // I'm taking some liberties here, this is not totally legit auth code, but it would utlize properties from the User object passed into the method
.ReceiveJson<TokenResponse>();
var token = response.access_token.ToString();
var expirationDate = DateTime.Now.AddSeconds(response.expires_in);
return (token, expirationDate); // can also express ValueTuple explicitly: return new ValueTuple<string, DateTime>(token, expirationDate);
}
@jspinella
jspinella / Font-Awesome-Cheatsheet-to-CSV.js
Last active September 10, 2015 11:08
Provides entire Font Awesome Cheatsheet in CSV format - just paste into your browser's Js console while on the Font Awesome Cheatsheet page (http://fortawesome.github.io/Font-Awesome/cheatsheet/)
// Font Awesome Cheatsheet to CSV
var awesomeOutput = "";
$(".col-md-4.col-sm-6.col-lg-3").each(function (i, element) { // selects a Font Awesome cheatsheet item
// Unicode value (i.e. "&#xf166")
var unicode = $(element).children(".muted").text().substring(1,8); // the unicode value is in a child span element with class "muted", this grabs it and "removes" the surrounding [brackets]
// CSS class name (i.e. "fa-youtube-square")
@jspinella
jspinella / ParseFA-Unicode.js
Last active August 29, 2015 14:25
Uses jQuery to fetch Font Awesome font-icon unicode values (in alphabetical order) from Font Awesome's website. Paste code into your browser's Js Developer Console while on Font Awesome's Cheatsheet page!
// ParseFA-Unicode
// FontAwesome Unicode Values
var awesomeOutput= "";
$(".col-md-4.col-sm-6.col-lg-3").children(".muted").each(function (i, element) {
var unicode = $(element).text(); // grabs text within HTML element
unicode = unicode.substring(1,8); // selects only the unicode values (not their enclosing brackets)
awesomeOutput += ('\n' + unicode); // puts each unicode value on its own line
});
@jspinella
jspinella / ParseFA-Class.js
Last active August 29, 2015 14:25
Uses jQuery to fetch Font Awesome font-icon CSS class values (in alphabetical order) from Font Awesome's website. Paste code into your browser's Js Developer Console while on Font Awesome's Cheatsheet page!
// ParseFA-Class
// FontAwesome Class Names
var awesomeOutput= "";
$(".col-md-4.col-sm-6.col-lg-3").each(function (i, element) {
var className = $(element).text().split("\n")[2].trim(); // takes all text items in element (the FA icon, class name, and unicode value), says "hey I just want [2], the class name,", and trims the extra space
awesomeOutput += ('\n' + className); // puts each class name on its own line
});
@jspinella
jspinella / ParseFA-Name.js
Last active August 29, 2015 14:25
Uses jQuery to fetch Font Awesome font-icon name values (in alphabetical order) from Font Awesome's website. Paste code into your browser's Js Developer Console while on Font Awesome's Cheatsheet page!
// ParseFA-Name
// FontAwesome Names, first letter alphabetized, hyphens replaced with spaces
var awesomeOutput= "";
$(".col-md-4.col-sm-6.col-lg-3").each(function (i, element) {
var properName = $(element).text().split("\n")[2].trim(); // takes all text items in element (the FA icon, class name, and unicode value), says "hey I just want [2], the class name,", and trims the extra space
properName = properName.replace("fa-", "").replace(/-/g, " "); // since class name is almost the same as the name, this removes the "fa-" prefix and replaces hyphens (-) with spaces ( )
properName = properName.charAt(0).toUpperCase() + properName.substr(1) // capitalizes the first letter of the first word in the name
awesomeOutput += ('\n' + properName); // puts each name on its own line