Archives 2016

jquery grep(),inArray(), map() and join() in javascript

1.jquery grep(): Filtered through an array

   eg.
       var array = [1,2,3,4,5,6,7,8,9];
       var filterarray = $.grep(array,function(value){
           return value > 5;//filter out of more than 5
       });
       for(var i=0;i<filterarray.length;i++){
           alert(filterarray[i]);
       }
       for (key in filterarray){
           alert(filterarray[key]);
       }

2.jquery inArray ...

Continue reading

Python list

Python list

a.Method for creating a list

     1.create list
     eg.
        >>> a=["python",25,89.9]
        >>> a
        ["python",25,89.9]
     2.list index   
     eg.
        >>> a=["python",25,89.9]
        >>> a[0]
        'python'
        >>> a[1]
        25
        >>> a[2]
        89.9
        >>> a[-1]
        89.9
        #get the index ...

Continue reading

Between the characters and numbers in Python is how to compare the size?

Between the characters and numbers in Python is how to compare the size?

1. any two objects can be compared

2. The same type of objects (instances), if it is digital type (int/float/long/complex), in accordance with the simple size to compare; if is non numeric type and class (type) definition of the ...

Continue reading

Python set

1.Method for creating a set

 1)s={1,"python"}
 2)s=set("python") or s=set([1,"python"])
   ps. set to list: 
                   lst=list(s)
       list to set(can remove duplicate elements from the set):
                   s=set([1,"python"])  
       Create an immutable set in "frozenset"

2.Common method of set

 1)add 
    eg.
    b ...

Continue reading

Implementation of Case Swithch syntax in Python

Python itself has no switch statement, there are 3 kinds of Solutions:

1.use dictionary

cases = {
           case1: do_some_stuff1,
           case2: do_some_stuff2,
           ...
           caseN: do_some_stuffN,
         }
cases.get(var, do_default_stuff)()

2.use lambda

result = {
  'a': lambda x: x * 5,
  'b': lambda x: x + 7,
  'c': lambda x: x - 2
}[value](x)

3.Beck Brian provides a class switch to ...

Continue reading

Python basic usage of pickle

Python pickle

import pickle

#dumps(object) :Object serialization
lista=["john","levi","kate"]
listb=pickle.dumps(lista)
#print listb

#loads(string) :The object is restored, and the object type is restored to the original format.
listc=pickle.loads(listb)
#print listc

#dump(object,file) :To store objects in a file.
group1=("cat","is","kkkk")
f1=file ...

Continue reading

Python basic grammar

python basic grammar

1.Constant and Variable

   1)Constant
    eg.
      import const
      const.value=5
      print const.value
      const.value=6
   2)Variable
     eg.
        a=1

2.Number and string

   1)Single quotation mark
     eg. a='string'
   2)Double quotation marks
     eg. b="string"
   3)Three single quotation marks (output special characters)
     eg. c='''string ...

Continue reading

Python read and write files

Python read and write file

1.Python read and write file

fr=open("readfile.txt","r")  
fw=open("writefile.txt","w")

print fr.readline()  
print fr.tell()

print fr.readlines()  
fw.write("===write line===")  
fw.close()

fr.seek(0,0) #The first parameter represents the number of bytes, after which a parameter represents the relative ...

Continue reading

Python randomly generated a 6 bit verification code

source code:

# -*- coding: utf-8 -*-
import random
def generate_verification_code():
    ''' randomly generated a 6 bit verification code '''
    code_list = []
    for i in range(10): # 0-9 number
        code_list.append(str(i))
    for i in range(65, 91): # A-Z
        code_list.append(chr(i))
    for i in range(97, 123): # a-z
        code_list.append(chr(i))
    myslice = random.sample(code_list, 6)  
    verification_code ...

Continue reading

Linux systemctl is the replacement for service and chkconfig

1.Enable a service to start automatically

1) chkconfig --level 3 SERVICENAME on (old command)    
2) systemctl enable SERVICENAME.service (new command)

2.Disable a service to start automatically

1) chkconfig --level 3 SERVICENAME off (old command)    
2) systemctl disable SERVICENAME.service (new command)

3.View service status(old command and old command)

1) service ...

Continue reading

Monthly archives

Previous year

2015

Next year

2020