Skip to content

Instantly share code, notes, and snippets.


Richard Caceres rchrd2

View GitHub Profile
rchrd2 /
Created Apr 21, 2016
YAML to Graphviz
# vim: fileencoding=utf-8
u'''Translate YAML written text to graphviz dot language
Input YAML text like below:
View test-php-basic-auth.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 ||
rchrd2 /
Last active Dec 26, 2020
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 /
Last active Dec 11, 2020
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 / .bashrc
Last active Nov 25, 2020
archive files based on creation date
View .bashrc
archive() {
if [ ! -d "$1" ]; then echo Missing base; return 1; fi
local BASE=$1
for f in "${@:2:$#-1}"; do
if [ -d "$f" ]; then continue; fi;
local DATE=`date -r "$f" "+%Y-%m-%d"`
local YEAR=`date -r "$f" "+%Y"`
mkdir -p $TARGET_DIR
echo cp -iv "$f" "$TARGET_DIR/"
rchrd2 / proxy.js
Created Nov 4, 2020
Cloudflare worker CORS proxy
View proxy.js
// forked from:
addEventListener("fetch", event => {
async function handleRequest(request) {
try {
const url = new URL(request.url);
if (url.pathname === "/") {
The idea is to take stdin, and write it to a new unique log file
php myscript.php | newlog filename
import os
import sys
rchrd2 / index.php
Created Jan 2, 2015
Include protect.php to password protect a page
View index.php
<?php include 'protect.php';?>
<!DOCTYPE html>
<body>Secrets. </body>
rchrd2 /
Created Oct 20, 2019
wget example to download the website
wget --no-verbose --mirror --convert-links --directory-prefix=dwebsummit-download --no-host-directories
rsync -vv --recursive --links --perms --checksum --ignore-times --exclude={.dat,dat.json} dwebsummit-download/ dwebsummit-dat/
rchrd2 / parts.txt
Last active Sep 3, 2018
View parts.txt
Here are the exact parts I used:
USB HOST - This has all the software pre-installed. Just need to wire it up.
1x $16.76
MIDI Breakout board - This handles the extra components needed to wire up midi
1x $11.95
Power - Needed a usb-power breakout board and a power supply
1x $1.50