Learning Python Part 1

Best way to learn is to do.  First idea was a Rock+Paper+Scissor Machine.

This probably is not the most effect way but it works…

import random

def get_var_value(filename="varstore0.dat"):
with open(filename, "a+") as f:
val = int(f.read() or 0) + 1
f.seek(0)
f.truncate()
f.write(str(val))
return val

foo = ['Rock', 'Paper', 'Scissor']
foo2 = ['Rock', 'Paper', 'Scissor']

select1 = (random.choice(foo))
select2 = (random.choice(foo2))

print "Player 1 %s" % select1
print "Player 2 %s" % select2

if select1 == select2:
print("Tie")
tie_counter = get_var_value("tie.dat")
print("{} Ties.\n".format(tie_counter))

if select1 == 'Rock' and select2 == 'Paper':
print ("Player 2 Wins - Paper Wins")
p2_counter = get_var_value("p2.dat")
print("Player 2 has won {} Times.\n".format(p2_counter))

if select1 == 'Paper' and select2 == 'Rock':
print ("Player 1 Wins - Paper Wins")
p1_counter = get_var_value("p1.dat")
print("Player 1 has won {} Times.\n".format(p1_counter))

if select1 == 'Rock' and select2 == 'Scissor':
print ("Player 1 Wins - Rock Wins")
p1_counter = get_var_value("p1.dat")
print("Player 1 has won {} Times.\n".format(p1_counter))

if select1 == 'Scissor' and select2 == 'Rock':
print ("Player 2 Wins - Rock Wins")
p2_counter = get_var_value("p2.dat")
print("Player 2 has won {} Times.\n".format(p2_counter))

if select1 == 'Paper' and select2 == 'Scissor':
print ("Player 2 Wins - Scissor Wins")
p2_counter = get_var_value("p2.dat")
print("Player 2 has won {} Times.\n".format(p2_counter))

if select1 == 'Scissor' and select2 == 'Paper':
print ("Player 1 Wins - Scissor Wins")
p1_counter = get_var_value("p1.dat")
print("Player 1 has won {} Times.\n".format(p1_counter))

Let the script fun for a few hours.

Tie 19006 Ties.
Player 1 has won 19052 Times
Player 2 has won 19161 Times.

HP A5500 Bridge-Aggregation LACP Configuration

Switch 1

Create Bridge-Aggregation LACP Trunk

interface Bridge-Aggregation100
link-aggregation mode dynamic

Apply port configuration.

interface GigabitEthernet1/0/49
port link-aggregation group 100
#
interface GigabitEthernet1/0/50
port link-aggregation group 100
#
interface GigabitEthernet1/0/51
port link-aggregation group 100
#
interface GigabitEthernet1/0/52
port link-aggregation group 100

Switch 2

interface Bridge-Aggregation100
link-aggregation mode dynamic

Apply port configuration.

interface GigabitEthernet2/0/1
port link-aggregation group 100
#
interface GigabitEthernet2/0/2
port link-aggregation group 100
#
interface GigabitEthernet1/0/1
port link-aggregation group 100
#
interface GigabitEthernet1/0/2
port link-aggregation group 100

Switch 1

interface Bridge-Aggregation100
port link-type trunk
undo port trunk permit vlan 1
port trunk pvid vlan 456

Switch 2

interface Bridge-Aggregation100
port link-type trunk
undo port trunk permit vlan 1
port trunk pvid vlan 456

Respect the order, do not apply commands to physical interfaces.

Display IP Address of users browser

< ?php
 // the IP address is unknown, so it equals to "%s" now.
 $urlTemplate = 'http://api.ip2location.com/?' . 'ip=%s&key=demo' .  '&package=WS10&format=json';
 // Current browser session
 $ip = $_SERVER['REMOTE_ADDR']?:($_SERVER['HTTP_X_FORWARDED_FOR']?:$_SERVER['HTTP_CLIENT_IP']);

 $urlToCall = sprintf( $urlTemplate, $ip);

 $rawJson = file_get_contents( $urlToCall );

 $geoLocation = json_decode( $rawJson, true );

 echo 'Hello to ', $geoLocation['city_name'];

?>

Best Sports Trip Weekends 2015

Boston
Dec 4, 2015 | Boston Bruins vs Calgary Flames | NHL
Dec 5, 2015 | Boston Celtics vs San Antonio Spurs | NBA
Dec 6, 2015 | New England Patriots vs Philadelphia Eagles | NFL

Chicago
Nov 20, 2015 | Chicago Bulls vs Golden State Warriors | NBA
Nov 21, 2015 | Chicago Blackhawks vs Vancouver Canucks | NHL
Nov 22, 2015 | Chicago Bears vs Denver Broncos  | NFL

New York
Nov 13, 2015 | Brooklyn Nets vs Sacramento Kings |NBA
Nov 13, 2015 | New York Islanders vs Anaheim Ducks | NHL
Nov 14, 2015 | Brooklyn Nets vs Golden State Warriors | NBA
Nov 14, 2015 | New York Rangers vs Ottawa Senators | NHL
Nov 15, 2015 | New York Giants vs New England Patriots | NFL

Nov 27, 2015 | New York Islanders vs Florida Panthers | NHL
Nov 27, 2015 | New York Rangers vs Boston Bruins | NHL
Nov 28, 2015 | Brooklyn Nets vs Cleveland Cavaliers | NBA
Nov 28, 2015 | New York Islanders vs Tampa Bay Lightning | NHL
Nov 29, 2015 | New York Jets vs Miami Dolphins | NFL

Dec 4, 2015 | Brooklyn Nets vs New York Knicks | NBA
Dec 5, 2015 | New York Knicks vs Milwaukee Bucks | NBA
Dec 5, 2015 | New York Islanders vs Ottawa Senators | NHL
Dec 6, 2015 | New York Giants vs New York Jets | NFL

Dec 11, 2015 | New York Rangers vs Edmonton Oilers | NHL
Dec 12, 2015 | New York Knicks vs Portland Trail Blazers | NBA
Dec 12, 2015 | New York Islanders vs Columbus Blue Jackets | NHL
Dec 12, 2015 | New York Rangers vs Calgary Flames | NHL
Dec 13, 2015 | New York Jets vs Tennessee Titans | NFL

Dec 18, 2015 | Brooklyn Nets vs Indiana Pacers| NBA
Dec 18, 2015 | New York Knicks vs Philadelphia 76ers | NBA
Dec 18, 2015 | New York Rangers vs Winnipeg Jets | NHL
Dec 19, 2015 | New York Islanders vs Arizona Coyotes | NHL
Dec 20, 2015 | New York Giants vs Carolina Panthers | NFL

Phoenix
Nov 20, 2015 | Phoenix Suns vs Denver Nuggets | NBA
Nov 21, 2015 | Arizona Coyotes vs Winnipeg Jets | NHL
Nov 22, 2015 | Phoenix Suns vs New Orleans Pelicans | NBA
Nov 22, 2015 | Arizona Cardinals vs Cincinnati Bengals | NFL

Jan 2, 2016 | Phoenix Suns vs Sacramento Kings | NBA
Jan 2, 2016 | Arizona Coyotes vs Edmonton Oilers | NHL
Jan 3, 2016 | Arizona Cardinals vs Seattle Seahawks | NFL
Jan 3, 2016 | Phoenix Suns vs Los Angeles Lakers | NBA
Jan 4, 2016 | Arizona Coyotes vs Vancouver Canucks | NHL

Toronto
Nov 6, 2015 | Toronto Raptors vs Orlando Magic | NBA
Nov 7, 2015 | Toronto Maple Leafs vs Washington Capitals | NHL
Nov 8, 2015 | Buffalo Bills vs Miami Dolphins | NFL

Washington, DC
Nov 27, 2015 | Washington Wizards vs Boston Celtics | NBA
Nov 28, 2015 | Washington Capitals vs Toronto Maple Leafs | NHL
Nov 29, 2015 | Washington Redskins vs New York Giants | NFL

Sending email with mutt

Simple message with text in the body of the email

mutt -s "Test from domain" user@domain.com < /temp/message.txt

And if you need to send an attachment

mutt -s "Test from domain" user@domain.com < /temp/message.txt -a /temp/file.jpg

This is another way to write the test, having the body in the same line.

echo "This is the body" | mutt -s "Testing mutt" user@domain.com -a /temp/file.jpg

[highlighter line=0]