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
""" | |
A file lock implementation that tries to avoid platform specific | |
issues. It is inspired by a whole bunch of different implementations | |
listed below. | |
- https://bitbucket.org/jaraco/yg.lockfile/src/6c448dcbf6e5/yg/lockfile/__init__.py | |
- http://svn.zope.org/zc.lockfile/trunk/src/zc/lockfile/__init__.py?rev=121133&view=markup | |
- http://stackoverflow.com/questions/489861/locking-a-file-in-python | |
- http://www.evanfosmark.com/2009/01/cross-platform-file-locking-support-in-python/ | |
- http://packages.python.org/lockfile/lockfile.html |
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
#!/usr/bin/env python | |
# Author: Chris Eberle <eberle1080@gmail.com> | |
# Watch for any changes in a module or package, and reload it automatically | |
import pyinotify | |
import imp | |
import os | |
class ModuleWatcher(pyinotify.ProcessEvent): | |
""" |
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
#!/bin/bash | |
# In this case, the backup file names end up with '~'. | |
for f in $(find . -print | grep -i '~$'); do rm $f; 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
newmtl cube | |
Ns 10.0000 | |
Ni 1.5000 | |
d 1.0000 | |
Tr 0.0000 | |
Tf 1.0000 1.0000 1.0000 | |
illum 2 | |
Ka 0.0000 0.0000 0.0000 | |
Kd 0.5880 0.5880 0.5880 | |
Ks 0.0000 0.0000 0.0000 |
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
#! /usr/bin/python | |
import smtplib | |
from optparse import OptionParser | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.mime.image import MIMEImage | |
from email.mime.application import MIMEApplication |
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
#! /usr/bin/env python | |
import threading | |
import subprocess | |
import traceback | |
import shlex | |
class Command(object): | |
""" | |
Enables to run subprocess commands in a different thread with TIMEOUT option. |
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://leetcode.com/problems/implement-trie-prefix-tree/ | |
// Implement a trie with insert, search, and startsWith methods. | |
// | |
// Note: | |
// You may assume that all inputs are consist of lowercase letters a-z. | |
class TrieNode { | |
private: | |
char ch; | |
std::map<char, TrieNode *> next; |
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
// Refer to: https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/ | |
bool dfs_node(TreeNode * root, TreeNode * node, std::vector<TreeNode *> & path) { | |
if (!root) { | |
return false; | |
} | |
path.push_back(root); | |
if (root == node) { |
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
#include <sstream> | |
template < typename _Ty > | |
_Ty convert_str(const std::string & str) { | |
_Ty ret = _Ty(); | |
std::stringstream ss; | |
ss << str; | |
ss >> ret; | |
return ret; | |
} |
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
std::vector<std::string> split_str(std::string & str, const char sep = ' ') { | |
std::vector<std::string> strs; | |
size_t pos = 0; | |
while (pos != (size_t)(-1)) { | |
pos = str.find_first_of(sep); | |
strs.push_back(str.substr(0, pos)); | |
str = str.substr(pos+1); | |
} |
NewerOlder