This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set shell=/bin/bash | |
" config Vundle | |
filetype off | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
Plugin 'VundleVim/Vundle.vim' | |
Plugin 'ctrlpvim/ctrlp.vim' " fuzzy find files | |
Plugin 'scrooloose/nerdtree' " file drawler, open with :NERDTreeToggle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config for python lib 'thefuck' | |
eval "$(thefuck --alias)" | |
eval "$(thefuck --alias fuck)" | |
function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; } | |
# linux core bash命令, mac是-G, linux是--color=auto | |
#alias ls='ls --color=auto' | |
#alias ls='ls -G' | |
alias vim="mvim -v" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frontera/contrib/backends/sqlalchemy/revisiting.py | |
def retry_and_rollback(func): | |
def func_wrapper(self, *args, **kwargs): | |
tries = 5 | |
while True: | |
try: | |
return func(self, *args, **kwargs) | |
except Exception as exc: | |
self.logger.exception(exc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frontera/utils/graphs/models.py | |
Base = declarative_base() | |
class BaseModel(object): | |
__abstract__ = True | |
@classmethod | |
def get_pk_name(cls): | |
return cls.__mapper__.primary_key[0].name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frontera/utils/graphs/manager.py | |
DEFAULT_ENGINE = 'sqlite:///:memory:' | |
class CrawlGraphManager(object): | |
def __init__(self, engine=DEFAULT_ENGINE, autocommit=False, autoFlush=False, | |
echo=False, drop_all_tables=False, clear_content=False): | |
self.engine = create_engine(engine, echo=echo) | |
if drop_all_tables: | |
Base.metadata.drop_all(self.engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frontera/utils/misc.py | |
from importlib import import_module | |
def load_object(path): | |
"""Load an object given its absolute object path, and return it. | |
object can be a class, function, variable o instance. | |
path ie: 'myproject.frontier.models.Page' | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script | |
while true; do | |
read -p "Do you wish to install this program?" yn | |
case $yn in | |
[Yy]* ) make install; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import heapq | |
class PriorityQueue: | |
def __init__(self): | |
self._queue = [] | |
self._index = 0 | |
def push(self, item, priority): | |
heapq.heappush(self._queue, (-priority, self._index, item)) | |
self._index += 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kafka-run-class kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic xxx --time -1 --offsets 1 | awk -F ':' '{sum += $3} END {print sum}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CaselessDict(dict): | |
__slots__ = () | |
def __init__(self, seq=None): | |
super(CaselessDict, self).__init__() | |
if seq: | |
self.update(seq) | |
def __getitem__(self, key): | |
return dict.__getitem__(self, self.normkey(key)) |
OlderNewer