Skip to content

Instantly share code, notes, and snippets.

@lrvick
lrvick / google-oauth.py
Created January 28, 2015 09:18
Python/Flask oAuth authorization example.
from flask import Flask, request, redirect
from rauth.service import OAuth2Service
import simplejson as json
google = OAuth2Service(
name='google',
consumer_key='478110803143-ct2e336q06knns6p7pgnob1msandulj3.apps.googleusercontent.com',
consumer_secret='BGncEz1jPsNAMN7mzqki7zTy',
access_token_url='https://accounts.google.com/o/oauth2/token',
authorize_url='https://accounts.google.com/o/oauth2/auth'
@lrvick
lrvick / rsscrawl.py
Created January 28, 2015 09:17
Simple Python RSS crawler using lxml
import lxml.html
urls= (
'http://lrvick.net',
'http://zenhabits.net/',
'http://theoatmeal.com/',
'http://botd.wordpress.com/',
'http://informantpodcast.com/',
'http://moo.com',
)
@lrvick
lrvick / yts.sh
Created January 28, 2015 06:59
Youtube batch browserless search/autoplay script I wrote ages ago. Probably no longer works.
#!/bin/bash
#YouTubeSucker 0.9999999423ish
#your media player and args of choice, must have flv support, mplayer or vlc will do the job
mediap="mplayer -fs"
terms="$*"
if [ "$terms" = "" ] ; then
echo 'Usage: yts.sh [YouTube URL] [search terms]'
fi
@lrvick
lrvick / nfcauth.sh
Created January 28, 2015 06:57
PAM NFC screen unlock helper script
valid_hash=$( cat /home/lrvick/.nfcauth )
challange_hash=$( printf $1 | shasum -a 256 | sed 's/ .*//' )
echo $valid_hash
echo $challange_hash
if [ "$valid_hash" == "$challange_hash" ]; then
echo "unlocked"
killall slock
fi
@lrvick
lrvick / crashff.html
Created January 28, 2015 06:20
Little example that consistently crashes Firefox. This is why it makes more sense to do one process per tab.
<html>
<body>
<a href="#" onclick="die()">click me!</a>
<script>
function die () {
setTimeout(function () {die(); die()}, 0)
}
</script>
</body>
</html>
@lrvick
lrvick / Dockerfile
Last active August 29, 2015 14:12
Cassandra single instance Docker
FROM abh1nav/java7
# Download and extract Cassandra
RUN \
mkdir /opt/cassandra; \
wget -O - http://www.us.apache.org/dist/cassandra/2.1.2/apache-cassandra-2.1.2-bin.tar.gz \
| tar xzf - --strip-components=1 -C "/opt/cassandra";
ADD cassandra.yaml /opt/cassandra/conf/
ADD run.sh /tmp/
@lrvick
lrvick / gist:ba303eae8ad89b7f0f4d
Created December 8, 2014 22:29
Twilio Node.JS SMS sending example.
var twilioNumber = '+19252414543';
var twilioSID = 'Your twilio account SID';
var twilioToken = 'Your twilio auth tokenn'
var client = require('twilio')(twilioSID,twilioToken);
var sendSMS = function(number,message){
client.sms.messages.post({
to:twilioNumber,
from:fromNumber,
@lrvick
lrvick / Dockerfile
Created November 13, 2014 19:40
Dockerfile for simple nginx static hosting
#Get latest debian image
FROM debian:wheezy
RUN echo "deb http://nginx.org/packages/debian/ wheezy nginx" >> /etc/apt/sources.list.d/nginx.list
RUN apt-key adv --fetch-keys "http://nginx.org/keys/nginx_signing.key"
# Update package repos
RUN apt-get update -y --fix-missing
RUN apt-get upgrade -y --fix-missing
@lrvick
lrvick / nginx.conf
Created November 13, 2014 18:40
Convert specific GET params to Cookies with NGINX.
# Convert GET access_token to Cookie to avoid Referrer leaks.
location / {
if ($request_uri ~ (.*[\?&])access_token=[^&]*&?(.*)){
add_header Set-Cookie access_token=$arg_access_token;secure;HttpOnly
return 301 $1$2;
}
}
@lrvick
lrvick / nginx.conf
Last active August 29, 2015 14:09
Nginx conditions to deny *.appcache files to IOS7 users to avoid their severe bugs.
# If IOS7 sees a *.appcache file it freaks out and disables browser
# history until browser cache is cleared AND it is rebooted.
# Tell IOS7 users asking for a *.appcache file to GTFO with a 412
# "precondition failed" response so they don't hurt themselves.
if ( $http_user_agent ~* '(iPad|iPhone);.*CPU.*OS 7_' ){
set $test IOS7;
}
if ($request_filename ~* ^.+.appcache$) {
set $test "${test}_APPCACHE";
}