使用php独有的array_map函数遍历清除数组中所有字符串的两端空格/** * Trims a entire array recursivly. * * @author Jonas John * @version 0.2 * @link http://www.jonasjohn.de/snippets/p……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2581浏览 0评论2223个赞
交换两个变量的值在所有语言中都是最基础的算法,一般都需要一个临时变量,此php代码只用一行实现这个功能,虽然代码只有一行,但是php内部做的工作应该一点也不少list($a,$b) = array($b,$a);……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3091浏览 0评论2898个赞
一个自定义的php数组元素随机调换的函数,php已经有一个内置的同样功能的函数shuffle($Array),这个代码权当参考// I noticed that there is already a built-in function that// does the same - so don't use mine ;-)//// --……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2682浏览 0评论1619个赞
这个php函数用来删除文件中的重复行,还可以指定是否忽略大小写,和指定换行符/** * RemoveDuplicatedLines * This function removes all duplicated lines of the given text file. * * @param string * @param bo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2652浏览 0评论144个赞
删除数组里的所有空值元素,包含空字符串,空的数组等等function array_remove_empty($arr){ $narr = array(); while(list($key, $val) = each($arr)){ if (is_array($val)){ $val = array……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2019浏览 0评论479个赞
一个php操作mysql数据库的类<?php /** * Database class * * @version: 2.2 * @author: Emil T. Kampp <emil@kampp-productions.dk> * @revised: 27 may 2007 * **/ class Data……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2634浏览 0评论968个赞
php计算两个坐标(经度,纬度)之间的距离,返回结果为米或者千米function distance($lat1, $lng1, $lat2, $lng2, $miles = true){ $pi80 = M_PI / 180; $lat1 *= $pi80; $lng1 *= $pi80; $lat2 *= $pi80; $lng2 *= ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3368浏览 0评论204个赞
一个php编写的xml分析类************************************************************************Example:************************************************************************ $xml……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3213浏览 0评论1073个赞
php获得用户的真实ip函数function getRealIpAddr(){if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet{ $ip=$_SERVER['HTTP_CLIENT_IP'];}elseif (……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2392浏览 0评论173个赞
这是一个用于登录的php类,包含了数据库调用,写入cookieclass Auth{ var $user_id; var $username; var $password; var $ok; var $salt = "34asdf34"; var $domain = ".domain.com"; ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3064浏览 0评论2922个赞
Python生成不重复随机数的简单方法print random.sample(from,to) 例如:生成1-100之间的不重复随机数random.sample(1,100)……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1879浏览 2339个赞
python中字符串自带的split方法一次只能使用一个字符对字符串进行分割,但是python的正则模块则可以实现多个字符分割import rere.split('-|_','sharejs_haotu-icon100') 输出结果如下……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2998浏览 2101个赞
这段python代码对xapian的部分操作进行了简单的封装,希望对大家有用。import xapian, configfrom mmseg.search import seg_txt_2_dictclass Xapian(): """xapian search class """……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2687浏览 1321个赞
xapian创建索引和搜索的简单范例程序,代码使用python实现 创建索引代码import sysimport osimport errnofrom contextlib import closingimport xapian as _xdef main(file……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2295浏览 770个赞
这是一段简单的python代码,用户转换不同单位的温度,适合初学者参考6061626364656667686970717273747576def c2f(t): return (t*9/5.0)+32def c2k(t): return t+273.15def f2c(t): return (t-32)……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2534浏览 897个赞
python编写的超简单端口转发程序代码非常简单,实现了简单的端口数据转发功能,用于真实环境还需要再修改一下。转自:http://blog.csdn.net/qffhq#tcp server import socket host = '127.0.0.1' #Local Server IP h……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2512浏览 2771个赞
xapian 通过python创建索引数据库的复杂一些的范例除了包含索引字符串外,还为索引添加了两个值#!/usr/bin/env python## Index each paragraph of a text file as a Xapian document.# Include some values that will be of use……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2198浏览 1015个赞
这段代码需要调用serial模块,通过while循环不断读取串口数据转自:http://www.yelinsky.com/import timeimport serialser = serial.Serial( #下面这些参数根据情况修改 port='COM1', baudrate=9600, par……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1809浏览 1381个赞
python通过BF算法实现关键词匹配作者:smalltt#!/usr/bin/python# -*- coding: UTF-8# filename BFimport time"""t="this is a big apple,this is a big apple,this is a big ap……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3185浏览 1576个赞
python利用asyncore的端口映射(端口转发)可以实现端口数据的转发,效果还是不错的代码转自:http://www.cnblogs.com/nethirteimport socket,asyncoreclass forwarder(asyncore.dispatcher): def __init__(self, ip, port……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2810浏览 1353个赞
python读写文件方法汇总转自:http://blog.csdn.net/adupt/archive/2009/08/11/4435615.aspx 1.open使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2017浏览 330个赞
python getaddrinfo() 基本使用代码import sys, socketresult = socket.getaddrinfo("192.1.1.100", None)print result[0][4]print result 输出结……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1846浏览 862个赞
这段代码可以生成5个不同的随机字母组成的长度为8的字符串import random, string for c in range(5): print random.sample(string.letters+string.digits, 8)……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3152浏览 2384个赞
python实现一个简单的基于SSL的 IRC bot的代码#!/usr/bin/python# -*- coding: utf8 -*- import socket, string, time, sslimport urllib, re network = 'irc.server.net'nick = 'n……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1861浏览 2330个赞
使用urllib和正则抓取和分析网页的简单代码片段import urllib, re url = 'http://www.viedemerde.fr/aleatoire'page = urllib.urlopen(url).read()parse = re.findall("\<div class=\&quo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2993浏览 2542个赞
python编写的简单RPG游戏流程代码#RPGrpg = Truewhp = 100mahp = 100hhp = 100MHP = 10 def dgrnd () : wa = raw_input ("What does Warrior do?") ma = raw_input ("Wha……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2902浏览 202个赞
将代码生成.py文件放在目录下运行,可以获取该目录的所有mp3文件的信息,需要使用ID3库import os, sysfrom ID3 import * files = os.listdir(os.getcwd()) for f in files: x = os.path.splitext(f) if x[1] == ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1498浏览 2439个赞
python将html表格转换成CSV使用方法:python html2csv.py *.html这段代码使用了 HTMLParser 模块#!/usr/bin/python# -*- coding: iso-8859-1 -*-# Hello, this program is written in Python - http://python.o……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3525浏览 295个赞
python根据主机名字获得所有ip地址# -*- coding: utf-8 -*-import sys, socketresult = socket.getaddrinfo('www.google.com', None, 0, socket.SOCK_STREAM)counter = 0for item in resul……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2870浏览 2136个赞
一个简单python ftp客户端代码#!/usr/bin/python# -*- coding: utf-8 -*-import ftplibimport osimport socketHOST = 'ftp.mozilla.org'DIRN = 'pub/mozilla.org/webtools'……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1856浏览 1982个赞
一段简单的python邮件客户端发送代码#/usr/bin/python# -*- coding: utf-8 -*-import reimport smtplibfrom poplib import POP3from email.mime.text import MIMETextdef sevname(username): pa ……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1490浏览 791个赞
python实现自动登录人人网并采集信息的代码#!/usr/bin/python# -*- coding: utf-8 -*-import sysimport reimport urllib2import urllibimport cookielibclass Renren(object): def __init__(se……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3240浏览 798个赞
python代码用于查找指定具有相同内容的文件,可以同时指定多个目录调用方式:python doublesdetector.py c:\;d:\;e:\ > doubles.txt# Hello, this script is written in Python - http://www.75271.com# doublesdetector.py 1……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2956浏览 130个赞
python Gevent multiprocessing serverimport sysfrom gevent import serverfrom gevent.baseserver import _tcp_listenerfrom gevent.monkey import patch_all; patch_all()from multi……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1737浏览 1691个赞
一个使用进程内通讯的python聊天室代码,非常简单的服务端和客户端代码#!/usr/bin/env python# Added by <ctang@redhat.com>import sysimport osfrom multiprocessing import connectionADDR = ('', 9……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2558浏览 2500个赞
这段代码可以对指定的目录进行扫描,包含子目录,对指定扩展名的文件进行SHA-1加密后存储在cvs文件,以防止文件被篡改调用方法:python snapper.py > todayCheck.csv# Hello, this is a script written in Python. See http://www.pyhon.org## Snapp……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2658浏览 2474个赞
我用这段代码来压缩数据库备份文件,没有使用python内置的zip模块,而是使用了zip.exe文件# Hello, this script is written in Python - http://www.75271.com## autozip.py 1.0p## This script will scan a directory (and……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1752浏览 1282个赞
这段python可以用来读取新闻组内的新闻,并保存为纯文本文件# Hello, this script is written in Python - http://www.75271.com## newsarchiver 1.1p - Newsgroup archiver## Purpose:# This script will dow……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2703浏览 2136个赞
python打印ASCII编码字符代码i = 0while i < 256: print chr(i), if i != 0 and i % 8 == 0 : print i = i + 1……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3731浏览 2791个赞
python实现的矩阵乘法def matrixMul(A, B): res = [[0] * len(B[0]) for i in range(len(A))] for i in range(len(A)): for j in range(len(B[0])): for k in range(le……继续阅读 » 水墨上仙 6年前 (2021-01-15) 3435浏览 1474个赞
There is always room for optimizing primelist functions. Here is an assortment timed with Python module timeit …'''primelist_timing1.pytiming some very fas……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2492浏览 1720个赞
This snippet allows one to implement an equivalent of a __getattr__() function in a python module. The module can then define its own way to lazily import abitrary symbols. For exa……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2498浏览 2228个赞
python从任意文件读取邮件地址输出,包括html、txt甚至exe文件调用方法:python email_extractor.py < PythonFAQ.html# Hello, this script is written in Python - http://www.75271.com# Script written by Sebastie……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2228浏览 1526个赞
python 操作 ssh#coding:utf-8""" ssh操作例子 实现了服务器日志下载 2012-08-24 yywolf"""import paramikoimport timehostname="????"port=22u……继续阅读 » 水墨上仙 6年前 (2021-01-15) 2866浏览 2031个赞
python统计cpu的利用率#-*-coding=utf-8-*-import win32pdhimport time# Counter pathsPROCESSOR_PERCENT = r'\Processor(_Total)\% Processor Time'MEMORY_PERCENT = r'\Memo……继续阅读 » 水墨上仙 6年前 (2021-01-15) 1956浏览 886个赞