Skip to content

Instantly share code, notes, and snippets.

View masdude's full-sized avatar

masdude

  • China
View GitHub Profile
@easychen
easychen / get_title_via_url.php
Last active December 25, 2015 15:49
做了下title转码、对于文件链接只取前1k(服务器支持断点下载的情况下
<?php
function get_title_via_url( $url )
{
// 抓取前1024个字节
$context=array('http' => array ('header'=> 'Range: bytes=0-1024' ));
$xcontext = stream_context_create($context);
$content = strtolower( file_get_contents( $url , FALSE,$xcontext ) );
$reg = '/<title>(.+?)<\/title>/is';
IMPORTANT
Please duplicate this radar for a Safari fix!
This will clean up a 50-line workaround.
rdar://22376037 (https://openradar.appspot.com/radar?id=4965070979203072)
//////////////////////////////////////////////////////////////////////////////
(Now available as a standalone repo.)
@zacstewart
zacstewart / classifier.py
Last active September 19, 2024 23:56
Document Classification with scikit-learn
import os
import numpy
from pandas import DataFrame
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.pipeline import Pipeline
from sklearn.cross_validation import KFold
from sklearn.metrics import confusion_matrix, f1_score
NEWLINE = '\n'
@shunfan
shunfan / slugify.py
Last active June 25, 2017 20:18
Slugify Chinese
# coding=utf-8
"""
Slugify for Chinese
没有优化多音字
优化多音字的项目有:
https://github.com/jiedan/chinese_pinyin
"""
import re
import unidecode
@yongsun
yongsun / mmseg.py
Created June 21, 2013 02:23
implement mmseg Chinese word segmentation algorithm (http://technology.chtsai.org/mmseg/) with Python, dictionary file and character frequencies from mmseg4j project.
#!/usr/bin/python
# -*- encoding: UTF-8 -*-
import codecs
import sys
from math import log
from collections import defaultdict
class Trie (object):
class TrieNode:
@lbj96347
lbj96347 / Git_Hooks_For_Auto_Deploy.sh
Created May 27, 2013 09:06
Git_Hooks_For_Auto_Deploy
#!/bin/sh
#
# git autodeploy script when it matches the string "[deploy]"
#
# @author cashlee
# @link http://cashlee.info
# @version 0.1
#
# Usage:
# 1. put this into the post-receive hook file itself below
@wintercn
wintercn / HTMLLexicalParser.js
Last active March 15, 2025 09:25
HTML语法分析器模型
function StartTagToken(){
}
function EndTagToken(){
}
function Attribute(){
}
@yourdesigncoza
yourdesigncoza / php-mail-postfix-ubuntu
Created April 26, 2013 18:42
Ubuntu PHP mail() Function with Postfix
# Ubuntu PHP mail
# Ubuntu 12.04 LTS
# IMPORTANT : add your own data or parameters, I make use of double segments [[ your variable ]]. eg. ssh root@[[ 96.172.44.11 ]] should be replaced with ssh root@888.88.88.88 where "888.88.88.88" is your value, variable etc. I have a habit of using ":::" to indicate line ending and end of paragraph, crazy I know but be warned its just how I write ::: All notes are for my own use & should you use any it's at your own risk, it's NOT a Tutorial :::
# Resources
# https://help.ubuntu.com/12.04/serverguide/postfix.html
# http://sourcelibrary.org/2011/08/29/how-to-set-up-the-php-mail-function-on-a-ubuntu-linux-lamp-server/
# http://stackoverflow.com/questions/12083025/xampp-on-ubuntu-server-12-04-with-pear-installed-returns-errors-when-trying-to-u
# http://askubuntu.com/questions/47609/how-to-have-my-php-send-mail
@encorehu
encorehu / gist:5090139
Created March 5, 2013 12:57
suffixtree.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Encore Hu, <huyoo353@126.com>'
class Suffix(object):
def __init__(self, start, end):
self.start = start
self.end = end
#!/usr/bin/env python
'''
analyse the user's chrome behavior.
'''
import sqlite3
import urlparse
class AnalyseChrome:
'''
the user's chrome history log is writed by sqllite. and saved default in ~/.config/google-chrome/Default/History at ubuntu.
'''