Skip to content

Instantly share code, notes, and snippets.

View joshnuss's full-sized avatar
🤘

Joshua Nussbaum joshnuss

🤘
View GitHub Profile
@joshnuss
joshnuss / OAuthClient.js
Last active December 10, 2023 22:46
OAuth2 Client
import fetch from 'node-fetch'
// some provider data is copied from github.com/simov/grant
const providers = {
bogus: {
authorize_url: "http://localhost:8282/auth/request/path",
access_url: "http://localhost:8282/access/token/request",
},
google: {
@joshnuss
joshnuss / ble_speedometer_esp32.ino
Last active August 17, 2023 21:46
Bluetooth Speedometer using ESP32 and Hall effect sensor
/*
* Using digital hall effect sensor SENS-M-10 (purchased at Abra)
*
* MCU Board: ESP2-WROOM-32
*/
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>
@joshnuss
joshnuss / .bash_aliases
Created January 31, 2022 15:31
bash alias for creating svelte-kit projects
sk() {
pnpm init svelte@next $1 \
&& cd $1 \
&& pnpm install \
&& git init \
&& git add . \
&& git commit -m 'Initial commit'
}
@joshnuss
joshnuss / streaming_http_requests.ex
Last active March 31, 2023 09:02
Streaming HTTP requests
defmodule MyApp.Integrations.Skubana do
@host "..."
@headers [ ... ]
# returns a stream of shipments
def get_shipments do
# start with page 1
start = fn -> 1 end
# create a stream, it will make HTTP requests until the page returned is empty
<script> // example of using evidence.dev // you can view the results of this page here: // https://covid-ca-joshnuss.vercel.app/ import { lightFormat } from 'date-fns' </script>

Covid in Canada

@joshnuss
joshnuss / index.md
Created December 31, 2021 04:40
Example of using evidence.dev
<script> // example of using evidence.dev // you can view the results of this page here: // https://covid-ca-joshnuss.vercel.app/ import { lightFormat } from 'date-fns' </script>

Covid in Canada

/*
scripts/newPost.js
A script for scaffolding markdown posts:
- Prompts for required metadata (title, tags, etc..)
- Generates a file name based on title
- Opens in fav. editor
Add script to package.json:
@joshnuss
joshnuss / slow_query_handler.ex
Last active July 9, 2023 09:26
Output slow Ecto queries to logs
defmodule MyApp.Telemetry do
require Logger
def handle_event([:my_app, :repo, :query], measurements, metadata, _config) do
milliseconds = System.convert_time_unit(measurements.total_time, :native, :millisecond)
# did the query take longer than 100ms?
if milliseconds > 100 do
# log it as a warning
Logger.warn("SLOW QUERY: ms: #{milliseconds}, query: #{metadata.query}")
@joshnuss
joshnuss / javascript.snippets
Last active September 29, 2021 00:57
Svelte snippets for ViM
snippet import "import a package"
import ${1:name} from '${2:name}'
snippet get "define a svelte GET endpoint"
export async function get() {
${1}
}
snippet post "define a svelte POST endpoint"
export async function post() {
@joshnuss
joshnuss / builder.js
Last active August 12, 2021 15:32
Builder DSL for SvelteKit responses
/*
In SvelteKit, endpoints return an object, like:
{
status: 200,
headers: {...},
body: JSON.stringify({a: 1})
}
This is an exploration into how it feels using a DSL instead. Like express and others use.