Skip to content

Instantly share code, notes, and snippets.

View rchrd2's full-sized avatar

Richard Caceres rchrd2

View GitHub Profile
PS1="$ "
alias pserve="python -m SimpleHTTPServer"
# show git branch in prompt
export PS1="(\$(git branch 2>/dev/null | grep '^*' | colrm 1 2))\$ "
source /usr/local/etc/bash_completion.d/git-completion.bash
# http://unix.stackexchange.com/a/48113
@rchrd2
rchrd2 / php_cache.php
Created June 3, 2017 22:38
Poor man's php cache. Saves to files. Includes expiry.
<?php
function add_cache($key, $value, $ttl) {
$dir = __DIR__.'/../cache/';
// Remove slashes for security
$filename = $dir . str_replace('/', '', $key);
// Store expiry in first line
$lines = [(string)(time() + (int)$ttl), $value ];
if (!file_exists($dir)) mkdir($dir, 0755, true);
file_put_contents($filename, implode("\n", $lines));
@rchrd2
rchrd2 / newlog.py
Last active June 2, 2017 17:28
newlog
#!/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 / stdin2www
Last active January 7, 2017 19:31 — forked from cwarden/stdin2www.sh
Show stdin in a web browser (for Mac OS X)
#!/bin/sh
# read from stdin, write to a temp file, open the temp file in a browser, then delete it
tmpfile=$(mktemp).html; cat > $tmpfile; open $tmpfile; #rm $tmpfile
@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 / rproxy.conf
Last active December 27, 2016 01:07
NGINX CLI – how to start nginx as a process
error_log /dev/stderr;
events {}
http {
#access_log /dev/stdout;
access_log /dev/null;
server {
listen 8066;
server_name _;
location / {
proxy_pass http://rchrd.net;
@rchrd2
rchrd2 / screenrc
Last active December 24, 2016 20:20
great screenrc config - /etc/screenrc
# Jeff McCune <jeff@puppetlabs.com>
# 2010-07-30
# GNU Screen configuration file
defutf8 on
defflow off
vbell off
autodetach on
startup_message off
defscrollback 10000
@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 / lorum-ipsum
Last active June 17, 2016 17:22
lorum ipsum command. place in /usr/local/bin and "chmod +x /usr/local/bin/lorum-ipsum"
#!/usr/local/bin/python
print """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam volutpat velit lorem, a aliquet mi egestas sit amet. Aliquam vitae mauris sit amet enim pellentesque consequat. Maecenas et nisi massa. Donec mi justo, mattis et tellus nec, elementum porttitor libero. Ut a lacus vitae orci mollis suscipit. Maecenas ullamcorper ligula in eros facilisis, et hendrerit neque sollicitudin. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec et quam quis metus ullamcorper dignissim. Nullam faucibus at nulla vel imperdiet. Ut nec pharetra eros. Aliquam erat volutpat. Curabitur sem diam, cursus ultricies velit non, placerat consequat velit.
Integer ut arcu id felis consectetur ultrices. Fusce ac augue ligula. Integer tempor lobortis posuere. Nam magna quam, efficitur varius blandit vitae, vulputate a diam. Suspendisse eu turpis aliquet ligula molestie commodo id consectetur lorem. Curabitur ornare, turpis vitae commodo hendrerit, sapien just
@rchrd2
rchrd2 / parts.txt
Last active September 3, 2018 23:15
DIY USB HOST parts
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