Skip to content

Instantly share code, notes, and snippets.

Avatar
🍵
probably writing something.

Paul leeyspaul

🍵
probably writing something.
View GitHub Profile
View dfexample.swift
import Foundation
let date = Date()
let df = DateFormatter()
df.dateFormat = "MMM d, yyyy" // prints out "Dec 10, 2021"
print(df.string(from: date))
@leeyspaul
leeyspaul / df.swift
Created Dec 11, 2021
DateFormatter Styles
View df.swift
import Foundation
let date = Date()
let df = DateFormatter()
// FULL STYLE
df.dateStyle = DateFormatter.Style.full
df.timeStyle = DateFormatter.Style.full
print(df.string(from: date)) // Friday, December 10, 2021 at 5:00:41 PM Pacific Standard Time
View date.swift
// creates the Date object which gives to you the current date in your systems locale.
let date: Date = Date()
@leeyspaul
leeyspaul / auth.txt
Created Dec 7, 2021
Stytch Google OAuth Authenticate cURL sample
View auth.txt
curl --request POST --url https://test.stytch.com/v1/oauth/authenticate -u 'YOUR-PROJECT-NAME:YOUR-SECRET' -H 'Content-Type: application/json' -d '{ "token": "YOUR-TOKEN-FROM-LOGIN-REDIRECT" }'
@leeyspaul
leeyspaul / login.html
Created Dec 7, 2021
Stytch Login Button
View login.html
<html>
<head>
<style>
.container {
height: 200px;
position: relative;
}
.center {
display: flex;
@leeyspaul
leeyspaul / app.py
Last active Dec 7, 2021
Stytch Google OAuth
View app.py
from flask import Flask
from flask import request
from flask import render_template
from flask import session
app = Flask(__name__)
app.secret_key = "development"
@app.route("/login")
@leeyspaul
leeyspaul / Calendar.swift
Created Dec 4, 2021
Calendar SwiftUI implementation using LazyVGrid
View Calendar.swift
struct Calendar: View {
var cols: [GridItem] = [
GridItem(spacing: 35),
GridItem(spacing: 35),
GridItem(spacing: 35),
GridItem(spacing: 35),
GridItem(spacing: 35),
GridItem(spacing: 35),
GridItem(spacing: 35)
@leeyspaul
leeyspaul / test.py
Created Dec 1, 2021
OAuth2 Testing an API request to Google Calendar API
View test.py
@app.route("/test-api-request")
def test_api_request():
"""Tests an API request to Google Calendar."""
# grab the credentials from our flask session, in production
# you will probably store this in some persistent database per user
credentials = google.oauth2.credentials.Credentials(
**flask.session['credentials'])
# build the Google Calendar service which we use to represent the Google Calendar
# API
@leeyspaul
leeyspaul / redirect.py
Created Nov 30, 2021
OAuth2 Google Calendar API Redirect Route Complete
View redirect.py
@app.route("/authorize-user")
def auth_user():
"""
Redirects a user to Google's authorization server to show the OAuth
Consent screen and get user consent.
"""
return redirect(authorization_url)
@app.route("/oauth2redirect")
def oauth2_redirect():
@leeyspaul
leeyspaul / redirect.py
Last active Nov 30, 2021
OAuth2 Google Calendar API Redirect Route
View redirect.py
@app.route("/oauth2redirect")
def oauth2_redirect():
"""
The redirect URI that Google hits after user grants access in the OAuth
consent screen where we fetch the access token from the access code given in the
URL and set them in the flask session.
"""
# grabs the URL response from the redirect after auth
authorization_response = request.url