Skip to content

Instantly share code, notes, and snippets.

@voidfiles
voidfiles / textrank.py
Created January 20, 2012 08:22
An implmentation of TextRank in python
"""
From this paper: http://acl.ldc.upenn.edu/acl2004/emnlp/pdf/Mihalcea.pdf
I used python with nltk, and pygraph to do an implmentation of of textrank.
for questions: http://twitter.com/voidfiles
"""
import nltk
import itertools
@andris9
andris9 / git-cache-meta.sh
Created March 5, 2012 13:15
git-cache-meta
#!/bin/sh -e
#git-cache-meta -- simple file meta data caching and applying.
#Simpler than etckeeper, metastore, setgitperms, etc.
#from http://www.kerneltrap.org/mailarchive/git/2009/1/9/4654694
#modified by n1k
# - save all files metadata not only from other users
# - save numeric uid and gid
# 2012-03-05 - added filetime, andris9
@tomds
tomds / login.py
Created July 2, 2012 10:24
Django site-wide login required middleware including AJAX support
# Based on http://djangosnippets.org/snippets/1158/
import json
import re
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect
class EnforceLoginMiddleware(object):
"""
@cjgiridhar
cjgiridhar / tornadowhoosh.py
Created September 21, 2012 11:15
Tornado - Whoosh
import whoosh,os
from whoosh import index
import whoosh.index
import whoosh.qparser
import tornado.ioloop
import tornado.web
class Search(object):
def __init__(self, indexdir, searchstr):
self.indexdir = indexdir
# Copyright (c) 2010, Philip Plante of EndlessPaths.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@ninehills
ninehills / backgroudmix.py
Last active December 10, 2015 17:08 — forked from methane/gist:2185380
tornado add block task to ThreadPool
from time import sleep
import tornado
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
class BackgroundMix(tornado.web.RequestHandler):
"""将block任务放入线程池中执行
EXAMPLE:
# blocking task like querying to MySQL
@inkless
inkless / blogs_and_nlp__summarize.py
Created April 24, 2013 01:27
对文章进行自动摘要(Automatic summarization)的算法实现(python)
# -*- coding: utf-8 -*-
import sys
import json
import nltk
import numpy
N = 100 # Number of words to consider
CLUSTER_THRESHOLD = 5 # Distance between words to consider
TOP_SENTENCES = 5 # Number of sentences to return for a "top n" summary
@gradetwo
gradetwo / __init__.py
Last active February 19, 2023 06:56
Connection Pool in redis python client redis-py
import redis
class RedisStorage(object):
_redis_pool = {}
@classmethod
def setup_redis_pool(cls, redis_pool):
for k, v in redis_pool.iteritems():
cls._redis_pool[k] = redis.Redis(v[0], v[1])
@madjar
madjar / scrapper.py
Last active March 5, 2023 15:02
A example of scrapper using asyncio and aiohttp
import asyncio
import aiohttp
import bs4
import tqdm
@asyncio.coroutine
def get(*args, **kwargs):
response = yield from aiohttp.request('GET', *args, **kwargs)
return (yield from response.read_and_close(decode=True))
@chenshaoju
chenshaoju / sysctl.conf
Last active September 7, 2023 06:31
sysctl.conf
#
# /etc/sysctl.conf - Configuration file for setting system variables
# See /etc/sysctl.d/ for additonal system variables
# See sysctl.conf (5) for information.
#
#kernel.domainname = example.com
# Uncomment the following to stop low-level messages on console
#kernel.printk = 3 4 1 3