Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / stdin2www
Last active Jan 7, 2017 — forked from cwarden/stdin2www.sh
Show stdin in a web browser (for Mac OS X)
View stdin2www
#!/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 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 / rproxy.conf
Last active Dec 27, 2016
NGINX CLI – how to start nginx as a process
View rproxy.conf
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 Dec 24, 2016
great screenrc config - /etc/screenrc
View 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
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 / lorum-ipsum
Last active Jun 17, 2016
lorum ipsum command. place in /usr/local/bin and "chmod +x /usr/local/bin/lorum-ipsum"
View 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 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
@rchrd2
rchrd2 / Gruntfile.js
Created May 4, 2016
Example gruntfile for react
View Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
watch: {
files: [
'src/**/*.js',
'src/**/*.jsx'
],
tasks: ['browserify']
},
browserify: {
@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:
@rchrd2
rchrd2 / upload_site.sh
Created Apr 5, 2016
Neocities Upload
View upload_site.sh
#!/bin/bash
# Neocities provies an API for uploading files from ./public_html to your site
#
# Example Usage:
# $ USERNAME=username PASS=secret_pass bash upload_site.sh
function upload_file {
fullName=$1
shortName=${fullName:2}