Skip to content

Instantly share code, notes, and snippets.

View rchrd2's full-sized avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / .bashrc
Last active November 25, 2020 04:27
archive files based on creation date
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 / stash.py
Last active October 7, 2020 21:59
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 January 2, 2015 23:09
Include protect.php to password protect a page
<?php include 'protect.php';?>
<!DOCTYPE html>
<html>
<head></head>
<body>Secrets. </body>
</html>
@rchrd2
rchrd2 / download.sh
Created October 20, 2019 02:08
wget example to download the decentralizedweb.net website
#!/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 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
@rchrd2
rchrd2 / gist:6179550
Created August 7, 2013 22:39
How to link django-social-auth with google-api-python-client I am creating a gist, because this took me way to long to figure out. Maybe it can save you some time!
import httplib2
from apiclient.discovery import build
from oauth2client.client import AccessTokenCredentials
def connect_helper(user):
c = user.social_auth.get(provider='google-oauth2')
access_token = c.tokens['access_token']
credentials = AccessTokenCredentials(access_token, 'my-user-agent/1.0')
http = httplib2.Http()
@rchrd2
rchrd2 / extra.plist
Created July 3, 2018 05:14
electron-packager associate with file type (support drag)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>txt</string>
@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 / sshuttle.sh
Last active April 5, 2018 22:31
BitBar + sshuttle
#!/bin/bash
#
# Easily start/stop sshuttle
#
# <bitbar.title>sshuttle</bitbar.title>
# <bitbar.version>v1.0</bitbar.version>
# <bitbar.author>richard@archive.org</bitbar.author>
# <bitbar.author.github>rchrd2</bitbar.author.github>
# <bitbar.desc>Easily start/stop a background shhuttle.</bitbar.desc>
# <bitbar.image></bitbar.image>
@rchrd2
rchrd2 / README.md
Last active November 15, 2017 07:20
wav2mp3
                     
 ___       ___     ____     __    __     ______      __    __     _____   _____   
(  (       )  )   (    )    ) )  ( (    (____  \     \ \  / /    (  __ \  )__  \  
 \  \  _  /  /    / /\ \   ( (    ) )        ) /     () \/ ()     ) )_) )  __) /  
  \  \/ \/  /    ( (__) )   \ \  / /    __  / /      / _  _ \    (  ___/  (__ (   
   )   _   (      )    (     \ \/ /    /  \/ / __   / / \/ \ \    ) )        \ \  
   \  ( )  /     /  /\  \     \  /    ( () \__/ /  /_/      \_\  ( (      ___/  ) 
    \_/ \_/     /__(  )__\     \/      \__\____(  (/          \) /__\     )____/