Skip to content

Instantly share code, notes, and snippets.

@kayzhu
kayzhu / clean_chain.py
Created March 6, 2013 05:36
Clean chain calculation
import itertools
def generate_prime():
d = {}
for i in itertools.count(2):
n = d.pop(i, None)
if n:
p = n + i
while p in d:
@kayzhu
kayzhu / csrf.js
Last active September 27, 2016 10:11
Send POST request in Angular.js to a CSRF-protected Django view
<script type="text/javascript" src="/angular/angular.js"></script>
<script type="text/javascript" src="/angular/angular-cookies.min.js"></script>
// app.js
// inject ngCookies to your app named 'myApp'.
angular.module('myApp', ['ngCookies']);
// controller.js
function MyCtrl($scope, $http, $cookies) {
@kayzhu
kayzhu / wikiLogin.py
Created September 24, 2012 20:45
Sample script to log in Wikipedia
import requests
from bs4 import BeautifulSoup as bs
def get_login_token(raw_resp):
soup = bs(raw_resp.text, 'lxml')
token = [n['value'] for n in soup.find_all('input')
if n['name'] == 'wpLoginToken']
return token[0]
@kayzhu
kayzhu / pyconRequests.py
Created September 24, 2012 20:20
A sample script to make requests to pycon.ca
import requests
payload = {
'username': 'MY_USERNAME',
'password': 'MY_PASSWORD',
'login.submit': 'Login'
}
user_id = 8 # change it to your user_id for testing purpose
talk_id = 8 # change it for testing purpose
@kayzhu
kayzhu / anonymous Pro-Powerline.ttf
Created April 19, 2012 03:11
Anonymous Pro for vim-powerline