Skip to content

Instantly share code, notes, and snippets.

View jkup's full-sized avatar

Jon Kuperman jkup

View GitHub Profile
@jkup
jkup / auth-middleware.ts
Last active May 2, 2023 04:12
Building a video app with Cloudflare
export const cfTeamsAccessAuthMiddleware = async ({request, data, env, next}) => {
try {
const userEmail = request.headers.get("cf-access-authenticated-user-email")
if (!userEmail) {
throw new Error("User not found, make sure application is behind Cloudflare Access")
}
// Pass user info to next handlers
data.user = {
@jkup
jkup / index.html
Created June 25, 2021 00:53
CSS Specificity
<!DOCTYPE html>
<html>
<head>
<style>
.foo {
color: blue;
}
#bar {
color: red;
}
interface Admin {
id: string;
role: string;
}
interface User {
email: string;
}
function redirect(usr: Admin | User) {
if("role" in usr) {
// I was amazed TS knew this was an Admin type
@jkup
jkup / Notes.md
Last active February 5, 2018 20:46
Docker Question

My Setup:

  1. I have a Node app running locally with Express + React + etc.
  2. I have an /etc/hosts entry mapping 127.0.0.1 to a necessary hostname 127.0.0.1 really.important.mycompany.com
  3. I have a standalone Docker image running selenium with standalone Chrome (https://hub.docker.com/r/selenium/standalone-chrome/)
  4. I have a webdriverio (http://webdriver.io/) suite of tests that need to run against the really.important.mycompany.com local hostname.

My process:

  1. I start the Docker image with: docker run --name mycompany-selenium --add-host -d --rm -p 4444:4444 selenium/standalone-chrome
function* createName() {
console.log(yield)
}
const name = createName()
name.next('Jon')
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
var data = JSON.parse(this.response)
data.photos.photo.map(function (photo) {
var image = generateImageFromPhotoObject(photo)
wrapper.appendChild(image)
})
} else {
wrapper.innerHTML = 'We recieved an error from the Flickr API. Please try again later.'
@jkup
jkup / semicolons.scala
Created October 13, 2016 07:37
Scala No Semicolons
object Foo {
def bar() {
println("no semicolons here!")
val xs = List(1, 2, 3, 4)
xs foreach println
def sumOfSquares(x: Int, y: Int) {
(x * x) + (y * y)
@jkup
jkup / return.scala
Created October 13, 2016 07:36
Scala Return
def foo() {
var bar = 42
}
@jkup
jkup / return.js
Created October 13, 2016 07:35
JavaScript Return
function foo() {
var bar = 42;
return bar;
}