This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>gd.wa</groupId> | |
<artifactId>minimal-pom</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<packaging>jar</packaging> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
current_time = time.time() # current time in seconds since the Epoch | |
print current_time | |
date = "201602251430" | |
time_tuple = time.strptime(date, "%Y%m%d%H%M") # parse date string using a specific format | |
print time_tuple | |
date_in_seconds = time.mktime(time_tuple) # convert time tuple to seconds from Epoch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
# Subclass TestCase class | |
class TestUM(unittest.TestCase): | |
# Execute code prior to unit tests being run | |
def setUp(self): | |
pass | |
# create unit tests using assert methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<data> | |
<country name="Liechtenstein"> | |
<rank>1</rank> | |
<year>2008</year> | |
<gdppc>141100</gdppc> | |
<neighbor name="Austria" direction="E"/> | |
<neighbor name="Switzerland" direction="W"/> | |
</country> | |
<country name="Singapore"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
# parse XML from a file | |
tree = ET.parse(file_path) # parse the file and obtain ElementTree obj | |
root = tree.getroot() # get the root Element obj | |
# parse XML in a string format | |
root = ET.fromstring(country_data_as_string) | |
root = ET.XML(country_data_as_string) # equivalent to above |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list previous stashes | |
git stash list | |
# drop most recent stash | |
git stash drop | |
# apply most recent stash | |
git stash apply | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create a list | |
squares = [1, 4, 9, 16, 25] | |
# indexing | |
squares[0] # it is zero-based index | |
squares[-1] | |
# slicing | |
squares[0:2] # [inclusive, exclusive], first and second element | |
squares[-2:] # last two elements |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Syntax: | |
# '.': Selects the current node. This is mostly useful at the | |
# beginning of the path, to indicate that it’s a relative path. | |
# Example: Find all elements named 'property' that are children | |
# of the current node. | |
root.findall("./property") | |
# Syntax: | |
# '[tag='text']': Selects all elements that have a child |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
f = open('myfile.txt') | |
s = f.readline() | |
i = int(s.strip()) | |
except IOError as e: | |
print "I/O error({0}): {1}".format(e.errno, e.strerror) | |
except ValueError: | |
print "Could not convert data to an integer." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for arg in sys.argv[1:]: | |
try: | |
f = open(arg, 'r') | |
except IOError: | |
print 'cannot open', arg | |
else: | |
print arg, 'has', len(f.readlines()), 'lines' | |
f.close() |