Get current date and time in Python
import datetime now = datetime.datetime.now() print print "Current date and time using str method of datetime object:" print str(now) print print "Current date and time using instance attributes:" print "Current year: %d" % now.year print "Current month: %d" % now.month print "Current day: %d" % now.day print "Current hour: %d" % now.hour print "Current minute: %d" % now.minute print "Current second: %d" % now.second print "Current microsecond: %d" % now.microsecond print print "Current date and time using strftime:" print now.strftime("%Y-%m-%d %H:%M") print print "Current date and time using isoformat:" print now.isoformat()
Results:
Current date and time using str method of datetime object: 2014-09-26 16:34:40.278298 Current date and time using instance attributes: Current year: 2014 Current month: 9 Current day: 26 Current hour: 16 Current minute: 34 Current second: 40 Current microsecond: 278298 Current date and time using strftime: 2014-09-26 16:34 Current date and time using isoformat: 2014-09-26T16:34:40.278298
References :
http://www.saltycrane.com/blog/2008/06/how-to-get-current-date-and-time-in/
Subtract time in Python
import datetime print datetime.datetime.now() print datetime.datetime.now() - datetime.timedelta(minutes=2) print datetime.datetime.now() - datetime.timedelta(seconds=10) print datetime.datetime.now() - datetime.timedelta(milliseconds=400)
el@dev ~ $ python test.py 2014-11-26 06:47:07.179411 2014-11-26 06:45:07.179538 2014-11-26 06:46:57.179581 2014-11-26 06:47:06.779614
References
http://stackoverflow.com/questions/13897246/python-time-subtraction
Setup a static IP in Ubuntu
open /etc/network/interfaces with editor
auto eth0 #iface eth0 inet dhcp iface eth0 inet static address 192.168.56.101 netmask 255.255.255.0 gateway 192.168.56.1
and then
service networking restart
JSON encoder and decoder in Python
json.JSONDecoder
JSON | Python |
---|---|
object | dict |
array | list |
string | str |
number (int) | int |
number (real) | float |
true | True |
false | False |
null | None |
json.JSONEncoder
Python | JSON |
---|---|
dict | object |
list, tuple | array |
str | string |
int, float, int- & float-derived Enums | number |
True | true |
False | false |
None | null |
Source :
axel
bash script for downloading with axel
#!/bin/bash axel -a -n32 link sleep 10 axel -a -n32 link sleep 10 axel -a -n32 link sleep 10 axel -a -n32 link
Cisco cheat sheet 1
#1: The “?”
#2: show running-configuration
#3: copy running-configuration startup-configuration
#4: show interface
#5: show ip interface
#6: config terminal, enable, interface, and router
example :
configure terminal interface fastEthernet 0/0 ip address 10.0.0.1 255.0.0.0 no shutdow exit
#7: no shutdown
#8: show ip route
#9: show version
#10: debug
sudo
Description :
execute a command as another user
Examples :
sudo -i
get super user shell
Trash
locations :
~/.local/share/Trash