Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / note.py
Created March 19, 2013 02:58
use notepad.cc as simple data storage
import requests
class Note:
def __init__(self, id):
self.id = id
self.note = None
def get_note(self, refresh=False):
if refresh or self.note is None:
text = requests.get('http://notepad.cc/'+self.id).content
@scturtle
scturtle / crawler.py
Created March 19, 2013 13:48
save feed data from GR
# coding: utf-8
import json
import urllib
import requests
base= 'http://www.google.com/reader/api/0/stream/contents/feed/'
url = 'http://scturtle.me/atom.xml'
url = urllib.quote(url)
@scturtle
scturtle / insta.py
Created March 19, 2013 14:10
get web page content via instapaper (slow but quick)
# coding: utf-8
import requests
from urllib import quote_plus
from bs4 import BeautifulSoup
def get_html(url):
text = requests.get('http://www.instapaper.com/text?u='+
quote_plus(url)).content
soup = BeautifulSoup(text)
title = soup.find('div',{'id':'titlebar'}).find('h1').get_text()
@scturtle
scturtle / youku.py
Created April 2, 2013 16:43
play youku with MPlayerX.app
#!/usr/bin/env python
import re
import os
import sys
import urllib
if len(sys.argv) <= 1:
print 'Usage: {} [video | videourl]'.format(sys.argv[0])
sys.exit()
@scturtle
scturtle / cnt0.py
Created April 3, 2013 15:31
number of last 0 in 32bit binary number from http://www.matrix67.com/blog/archives/3985
c=(0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9)
def num_of_last_0_in_32bit(v):
return c[(0xffffffff & ((v&-v) * 0x077CB531)) >> 27]
@scturtle
scturtle / activity.py
Last active October 11, 2017 17:07
undocumented twitter activity api
# coding: utf-8
import oauth2 as oauth
import json
CONSUMER_KEY = "yT577ApRtZw51q4NPMPPOQ"
CONSUMER_SECRET = "3neq3XqN5fO3obqwZoajavGFCUrC42ZfbrLXy5sCv8"
ACCESS_KEY = ""
ACCESS_SECRET = ""
consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET)
@scturtle
scturtle / app.py
Created April 14, 2013 04:53
Flask login with google+ oauth
from flask import Flask, request, session, redirect, url_for
import urllib
import requests
app = Flask(__name__)
app.secret_key = 'iwonttellyou'
redirect_uri = 'http://localhost:5000/callback'
client_id = '' # get from https://code.google.com/apis/console
client_secret = ''
@scturtle
scturtle / config.fish
Last active December 16, 2015 11:48
powerline prompt for fishfish (with patched font)
set DARKGREEN 2b6003
set LIGHTGREEN b7da2d
set DARKBLUE 2f6f93
set LIGHTBLUE 87d6fc
set SPARATOR \u2b80
set SPARATOR_THIN \u2b81
function fish_prompt
# first line
set_color -o $DARKGREEN -b $LIGHTGREEN
@scturtle
scturtle / kongzhi.py
Created April 28, 2013 12:57
vote for shanghaizoo
# coding: utf-8
#import httplib
#httplib.HTTPConnection.debuglevel = 1
import gevent
from gevent import monkey, Greenlet
monkey.patch_all()
from gevent.pool import Pool
import requests
import re
@scturtle
scturtle / crawler.go
Created May 4, 2013 09:32
A Tour of Go #70 Exercise: Web Crawler
package main
import (
"fmt"
)
type Fetcher interface {
Fetch(url string) (body string, urls []string, err error)
}