Skip to content

Instantly share code, notes, and snippets.

View greatghoul's full-sized avatar
🏠
Working from home

greatghoul greatghoul

🏠
Working from home
View GitHub Profile
@greatghoul
greatghoul / 265g_pics.py
Created September 26, 2012 17:22
265g.com 美图下载
#-*- coding: utf-8 -*-
import urllib, re, os, argparse
RE_NEXT_URL = ur'<a href=\"(?!javascript\:)([^\"]*?)">下一页<\/a>'
RE_PICTURE = ur'<p\s+(?:align=\"center\")>\s*<img.*?src=\"(.*?)\".*?\/?>'
RE_ARCTITLE = ur'var arctitle=\'(.*?)\';'
def get_html(url):
try:
return urllib.urlopen(url).read().decode('gbk')
@greatghoul
greatghoul / gmail-gist.xml
Created September 28, 2012 15:13
Gist Gmail Gadget
<?xml version="1.0" encoding="UTF-8" ?>
<ApplicationManifest xmlns="http://schemas.google.com/ApplicationManifest/2009">
<!-- Support info to show in the marketplace & control panel -->
<Support>
<!-- URL for application setup as an optional redirect during the install -->
<Link rel="setup" href="http://_example.com_/google/setup.php?domain=${DOMAIN_NAME}" />
<!-- URL for application configuration, accessed from the app settings
page in the control panel -->
@greatghoul
greatghoul / group_sum.py
Created November 15, 2012 14:24
SqlAlchemy Group By
#!/usr/bin/env python
#-*- coding: utf-8 -*-
from sqlalchemy import create_engine, Column, Integer, String, func
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
class StudentInfo(Base):
@greatghoul
greatghoul / slides.md
Last active December 14, 2015 15:29
Rails for Legacy Database

name: inverse layout: true class: inverse

class: center middle

Rails for Legacy Database

[greatghoul@scriptfan-201301]

class: center middle

Convention Over Configuration

@greatghoul
greatghoul / slides.md
Last active November 30, 2018 04:13
The Official remark Slideshow

title: remark description: Introduce remark. name: inverse layout: true class: center, middle, inverse

#remark [ri-mahrk]

What is it and why should I be using it?

(function(){
var gist_id = document.location.pathname.replace(/.*\//g, '');
window.open('http://remarks.sinaapp.com/s/' + gist_id, '_blank', 'width=600,height=400');
})()
/*
gfw_whitelist.pac
GFW Whitelist
- inspired by autoproxy and chnroutes
- https://gist.github.com/greatghoul/5283630/raw/subway-whitelist.pac
v1.2
Author: n0gfwall0@gmail.com
License: MIT License
@greatghoul
greatghoul / get_elem_attr.py
Last active December 15, 2015 21:49
BeautifulSoup 获取标签属性 http://segmentfault.com/q/1010000000185964
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
import re
def get_timestamp(html):
soup = BeautifulSoup(html)
authi_elems = soup.findAll('div', { 'class': 'authi' })
for authi_elem in authi_elems:
date_elem = authi_elem.find('span', title=re.compile(r'20\d{2}-\d+-\d+\s\d{2}:\d{2}:\d{2}'))
print date_elem.get('title')
@greatghoul
greatghoul / string-fmt.js
Created April 9, 2013 08:32
Format javascript.
// 格式化字符串
//
// 用法:
//
// var s1 = '%{1} and %{2}!';
// console.log('source: ' + s1);
// console.log('target: ' + fmt(s1, 'ask', 'learn'));
//
// var s2 = "%{name} is %{age} years old, his son's name is %{sons[0].name}";
// console.log('source: ' + s2);
@greatghoul
greatghoul / background.js
Last active January 16, 2019 06:37
crx-test - Chrome插件开发-请问如何跨域XMLHttpRequest中修改Referer
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.type === 'xmlhttprequest') {
var exists = false;
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name === 'Referer') {
exists = true;
details.requestHeaders[i].value = 'http://www.baidu.com';
break;
}