Skip to content

Instantly share code, notes, and snippets.

View pyokagan's full-sized avatar

Paul Tan pyokagan

View GitHub Profile
@pyokagan
pyokagan / tumblr.py
Created November 19, 2012 14:39
Tumblr oAuth Non-compliance
import urllib,hmac,time,hashlib,base64,httplib,sys,json,urlparse
## This is just a simple example that is self contained.
## You will need to modified it to make it work
##
## creds - need to be filled out
## blognmae - needs to be defined
##
## reads in image files from the command line and posts to your blog
@pyokagan
pyokagan / gist:4250200
Created December 10, 2012 11:58
For future reference: How to properly modify the URL of a urllib.request.Request
import urllib.request
from urllib.parse import urlsplit, urlunsplit, unquote
class ModifyUrlHandler(urllib.request.BaseHandler):
def __init__(self, target):
x = urlsplit(target)
self.full_url = urlunsplit(x._replace(fragment=""))
self.fragment = x.fragment
#Remove port from x.netloc if present for origin_req_host
self.origin_req_host = x.netloc.partition(":")[0]
@pyokagan
pyokagan / mozreplcurl.py
Created December 11, 2012 09:35
mozreplcurl - Curl wrapper that uses Firefox's cookies database
#! /usr/bin/env python3.2
"""
mozreplcurl - Wrapper around curl that adds on firefox's cookies, and updates firefox's cookie db after curl finishes running.
To update firefox's cookies db when firefox is running, mozrepl is required to be installed.
"""
import sys
import re
from telnetlib import Telnet
from argparse import ArgumentParser
@pyokagan
pyokagan / fun.js
Last active December 16, 2015 07:59
fun.js -- injecting 100% more fun and excitement into nodejs programming by implementing module reloading, code swapping, classes with C3 MRO, state saving, loading and replacing.
/* This fun module implements 100% more fun and excitement in
* nodejs coding.
*
* Implements module reloading, code swapping, classes with C3 MRO,
* state saving (pickling) and loading (unpickling) and replacing.
*
* This is extracted from the bb4 source code, licensed under the MIT License.
* bb4 is available at <https://github.com/pyokagan/bb4>
*
* Requires node-weak to be installed. (npm install weak)
@pyokagan
pyokagan / code2tex.py
Created February 5, 2014 22:22
code2tex - Converts a list of code files into a LaTeX document.
#! /usr/bin/python
"""Converts a list of code files into a LaTeX document."""
from argparse import ArgumentParser
import re
import os
import subprocess
import pygments
import itertools
import sys
import signal
@pyokagan
pyokagan / tempy.py
Created April 3, 2014 13:32
Simple python templates
r"""Inline python
USAGE
------
`render()` compiles and renders a template, returning a string:
>>> render(r'Hello {{name}}!', name='World')
'Hello World!'
`compile()` compiles a template into a function for later use:
@pyokagan
pyokagan / gist:fa20ece86a9774d02719
Last active August 29, 2015 14:00
Working Android 4.4 emulator

Problem was that noemulatedsd was not set in /fstab.goldfish which led to /mnt/secure/asec to not be mounted at boot. I had to look through Android's source code to find this -_-. Why google.

Steps to get working emulator:

  1. Install Android SDK Tools Only. The directory where the SDK is installed will henceforth be known as <sdk>.
  2. Launch the Android SDK Manager, install everything under the Android 4.4.2 group
  3. Now overwrite the ramdisk.img file (located at <sdk>/add-ons/addon-google_apis-google-19/images/armeabi-v7a with this modified version. This is the ramdisk file used by the Google APIs (Google Inc.) - API Level 19 device target.
  4. Launch the Android ADB Manager, create a new Android Virtual Device. Make sure the target is set to Google APIs (Google Inc.) - API Level 19. Give the device plenty of RAM, and make sure that there is a SD Card!. (Also, remember to enable GPU Acceler
@pyokagan
pyokagan / README.rst
Last active August 29, 2015 14:17
Google Summer of Code 2015 proposal for git

Make git-pull and git-am builtins

Abstract

git-pull and git-am are frequently used git subcommands. However, they are porcelain commands and implemented as shell scripts, which has some limitations which can cause poor performance, especially in non-POSIX environments like Windows. I propose to rewrite these scripts into low level C code and make them builtins. This will increase git's portability, and may

#!/usr/bin/env python3
import sys
import re
import argparse
import subprocess
import requests
def get_remote_owner_repo(remote):
"Returns the github owner and repo of the remote"
r"""Simple Python templates
USAGE
------
`render()` compiles and renders a template, returning a string:
>>> render('Hello {{name}}!', name='World')
'Hello World!'
`compile()` compiles a template into a function for later use: