Skip to content

Instantly share code, notes, and snippets.

@jschr
jschr / parseYouTubeUrl.js
Last active February 8, 2024 05:57
Parse YouTube URLs
import UrlPattern from 'url-pattern';
import qs from 'query-string';
// Returns YouTube Player API options from a YouTube URL.
// ie. { playlistId }
// { videoId, start, end }
// { query }
export default function parseYouTubeUrl(url) {
const [domain, querystring] = url.split('?');
const options = {};
@jschr
jschr / 01-migrate-db.config
Last active February 7, 2020 07:55
.ebextension file and package.json for migrating a db with knex migrate cli and a single docker container beanstalk app
container_commands:
migrate_db:
command: >
docker run -e "DB_HOST=${DB_HOST}" -e "DB_PORT=${DB_PORT}" -e "DB_NAME=${DB_NAME}" -e "DB_USER=${DB_USER}" -e "DB_PASSWORD=${DB_PASSWORD}" aws_beanstalk/staging-app:latest npm run db:migration:run
leader_only: true
@jschr
jschr / open.sh
Created March 12, 2018 02:41
Open VSCode with proxy server
open /Applications/Visual\ Studio\ Code.app --args \
--proxy-server=localhost:5555 \
--ignore-certificate-errors
@jschr
jschr / wifi-connect.js
Last active September 14, 2018 03:54
Kill resin-wifi-connect on failed attempt.
import { spawn } from 'child-process-promise';
import readline from 'readline';
export default function wifiConnect(ssid) {
const promise = spawn('wifi-connect', [`--portal-ssid=${ssid}`]);
const childProcess = promise.childProcess;
readline
.createInterface({
input: childProcess.stderr,
@jschr
jschr / keybase.md
Created March 12, 2018 01:40
keybase.md

Keybase proof

I hereby claim:

  • I am jschr on github.
  • I am jschr (https://keybase.io/jschr) on keybase.
  • I have a public key ASCNojj9T9HQj66TpcpiOtX-KzFVfknk25JPASo1q4Ogpgo

To claim this, I am signing this object:

@jschr
jschr / handler.ts
Last active November 20, 2017 02:10
Handler step 1
import createWebpackConfig from './webpack.config'
const s3 = new AWS.S3()
// the lambda handler
// event contains information from the source of the lambda invocation
// it could be data provided by manually invoking it, a payload from
// API Gateway, an S3 putObject event or an SNS topic message.
// we are going to create a scheduled lambda function through CloudWatch
// and don't actually use the event data
@jschr
jschr / App.js
Last active September 20, 2017 04:58
state-provider api
import { createStateProvider, createStateSlicer } from 'state-provider'
import ProfileForm from './ProfileForm'
const Provider = createStateProvider('app')
const Slicer = createStateSlicer('app')
async function saveUser(user) {
await api.saveUser(user)
}
@jschr
jschr / Template.tsx
Last active April 13, 2017 01:43
glamor ssr
import * as React from 'react'
export default function Template({ css, js, body, ssr }) {
return (
<html lang='en' data-timestamp={(new Date()).toISOString()}>
<head>
<title>{ssr.appProps.username}</title>
<style>{css}</style>
</head>
<body>
@jschr
jschr / mailgun-broken.tf
Last active April 13, 2017 01:13
terraform dns entries broken
# ideally we could create the dns entries by iterating over
# each record but terraform currently doesn't computed variables
# when using count.
resource "aws_route53_record" "mailgun_sending" {
# create an route 53 entry for each record for the mailgun domain
count = "${length(mailgun_domain.domain.sending_records)}"
zone_id = "${data.aws_route53_zone.domain.zone_id}"
ttl = "300"
# select the record name from the current count
@jschr
jschr / mailgun-terraform-output.txt
Created April 13, 2017 01:05
Mailgun terraform output
module.app.mailgun_domain.domain:
receiving_records.# = 2
receiving_records.0.priority = 10
receiving_records.0.record_type = MX
...
sending_records.# = 3
sending_records.0.name = jschr.io
sending_records.0.record_type = TXT
sending_records.0.valid = valid
...