Skip to content

Instantly share code, notes, and snippets.

@erikdstock
erikdstock / extractor.py
Last active October 18, 2022 02:31
Extract things that look like apa citations to a csv
# naive script to read a text file and
# extract what look like apa citations from parentheses,
# then split them on `;` to pull out groups of citations
# and finally write them to a text file.
# usage: `python extractor.py ./some-text.txt`
import sys
import re
@erikdstock
erikdstock / fancyhash.rb
Created September 28, 2022 19:34
Ruby hash with js object-like syntax
# Nesting would not work here but could easily be tweaked to do so
# other hash methods that return a copy (eg #merge) also need to be reimplemented
# OpenStruct already does this too btw
class HashObj < SimpleDelegator
def method_missing(method_name, *args, &block)
if __getobj__.keys.include?(method_name)
puts "looking for #{method_name}"
__getobj__[method_name]
@erikdstock
erikdstock / gmail_sorting.md
Last active May 24, 2024 10:16
gmail sorting and filters

source

  1. Move all emails older than 7 days to Archive/All Mail
in:inbox older_than:7d -is:starred
  1. Move all emails you are cc'ed on older than 3 days to Archive/All Mail
cc:me older_than:3d -is:starred
@erikdstock
erikdstock / schema.scala
Created July 22, 2020 16:46
Scala, Sangria, lazies and implicits
trait CartTypes {
implicit val ec: ExecutionContextExecutor
val itemType: ObjectType[RequestServices, Item]
lazy val cartType: ObjectType[Unit, Cart] = ObjectType[RequestServices, Cart](
/* ... */
fields = Field(
"items",
ListType(ItemType),
@erikdstock
erikdstock / graphql.models.Money.scala
Created July 16, 2020 23:25
Example method of organizing sangria type
package graphql.models
import java.text.DecimalFormat
import sangria.validation.ValueCoercionViolation
import json.SprayJsonConversions
import sangria.macros.derive.{
deriveObjectType, AddFields, ObjectTypeDescription, ObjectTypeName
}
@erikdstock
erikdstock / authnotes.md
Last active June 15, 2020 22:50
Authentication/Authorization Notes

Authentication & Authorization

Oauth 2.0 Flows

  • Authorization Code Flow: Server-side web apps where code is not publicly exposed - allowing the client to exchange an authorization code for a token
  • Authorization Code Flow with Proof Key for Code Exchange (PKCE):
  • Device Authorization Flow: Entering a code from your Roku screen on the hulu website for example.
  • Client Credentials flow: For machine to machine
  • Auth0: Authorization Flows good docs all around here.
  • Auth0: Which flow should I use?
  • Auth0: Silent Authentication Explains Auth0's approach to reloading a browser session on a client-only app.
@erikdstock
erikdstock / relay_cheatsheet.md
Last active August 22, 2019 18:52
Relay Notes

Keybase proof

I hereby claim:

  • I am erikdstock on github.
  • I am erikdstock (https://keybase.io/erikdstock) on keybase.
  • I have a public key ASCKupOd3yVYrqY4tHkyUmwl51kckhpi_Awj7wLCIcmNSwo

To claim this, I am signing this object:

@erikdstock
erikdstock / one-off-docker-command.sh
Created October 17, 2018 02:52
Docker shell commands
#!/usr/bin/env bash
# Start your built mycoolservice image with a bind mount on its source files in your ./myservice folder
DIR=$(dirname "$0") # relative
ROOT="$( cd "$DIR/.." && pwd )" # root, absolutized and normalized
Start the backend (docker)
cmd="docker run -p 8000:8000"\
" --mount src=$ROOT/myservice,target=/code,type=bind"\