Skip to content

Instantly share code, notes, and snippets.

View pyokagan's full-sized avatar

Paul Tan pyokagan

View GitHub Profile
@pyokagan
pyokagan / youtube-sh
Created May 1, 2012 13:24
Prints list of videos in season of Youtube Show. Requires Python 3 for parsing URLs. Requires jshon for parsing JSON. Now, why didn't I write this whole thing in Python in the first place :(
#! /bin/sh
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: $0 URL SEASON" >&2
exit 1
fi
SHOW_ID=`python3 -c 'from urllib.parse import urlparse, parse_qs;from sys import argv;print(parse_qs(urlparse(argv[1]).query)["p"][0])' "$1"`
SHOW_URL="http://gdata.youtube.com/feeds/api/shows/$SHOW_ID/content?v=2&alt=json"
SEASON="$2"
@pyokagan
pyokagan / gist:2891064
Created June 7, 2012 19:32
tl;dr of usage of pykoauth2
#Add client credentials
pykoauth2 addclient facebook.com CLIENT_ID CLIENT_SECRET
#Make authorization request (starts web server at http://localhost:8080 and prints URL. Point your web browser to this URL)
pykoauth2 authcode facebook.com
#Get access token
pykoauth2 token --server_fqdn facebook.com
#Make authenticated request
pykoauth2curl --data-urlencode 'message=Hello world from pykoauth2!' \
'https://graph.facebook.com/me/feed'
@pyokagan
pyokagan / multiprocessing_fail
Created June 10, 2012 03:13
Pickling in multiprocessing causing bug
---------------------------------------------------------------------------
PicklingError Traceback (most recent call last)
C:\Users\pyokagan\<ipython-input-5-846925efa119> in <module>()
9 #Wrap all Client Credentials!
10 cwrap.wrap_authorization_server_database(context.authorization_servers, client_db)
---> 11 args.func(args)
C:\Users\pyokagan\<ipython-input-2-7bd01ceccacc> in authcode(args)
19 redirect_uri = args.redirect_uri
@pyokagan
pyokagan / Island5.vb
Created June 27, 2012 07:08
Bouncy Boar 3 Island Object
Imports BouncyBoar3
Namespace MyGame
Namespace Nodes
''' <summary>
'''
''' </summary>
''' <remarks>
@pyokagan
pyokagan / sshinotifytransfer
Created October 7, 2012 07:06
sshinotifytransfer - Transfers files in one direction
#! /bin/bash
#Transfers files in one direction
usage="$0 remote dest"
if [[ !( -n $1 ) || !( -n $2 ) ]]; then
echo $usage >&2
exit 2
fi
@pyokagan
pyokagan / youtube-plvids.sh
Created October 19, 2012 08:46
Prints URL of all videos in Youtube Playlist. Requires: curl, jshon
#! /bin/bash
if [ -z $1 ]; then
echo "usage: $0 URL" >&2
exit 1
fi
playlistid="$(sed -n 's|https://www\.youtube.com/playlist?list=PL\([A-Z0-9]*\)|\1|p' <<< $1)"
if [ -z "$playlistid" ]; then
echo "Invalid URL" >&2
exit 1
@pyokagan
pyokagan / mozrepl-inspect.py
Created October 22, 2012 11:10
Prints HTML contents of inspected node in Firebug. Requires firebug and mozrepl to be installed in Firefox. For Python 2.6, requires python-argparse.
#! /usr/bin/python2.6
#NOTE: Also python3 compatible.
from __future__ import print_function,unicode_literals
import time, json, sys, re
from argparse import ArgumentParser
from telnetlib import Telnet
class Mozrepl:
def __init__(self, host="127.0.0.1", port=4242):
self.host = host
#! /usr/bin/python2.6
"""
trunc -n LENGTH -k 0,1,2,3... COMPONENTS...
"""
from __future__ import print_function,unicode_literals
from argparse import ArgumentParser
from math import floor
def shorten(length, x, suffix = "..."):
if len(x) <= length:
@pyokagan
pyokagan / code2tex.py
Created October 31, 2012 01:01
Converts a list of code files into a latex document.
#! /usr/bin/python3
"""Converts a list of code files into a latex document."""
from argparse import ArgumentParser
import re
import os
from pygments.lexers import get_lexer_for_filename
def filter_tex(x):
def escape(x):
@pyokagan
pyokagan / googlecurl.py
Created November 2, 2012 16:21
googlecurl - Wrapper around oauth2curl providing automatic pagination of items in google API responses. Supports gdata json, youtube jsonc and new-style google API responses.
#! /usr/bin/python3 -u
"""A wrapper around oauth2curl. Makes multiple
calls to oauth2curl. Returns items one item
per line."""
from argparse import ArgumentParser
from subprocess import Popen, PIPE
import sys
from urllib.parse import urlsplit, parse_qs, urlencode, urlunsplit
import json
import signal