Skip to content

Instantly share code, notes, and snippets.

# -*- coding: UTF-8 -*-
# !/usr/bin/python
# read content from the html file
file = open('/Users/marco/PycharmProjects/StyleReplace/wechat.html' ,'r')
str = file.read()
# replace head 2 label
h2Start = '''<p style="line-height: 25.6px; max-width: 100%; min-height: 1em; white-space: pre-wrap; color: rgb(62, 62, 62); background-color: rgb(255, 255, 255); box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="max-width: 100%; color: rgb(41, 148, 128); line-height: 25.6px; box-sizing: border-box !important; word-wrap: break-word !important;"></strong></p>
<p style="max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important;"><strong style="max-width: 100%; color: rgb(41, 148, 128); line-height: 25.6px; box-sizing: border-box !important; word-wrap: break-word !important;"><span style="max-width: 100%; font-size: 24px; box-sizing: border-box !important; word-wrap: break-word !important;"> ''';
@alexzhan
alexzhan / disk-usage.py
Last active November 13, 2016 07:27
A python snippet to figure out disk usage
import os
from collections import namedtuple
disk_ntuple = namedtuple('partition', 'device mountpoint fstype')
usage_ntuple = namedtuple('usage', 'total used free percent')
def disk_partitions(all=False):
"""Return all mountd partitions as a nameduple.
If all == False return phyisical partitions only.
"""
@alexzhan
alexzhan / vim74centos
Created July 12, 2016 14:01 — forked from juxtin/vim74centos
Compile Vim 7.4 on Centos and install my vimrc
#!/bin/bash
yum groupinstall 'Development tools' -y
yum install ncurses ncurses-devel wget git -y
cd /usr/local/src
wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
tar -xjf vim-7.4.tar.bz2
cd vim74
./configure --prefix=/usr --with-features=huge --enable-rubyinterp --enable-pythoninterp
make && make install
import os
import string
RCV_LOG = r"/path/to/xxx.log"
def get_last_n_lines(logfile, n):
n = string.atoi(n)
blk_size_max = 4096
n_lines = []
with open(logfile, 'rb') as fp:
@alexzhan
alexzhan / url_encode_characters
Created August 5, 2015 15:23
URL Encode Characters
backspace %08
tab %09
linefeed %0A
creturn %0D
space %20
! %21
" %22
# %23
$ %24
% %25
@alexzhan
alexzhan / get_login_addr.py
Created June 18, 2015 07:26
get mail login address by email address
def get_login_addr(email):
main_addr = email.split('@')[-1]
if 'mail' in main_addr: return main_addr
else: return 'mail.' + main_addr
@alexzhan
alexzhan / drop_tests.sh
Last active December 26, 2015 18:29
drop many databases prefixed with 'test_'
#!/bin/bash
#originated from http://stackoverflow.com/questions/5457286/drop-multiple-databases
#firstly you should use mysql_config_editor to set up a "login path" which the mysql command line client can then use.
#http://architects.dzone.com/articles/passwordless-command-line
DB_STARTS_WITH="test_"
MYSQL="mysql"
DBS="$($MYSQL --login-path=restore -Bse 'show databases')"
<?php
class Foo {
function myFoo() {
return $this->myBar();
}
function myBar() {
return "Foo";
}
}
<?php
class Foo {
function myFoo() {
return $this->myBar();
}
function myBar() {
return "Foo";
}
}
<?php
/*
* The lesson from this example is in the output
* rather than the PHP code itself.
*/
$magnitude_lower = pow(2, (PHP_INT_SIZE * 8) - 2);
p($magnitude_lower - 1);
p($magnitude_lower, 'See the rollover? Watch it next time around...');