Skip to content

Instantly share code, notes, and snippets.

View superMDguy's full-sized avatar

Matthew Dangerfield superMDguy

View GitHub Profile
from dotenv import load_dotenv
from livekit import agents
from livekit.agents import Agent, AgentSession
from livekit.plugins import elevenlabs
load_dotenv()
class Assistant(Agent):
def __init__(self) -> None:
@superMDguy
superMDguy / location_hash.sql
Created September 25, 2025 21:50
Create a location "hash" to uniquely identify an address, useful for de-duping messy address data
UPDATE TABLE_NAME
SET location_hash = CASE
-- Set to NULL if address_1 or city or zip is null
WHEN address_1 IS NULL OR city IS NULL OR zip IS NULL
THEN NULL
ELSE md5(CONCAT(
-- Standardize the combined street address
COALESCE(
-- Hack to set to NULL if standardize_address returns row with all empty fields
NULLIF(
@superMDguy
superMDguy / pug-to-html.js
Last active May 31, 2019 22:53
Automatically convert Vue single file components from Pug/Jade to HTML
const fs = require('fs')
const pug = require('pug')
const glob = require('glob')
const templateRegex = new RegExp('<template lang="pug">(.*)</template>', 's')
const attributeRegex = new RegExp(/(\S*)="/, 'g')
function compilePug(pugCode) {
let cleanedPug = pugCode.split('\n').filter(line => line.trim().length > 0)
const initialTab = cleanedPug[0].match(/^\s*/)[0]
function loadStuff() {
state.loading = true
fetch('//myapi.com/stuff')
.then(res => res.json())
.then(data => {
state.loading = false
state.stuff = data
})
}
import tuxi from 'tuxi'
import Vuex from 'vuex'
import Vue from 'vue'
import api from './api'
Vue.use(Vuex)
const store = new Vuex.Store({
strict: true, // tuxi works in strict mode!
<template>
<div class="wrapper">
<div class="empty-message" v-if="articlesTask.empty">
No articles
</div>
<div class="spinner" v-if="articlesTask.spinning">
Loading articles...
</div>
import tuxi from 'tuxi'
import api from './api'
const articlesTask = tuxi.task(api.fetchArticles)
// ⚡ Fire the api call
articlesTask.start()
// The task is immediately set to pending
console.log(articlesTask.pending) // true
/**
* Create a Vuex store module to represent states for an asynchronous API getter.
*
* Includes defaultState, actions, and mutations for a standard value gotten via asynchronous call.
* See defaultState() function for list of states included.
*
* Usage:
* Assuming we have an async call to get documents (getDocuments) which takes a payload object as an arg, here's what we can do:
*
* ----- store.js -----
@superMDguy
superMDguy / sortable-dnd.util.js
Last active December 12, 2022 20:13
SortableJS drag and drop testing utilities for cypress
// Cypress-ized and modified version of https://github.com/kemokid/scripting-sortable/blob/master/script_sortable_dnd.js
export function triggerSortableDragAndDrop(elemDrag, elemDrop) {
/*
Summary of what events this fires:
On elemDrag:
mouseDown
dragstart
On elemDrop:
dragover (repeat until it moves)
@superMDguy
superMDguy / progress.js
Last active January 31, 2018 01:24
Progress report generator bookmarklet for Khan Academy courses
const progress = Array.from(
document.querySelectorAll('p[class^="progressNumbers"]')
)
.map(x => x.innerText)
.map(txt => {
let parsed = txt.match(/(\d+) of (\d+) complete/);
return { done: parseInt(parsed[1]), total: parseInt(parsed[2]) };
});
const done = progress.map(unit => unit.done).reduce((acc, val) => acc + val);