Skip to content

Instantly share code, notes, and snippets.

Avatar

Richard Caceres rchrd2

View GitHub Profile
@rchrd2
rchrd2 / gist:6179550
Created Aug 7, 2013
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!
View gist:6179550
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 Jul 3, 2018
electron-packager associate with file type (support drag)
View extra.plist
<?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 Jun 3, 2017
Poor man's php cache. Saves to files. Includes expiry.
View php_cache.php
<?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 Apr 5, 2018
BitBar + sshuttle
View sshuttle.sh
#!/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 / player.js
Created Dec 19, 2014
Videojs BigPlayButton Play Pause
View player.js
videojs.BigPlayButton.prototype.onClick = function(){
if(this.player_.paused()) {
this.player_.play();
} else {
this.player_.pause();
}
};
View README.md
                     
 ___       ___     ____     __    __     ______      __    __     _____   _____   
(  (       )  )   (    )    ) )  ( (    (____  \     \ \  / /    (  __ \  )__  \  
 \  \  _  /  /    / /\ \   ( (    ) )        ) /     () \/ ()     ) )_) )  __) /  
  \  \/ \/  /    ( (__) )   \ \  / /    __  / /      / _  _ \    (  ___/  (__ (   
   )   _   (      )    (     \ \/ /    /  \/ / __   / / \/ \ \    ) )        \ \  
   \  ( )  /     /  /\  \     \  /    ( () \__/ /  /_/      \_\  ( (      ___/  ) 
    \_/ \_/     /__(  )__\     \/      \__\____(  (/          \) /__\     )____/  
                                                                                  
@rchrd2
rchrd2 / freeway-2600.asm
Last active Oct 20, 2017
Honking & collision sound are redacted
View freeway-2600.asm
; Disassembly of roms/Freeway (1981) (Activision).a26
; Disassembled Thu Oct 19 22:17:47 2017
; Using DiStella v3.01a
;
; Command Line: ./binaries/osx/distella -pafs roms/Freeway (1981) (Activision).a26
;
processor 6502
VSYNC = $00
VBLANK = $01
@rchrd2
rchrd2 / add_swap.sh
Last active Aug 12, 2017
Create memory swap (virtual memory) on ubuntu
View add_swap.sh
sudo swapon -s
free -m
df -h
# 2G, 4G, etc
sudo fallocate -l 2G /swapfile
ls -lh /swapfile
sudo chmod 600 /swapfile
ls -lh /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
View .bash_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
View newlog.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