JavaScript随机打乱数组function Shuffle(o) { for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); return o;};使用方法var testArray = ……继续阅读 »  5年前 (2020-11-18)  1322浏览  2050个赞
   Python遍历字符串中的每一个字符直接用for 语句#遍历字符串a = 'asd'for q in a: print(q)# 输出结果为asd ……继续阅读 »  5年前 (2020-11-16)  2918浏览  953个赞
   python旋转图片的代码# rotate an image counter-clockwise using the PIL image library# free from: http://www.pythonware.com/products/pil/index.htm# make sure to install PIL after your……继续阅读 »  5年前 (2020-11-16)  1425浏览  2470个赞
   python 计算字符串长度,一个中文算两个字符,先转换成utf8,然后通过计算utf8的长度和len函数取得的长度,进行对比即可知道字符串内中文字符的数量,自然就可以计算出字符串的长度了。来源:http://www.75271.comvalue=u'脚本12'length = len(value)utf8_length = ……继续阅读 »  5年前 (2020-11-16)  2504浏览  1524个赞
   python从网络端口读取文本数据# To test it with netcat, start the script and execute:# # echo "Hello, cat." | ncat.exe 127.0.0.1 12345#import socketHOST = 'localhos……继续阅读 »  5年前 (2020-11-16)  2693浏览  1514个赞
   windows下通过批处理获得本机mac地址@ECHO OFF:: Check OS versionIF NOT "%OS%"=="Windows_NT" GOTO SyntaxSETLOCAL:: Check command line argumentsIF NOT "%~2"……继续阅读 »  5年前 (2020-11-16)  2128浏览  2658个赞
   转自:http://blog.csdn.net/marising/article/details/6551692在很久以前,我写了一个系列,Python和C和C++的交互,如下http://blog.csdn.net/marising/archive/2008/08/28/2845339.aspx目的是解决Python和C/C++的互操作性的问题,假如……继续阅读 »  5年前 (2020-11-16)  2002浏览  798个赞
   回文,亦称回环,是正读反读都能读通的句子,亦有将文字排列成圆圈者,是一种修辞方式和文字游戏。下面的代码用于检测一个字符串是否是回文/**检测回文串: * 先判断该字符的第一个和最后一个字符是否相等。如果相等,检查第二个字符和倒数第二个字符 * 是否相等。这个过程继续进行,直到出现不配陪的情况或者字符串的所有字符都检验完了。当字 ……继续阅读 »  5年前 (2020-11-16)  1918浏览  1087个赞
   python显示生日是星期几# find the day of the week of a given date# Python will trap impossible dates like (1900, 2, 29)# tested with Python24 vegaseat 01aug2005from datetime i……继续阅读 »  5年前 (2020-11-16)  1615浏览  218个赞
   python比较两段文本的不同之处# find the difference between two texts# tested with Python24 vegaseat 6/2/2005import difflibtext1 = """The World's Shortest Books:……继续阅读 »  5年前 (2020-11-16)  1345浏览  2265个赞
   C++通过递归进行回文判断#include   using namespace std;  //将一整数逆序后放入一数组中(要求递归实现)  int IsRound(char *str,int len)  {  if(*str==*(str+len-1))  return IsRound(str+1,len-2);  if(le……继续阅读 »  5年前 (2020-11-16)  2795浏览  2118个赞
   python获取一组汉字拼音的首字母来源:http://wangwei007.blog.51cto.com/68019/983289作者:lover007#!/usr/bin/env python # -*- coding: utf-8 -*- def multi_get_letter(str_input): if ……继续阅读 »  5年前 (2020-11-13)  1528浏览  621个赞
   python监控本机cpu的利用百分比情况import wmiimport timec = wmi.WMI()while True: for cpu in c.Win32_Processor(): timestamp = time.strftime('%a, %d %b %Y %H:%M:%S',……继续阅读 »  5年前 (2020-11-13)  1977浏览  421个赞
   python自动连接ssh的代码#!/usr/bin/python#-*- coding:utf-8 -*-import sys, time, ostry: import pexpectexcept ImportError: print """ You must insta……继续阅读 »  5年前 (2020-11-13)  2240浏览  1377个赞
   下面这段代码意思是,如果b为None则c等于a,否则c=b,用python写起来就容易多了a=100b=50c=a if b is None else bprint(c)#输出结果为50,这段代码相当于if b is None: c = aelse: c = b ……继续阅读 »  5年前 (2020-11-13)  3151浏览  1945个赞
   想sqlite插入一条记录后,马上获得自动生成的id编号的方法connection=sqlite3.connect(':memory:')cursor=connection.cursor()cursor.execute('''CREATE TABLE foo (id integer primary ……继续阅读 »  5年前 (2020-11-13)  2120浏览  973个赞
   JavaScript判断浏览器是否是IEvar isMSIE = /*@cc_on!@*/0;if (isMSIE) { // do IE-specific things} else { // do non IE-specific things} ……继续阅读 »  5年前 (2020-11-06)  3730浏览  2157个赞
   JavaScript不要在for循环语句里使用计算表达式和函数//慢for(var i = 0; i < my_array.length; i++)//也很慢for(var i = 0; i < myMethod(); i++)//快var length = my_array.length;for(var i = 0; ……继续阅读 »  5年前 (2020-11-06)  2033浏览  2825个赞
   一段简单的js代码,让浏览器自动点击按钮<script type="text/javascript"> function init(){ document.getElementById('button1').click(); } onl……继续阅读 »  5年前 (2020-11-06)  3485浏览  244个赞
   此代码主要是为了演示如何通过按钮来更新grid的数据import wx, wx.gridclass GridData(wx.grid.PyGridTableBase): _cols = "a b c".split() _data = [ "1 2 3".split(), ……继续阅读 »  6年前 (2020-04-13)  1699浏览  2456个赞
   在python脚本内运行linux命令#/usr/bin/env pythonimport subprocessclass RunCmd(object): def cmd_run(self, cmd): self.cmd = cmd subprocess.call(self.cmd, shell=Tru……继续阅读 »  6年前 (2019-09-03)  2425浏览  361个赞
   Python输出两个字符串中相同的字符,计算两个字符串的交集import setsmagic_chars = sets.Set('abracadabra')poppins_chars = sets.Set('supercalifragilisticexpialidocious')print '&……继续阅读 »  6年前 (2019-09-03)  2324浏览  1088个赞
   python提供了非常方便的日志模块#-*- coding:utf-8 -*-import logging# 配置日志信息logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(name)-12s %(levelname)-……继续阅读 »  6年前 (2019-09-03)  2293浏览  206个赞
   split(string[, maxsplit]) | re.split(pattern, string[, maxsplit]):按照能够匹配的子串将string分割后返回列表。maxsplit用于指定最大分割次数,不指定将全部分割。import re p = re.compile(r'\d+')print p.spli……继续阅读 »  6年前 (2019-09-03)  1281浏览  1465个赞
   python 中map函数使用范例代码# build a dictionary that maps the ordinals from 32 to 255# to their ASCII character equivalents eg. 33: '!'# (note that 32 and 160 are spaces)……继续阅读 »  6年前 (2019-09-03)  1845浏览  2974个赞
   python统计文本文件内单词数量# count lines, sentences, and words of a text file# set all the counters to zerolines, blanklines, sentences, words = 0, 0, 0, 0print '-' * 50tr……继续阅读 »  6年前 (2019-09-03)  2544浏览  2565个赞
   Go语言获取数组长度// getting the length of an array is silly, because the length is part of the array's static typemyArray := [3]int{1, 2, 3}fmt.Println(len(myArray)) // prints 3……继续阅读 »  6年前 (2019-09-03)  2252浏览  2903个赞
   Go语言排序与接口代码演示import "fmt"type Sorter interface { Len() int Less(i, j int) bool Swap(i, j int)}type Xi []inttype Xs []stringfunc (p Xi) Len() int { ……继续阅读 »  6年前 (2019-09-03)  1349浏览  2744个赞
   Go语言写入字符串到文件代码package main import "fmt"import "os"func main() { fileName := "test.dat" dstFile,err := os.Create(fileName) if err!=nil……继续阅读 »  6年前 (2019-09-03)  2215浏览  820个赞
   go语言里使用scp的范例// https://blogs.oracle.com/janp/entry/how_the_scp_protocol_workspackage mainimport ( "code.google.com/p/go.crypto/ssh" "crypto" &q……继续阅读 »  6年前 (2019-09-03)  1883浏览  2431个赞
   本范例演示了JS中如何通过String.prototype自定义字符串操作协议,本代码定义了两个操作方法,一个用于清除html标签,一个用来转换html标签,都非常有用String.prototype.stripslashes = function(){ return this.replace(/<.*?>/g, '……继续阅读 »  6年前 (2019-09-03)  1630浏览  1399个赞
   python计算数组、元祖等列表元素的和print( sum([1,2,3])) 返回值:6……继续阅读 »  6年前 (2019-08-08)  3390浏览  482个赞
   python遍历字符串中的字符word = raw_input("Enter a word: ")print "\nHere's each letter in your word:"for letter in word: print letter……继续阅读 »  6年前 (2019-08-08)  2344浏览  2855个赞
   def isAString(anobj):return isinstance(anobj, basestring)def isAString(anobj): return isinstance(anobj, basestring)……继续阅读 »  6年前 (2019-08-08)  2818浏览  1592个赞
   multipart/form-data类型的POST实体结构相对来说(常规的POST正文采用application/x-www-form-urlencoded格式)比较复杂,它常用于文件上传。下面是一个multipart/form-data格式的POST实体示例-----------------------------114782935826962 ……继续阅读 »  6年前 (2019-08-08)  2307浏览  413个赞
   python写日志的封装类# encoding:utf-8import sysimport loggingimport time def writeLog(message): logger=logging.getLogger() filename = time.strftime('%Y-%m-%d'……继续阅读 »  6年前 (2019-08-08)  2798浏览  2341个赞
   python链接Oracle数据库的代码,需要引用cx_Oracle库#coding=UTF-8 import cx_Oracle def hello(): '''Hello cx_Oracle示例: 1)打印数据库版本信息. 2)查询表数据.'……继续阅读 »  6年前 (2019-08-08)  2207浏览  1051个赞
   python 给目录下的图片批量加水印water.py 放到 图片文件夹里 然后cd 到当前文件夹 python water.py#coding=utf-8import Imageimport os#print list[0]#exit()def getlogo(x1,y1): im =Image.open("./&qu……继续阅读 »  6年前 (2019-08-08)  2373浏览  2064个赞
   python正则查找所有匹配的字符串import re p = re.compile(r'\d+')print p.findall('one1two2three3four4') ### output #### ['1', '2', '3……继续阅读 »  6年前 (2019-08-08)  2904浏览  2244个赞
   python zip和unzip数据# zipping and unzipping a string using the zlib module# a very large string could be zipped and saved to a file speeding up file writing time # and later rel……继续阅读 »  6年前 (2019-08-08)  1937浏览  278个赞
   wxpython GUI界面显示jpg图片# show a jpeg (.jpg) image using wxPython, newer coding style# two different ways to load and display are given# tested with Python24 and wxPython25 veg……继续阅读 »  6年前 (2019-08-08)  2093浏览  2421个赞
   python将文本转换成语音# Text To Speech using SAPI (Windows) and Python module pyTTS by Peter Parente# download installer file pyTTS-3.0.win32-py2.4.exe # from: http://sourceforge.ne……继续阅读 »  6年前 (2019-08-08)  2151浏览  320个赞
   由于Python设计的限制(我说的是咱们常用的CPython)。最多只能用满1个CPU核心。Python提供了非常好用的多进程包multiprocessing,你只需要定义一个函数,Python会替你完成其他所有事情。借助这个包,可以轻松完成从单进程到并发执行的转换。1、新建单一进程如果我们新建少量进程,可以如下:import multiproces……继续阅读 »  6年前 (2019-08-08)  1531浏览  2084个赞
   在2.6才开始使用multiprocessing 是一个使用方法类似threading模块的进程模块。允许程序员做并行开发。并且可以在UNIX和Windows下运行。通过创建一个Process 类型并且通过调用call()方法spawn一个进程。下面是该模块的一个测试程序。效果非常好#!/usr/bin/env python#coding=utf-……继续阅读 »  6年前 (2019-08-08)  1759浏览  629个赞
   python subprocess模块 监控子进程的2种方式 忙等待和立即返回同时设置子进程超时时间一:循环 忙等 子进程结束import subprocess import os import time tt = '555' cmd = "python /home/1……继续阅读 »  6年前 (2019-08-08)  1505浏览  614个赞