Skip to content

Instantly share code, notes, and snippets.

View iziang's full-sized avatar

Ziang Guo iziang

View GitHub Profile
@iziang
iziang / second_max_number.cc
Last active January 2, 2016 11:29
从前向后遍历数组,每一个元素都先和max比较 (1)如果大于max,则更新max和second_max (2)如果小于max,再和second_max比较,如果大于second_max,则更新second_max
#include<stdio.h>
int second_max_length(int array[], const int length, int &second_max)
{
if((array == NULL) || (length < 2)){
return 0;
}
int i;
@iziang
iziang / ls.c
Last active January 3, 2016 00:39
指针一定要初始化,给其分配指向的内存地址!!!!!
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
if (argc != 2) {
#include <stdio.h>
typedef enum {
ST_RADIO,
ST_CD
} STATES;
typedef enum {
EVT_MODE,
EVT_NEXT
#统计C文件和Python文件中有效代码行数
#Python文件中空行,以"#"开头的注释行,不在统计之列
#C文件中空行,以"//"开头的注释行,以"/* comment*/"包围的注释块,不再统计之列
import os
import re
from sys import argv
filename, name= argv
blank_line =re.compile(r"^ *$")
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@iziang
iziang / gen_passwd.sh
Last active August 29, 2015 14:00
生成随机的密码,支持长度自定义
#Version 1
read -p "please input the length of passwd: " p
list=(0 1 2 3 4 5 6 7 8 9 a b c d A B C D + -)
for i in $(seq $p); do
echo -n ${list[$RANDOM % ${#list[*]}]}
done
@iziang
iziang / char_most_start_with.sh
Last active August 29, 2015 14:01
找出以哪个英文字母开头的单词最多
awk -vFS="" '{a[$1]++}END{for (i in a) if(match(i,/[a-z]/)) {b[i]=a[i]+a[toupper(i)];print i","b[i]}}' /usr/share/dict/words|sort -t "," -nrk 2
@iziang
iziang / find_max_file_in_dir.sh
Last active August 29, 2015 14:01
找出一个文件夹中最大的文件,包括子目录中的文件
find . -type f -exec stat -c "%s %n" {} \;|sort -n|tail -n 1
#从列表的特定位置迭代,比如从第五项迭代到末尾,可以用下面的方法,当然也可以把列表从指定位置分片后再迭代
for i in list_inst[4:]:
process
#可以对可迭代对象进行解包操作,类似于下面这样的形式,只要两边的参数个数匹配即可
m = [1, 2, 3]
p, q, r = m
#自定义异常类的定义,触发,处理
#!/usr/bin/python
@iziang
iziang / php_export_excel.php
Last active August 29, 2015 14:04
PHP把MySQL中检索出的数据导出到EXCEL
<?php
/*******EDIT LINES 3-8*******/
$DB_Server = "localhost"; //MySQL Server
$DB_Username = "username"; //MySQL Username
$DB_Password = "password"; //MySQL Password
$DB_DBName = "databasename"; //MySQL Database Name
$DB_TBLName = "tablename"; //MySQL Table Name
$filename = "excelfilename"; //File Name
/*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/
//create MySQL connection