Skip to content

Instantly share code, notes, and snippets.

@alexzhan
alexzhan / find and delete command
Created November 15, 2010 06:52
linux find command
find command:http://www.oreillynet.com/linux/cmd/cmd.csp?path=f/find
find . -maxdepth 1/2/..../n
%to just find them and printout:
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n'
%delete them, may be modified to use
find . -maxdepth 1 -name '[!.]*' -size 0 -printf 'Name: %16f Size: %6s\n' | xargs rm
http://content.hccfl.edu/pollock/unix/findcmd.htm
@alexzhan
alexzhan / pdfcrop.py
Created October 7, 2011 12:53 — forked from laogao/pdfcrop.py
Use pyPdf to crop a pdf file according to user inputs
#!/usr/bin/env python
import sys
if __name__ == '__main__' and len(sys.argv) > 5 and sys.argv[1][-3:].upper() == 'PDF':
original = sys.argv[1]
target = original[:-4] + '.cropped.pdf'
left = int(sys.argv[2])
top = int(sys.argv[3])
right = int(sys.argv[4])
# -*- 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
@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...');
@alexzhan
alexzhan / textdiff.py
Created May 5, 2012 09:11
Find the differences between two pieces of TEXT.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
textdiff.py
Original is (C) Ian Bicking <ianb@colorstudy.com>
With changes from Richard Cyganiak <richard@cyganiak.de> and Richard Cyganiak <richard@cyganiak.de>
Modified from https://github.com/cygri/htmldiff/blob/master/htmldiff
Finds the differences between two pieces of TEXT.