Skip to content

Instantly share code, notes, and snippets.

View rchrd2's full-sized avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / test-php-basic-auth.php
Last active February 1, 2024 21:18 — forked from westonruter/test-php-basic-auth.php
PHP basic auth example
<?php
function require_auth() {
$AUTH_USER = 'admin';
$AUTH_PASS = 'admin';
header('Cache-Control: no-cache, must-revalidate, max-age=0');
$has_supplied_credentials = !(empty($_SERVER['PHP_AUTH_USER']) && empty($_SERVER['PHP_AUTH_PW']));
$is_not_authenticated = (
!$has_supplied_credentials ||
$_SERVER['PHP_AUTH_USER'] != $AUTH_USER ||
$_SERVER['PHP_AUTH_PW'] != $AUTH_PASS
@rchrd2
rchrd2 / proxy.js
Created November 4, 2020 01:12
Cloudflare worker CORS proxy
// forked from: https://github.com/chebyrash/cors
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
try {
const url = new URL(request.url);
if (url.pathname === "/") {
@rchrd2
rchrd2 / confirm.swift
Last active May 20, 2023 19:08
Swift shell script with native confirm dialog
import AppKit
import Foundation
import SwiftUI
extension NSApplication {
public func run<V: View>(@ViewBuilder view: () -> V) {
let appDelegate = AppDelegate(view())
NSApp.setActivationPolicy(.regular)
delegate = appDelegate
@rchrd2
rchrd2 / Toaster_AI_v2.c
Last active April 12, 2023 17:34
Toaster_AI_v2.pd
// Toaster AI v2
// by Richard Caceres
// 11/12/09
//
// Safety Precautions that could be put in place
// Overheating
// Description: Precautions to prevent the toaster from being on too long.
// Status: A solution is put in place where the toaster can only be on N seconds at a time.
// There is also a cool down period.
//
@rchrd2
rchrd2 / sketch.java
Created March 25, 2022 20:58
Processing sketch to convert midi sustain pedal to a bass drum midi note trigger
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus
int NOTE_NUMBER = 36;
int NOTE_VELOCITY = 50;
int NOTE_CHANNEL = 9;
String MIDI_DEVICE_IN = "GO:KEYS";
String MIDI_DEVICE_OUT = "GO:KEYS";
@rchrd2
rchrd2 / admin.py
Last active March 3, 2022 00:14
Adding custom views to django's admin
from django.contrib import admin
from polls.models import Poll, Choice
from django.contrib.auth.models import User
from django.contrib.admin import AdminSite
from polls.views import index
class MyAdminSite(AdminSite):
@rchrd2
rchrd2 / models.py
Last active February 14, 2022 08:15
Django object manager with Haversine distance annotation method (aka filter by distance with mysql)
from django.db import models
from with_distance_manager import WithDistanceManager
class Foo(models.Model):
longitude = models.DecimalField(max_digits=19, decimal_places=10, null=True)
latitude = models.DecimalField(max_digits=19, decimal_places=10, null=True)
objects = WithDistanceManager()
@rchrd2
rchrd2 / using-details-summary-github.md
Created January 8, 2022 02:12 — forked from scmx/using-details-summary-github.md
Using <details> <summary> expandable content on GitHub with Markdown #details #summary #markdown #gfm #html

How to use <details> <summary> expandable content on GitHub with Markdown

Firstly, what is <details> <summary>?

The HTML Details Element (<details>) creates a disclosure widget in which information is visible only when the widget is toggled into an "open" state. A summary or label can be provided using the <summary> element. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details.

Example

@rchrd2
rchrd2 / yaml2dot.py
Created April 21, 2016 05:45
YAML to Graphviz
#!/usr/bin/python
# vim: fileencoding=utf-8
u'''Translate YAML written text to graphviz dot language
Input YAML text like below:
---
foo:
@rchrd2
rchrd2 / player.js
Created December 19, 2014 09:23
Videojs BigPlayButton Play Pause
videojs.BigPlayButton.prototype.onClick = function(){
if(this.player_.paused()) {
this.player_.play();
} else {
this.player_.pause();
}
};