Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / yaml2dot.py
Created Apr 21, 2016
YAML to Graphviz
View yaml2dot.py
#!/usr/bin/python
# vim: fileencoding=utf-8
u'''Translate YAML written text to graphviz dot language
Input YAML text like below:
---
foo:
View test-php-basic-auth.php
<?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 / admin.py
Last active Dec 26, 2020
Adding custom views to django's admin
View admin.py
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 Dec 11, 2020
Django object manager with Haversine distance annotation method (aka filter by distance with mysql)
View models.py
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 / .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"`
local TARGET_DIR="$BASE/$YEAR/$DATE"
mkdir -p $TARGET_DIR
echo cp -iv "$f" "$TARGET_DIR/"
@rchrd2
rchrd2 / proxy.js
Created Nov 4, 2020
Cloudflare worker CORS proxy
View proxy.js
// 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 === "/") {
View stash.py
#!/usr/bin/python3
"""
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
rchrd2 / index.php
Created Jan 2, 2015
Include protect.php to password protect a page
View index.php
<?php include 'protect.php';?>
<!DOCTYPE html>
<html>
<head></head>
<body>Secrets. </body>
</html>
@rchrd2
rchrd2 / download.sh
Created Oct 20, 2019
wget example to download the decentralizedweb.net website
View download.sh
#!/bin/bash
wget --no-verbose --mirror --convert-links --directory-prefix=dwebsummit-download --no-host-directories https://decentralizedweb.net
rsync -vv --recursive --links --perms --checksum --ignore-times --exclude={.dat,dat.json} dwebsummit-download/ dwebsummit-dat/
@rchrd2
rchrd2 / parts.txt
Last active Sep 3, 2018
DIY USB HOST parts
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 http://www.hobbytronics.co.uk/usb-host-midi
MIDI Breakout board - This handles the extra components needed to wire up midi
1x $11.95 http://www.amazon.com/ubld-it-MIDI-Breakout-Board/dp/B00YDLVLVO/ref=sr_1_1?ie=UTF8&qid=1464058935&sr=8-1&keywords=midi+breakout
Power - Needed a usb-power breakout board and a power supply
1x $1.50 https://www.adafruit.com/products/1764