From 400992f72631e4e27402a79ce0788a1ba668968e Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 20:49:55 -0400 Subject: [PATCH 1/8] add portscan --- .gitignore | 2 +- Networking/Makefile | 4 ++++ Networking/src/portscan.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Networking/Makefile create mode 100644 Networking/src/portscan.go diff --git a/.gitignore b/.gitignore index c084059d9..05afd1f18 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,4 @@ nosetests.xml # Komodo .komodotools/ -*.komodoproject \ No newline at end of file +*.komodoproject diff --git a/Networking/Makefile b/Networking/Makefile new file mode 100644 index 000000000..f34767af9 --- /dev/null +++ b/Networking/Makefile @@ -0,0 +1,4 @@ +all: portscan + +portscan: + go build -v -o bin/portscan src/portscan.go diff --git a/Networking/src/portscan.go b/Networking/src/portscan.go new file mode 100644 index 000000000..ab412ef58 --- /dev/null +++ b/Networking/src/portscan.go @@ -0,0 +1,34 @@ +package main + +import ( + "fmt" + "net" + "os" + "strconv" + "time" +) + +func main() { + args := os.Args; + if len(args) != 4 { + fmt.Printf("USAGE: %s \n", args[0]); + os.Exit(1); + } + ipaddr := args[1]; + lport, ce1 := strconv.Atoi(args[2]); + uport, ce2 := strconv.Atoi(args[3]); + if ce1 != nil || ce2 != nil { + fmt.Printf("Invalid port received."); + } + to, toerr := time.ParseDuration("3s"); + if toerr != nil {} + for i := lport; i <= uport; i++ { + fmt.Printf("Scanning port %d\n", i); + conn, err := net.DialTimeout("tcp", ipaddr + ":" + strconv.Itoa(i), to); + if err == nil { + fmt.Printf("%d open on TCP.\n", i); + continue; + } + if conn == nil {} + } +} From 2c9beaf70579c01eba0c0cb13338ef965f9f8b4d Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 20:50:54 -0400 Subject: [PATCH 2/8] remove debug print --- Networking/src/portscan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Networking/src/portscan.go b/Networking/src/portscan.go index ab412ef58..925fd749f 100644 --- a/Networking/src/portscan.go +++ b/Networking/src/portscan.go @@ -23,7 +23,7 @@ func main() { to, toerr := time.ParseDuration("3s"); if toerr != nil {} for i := lport; i <= uport; i++ { - fmt.Printf("Scanning port %d\n", i); + //fmt.Printf("Scanning port %d\n", i); conn, err := net.DialTimeout("tcp", ipaddr + ":" + strconv.Itoa(i), to); if err == nil { fmt.Printf("%d open on TCP.\n", i); From 64a0017e2e331101109b70b57b1bacec1d656852 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 20:55:07 -0400 Subject: [PATCH 3/8] reduce timeout --- Networking/src/portscan.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Networking/src/portscan.go b/Networking/src/portscan.go index 925fd749f..963d1a5e0 100644 --- a/Networking/src/portscan.go +++ b/Networking/src/portscan.go @@ -20,7 +20,7 @@ func main() { if ce1 != nil || ce2 != nil { fmt.Printf("Invalid port received."); } - to, toerr := time.ParseDuration("3s"); + to, toerr := time.ParseDuration("300ms"); if toerr != nil {} for i := lport; i <= uport; i++ { //fmt.Printf("Scanning port %d\n", i); From 31bd81d3879c357f1763de173b49e29f41288443 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 21:12:18 -0400 Subject: [PATCH 4/8] remove python --- Numbers/alarm.py | 49 ----------------- Numbers/binary_decimal.py | 50 ------------------ Numbers/calc.py | 17 ------ Numbers/change.py | 39 -------------- Numbers/credit_card_validator.py | 41 -------------- Numbers/distance.py | 55 ------------------- Numbers/factorial.py | 33 ------------ Numbers/fibonacci.py | 15 ------ Numbers/happy_numbers.py | 40 -------------- Numbers/next_prime.py | 25 --------- Numbers/pi.py | 10 ---- Numbers/prime.py | 23 -------- Numbers/tile.py | 11 ---- Numbers/unit.py | 91 -------------------------------- 14 files changed, 499 deletions(-) delete mode 100644 Numbers/alarm.py delete mode 100644 Numbers/binary_decimal.py delete mode 100644 Numbers/calc.py delete mode 100644 Numbers/change.py delete mode 100644 Numbers/credit_card_validator.py delete mode 100644 Numbers/distance.py delete mode 100644 Numbers/factorial.py delete mode 100644 Numbers/fibonacci.py delete mode 100644 Numbers/happy_numbers.py delete mode 100644 Numbers/next_prime.py delete mode 100644 Numbers/pi.py delete mode 100644 Numbers/prime.py delete mode 100644 Numbers/tile.py delete mode 100644 Numbers/unit.py diff --git a/Numbers/alarm.py b/Numbers/alarm.py deleted file mode 100644 index a0a1c7367..000000000 --- a/Numbers/alarm.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -Alarm Clock - A simple clock where it plays a sound after -X number of minutes/seconds or at a particular time. - -Dependencies: -pyglet - pip install pyglet -""" - -import time -import winsound -import pyglet - -def play(hh, mm): - not_alarmed = 1 - - while(not_alarmed): - cur_time = list(time.localtime()) # get the time right now - hour = cur_time[3] # find the hour - minute = cur_time[4] # and the minute - if hour == hh and minute == mm: - song = pyglet.media.load('bin/sound.wav') - song.play() # play the sound - pyglet.app.run() - not_alarmed = 0 # stop the loop - -if __name__ == '__main__': - - print """ - 1. Play sound after X minutes - 2. Play sound at an exact time - """ - choice = input('What do you want to do? ') - - if choice == 1: - mins = input('How many minutes from now? ') - hh_from_now = mins / 60 # if minutes > 60, this will adjust the hours - mm_from_now = mins % 60 # and then the minutes - cur_time = list(time.localtime()) # get the time right now - hour = cur_time[3] # find the current hour - minute = cur_time[4] # and the current minute - hh = (hour + hh_from_now) % 24 # cycle through the clock if hh > 24 - mm = (minute + mm_from_now) % 60 # cycle through the clock if mm > 60 - play(hh, mm) - elif choice == 2: - hh = input('What hour do you want to wake up (0-23)? ') - mm = input('What minute do you want to wake up (0-59)? ') - play(hh, mm) - diff --git a/Numbers/binary_decimal.py b/Numbers/binary_decimal.py deleted file mode 100644 index f378fb76f..000000000 --- a/Numbers/binary_decimal.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -Binary to Decimal and Back Converter -Develop a converter to convert a decimal number to binary -or a binary number to its decimal equivalent. -""" - -def binary_to_decimal(binary): - """ - Converts a binary number into a decimal number. - """ - decimal = 0 - index = 0 - while binary > 0: - last = binary % 10 - binary = binary / 10 - decimal += (last * (2 ** index)) - index += 1 - return decimal - -def decimal_to_binary(decimal): - """ - Converts a decimal number into a binary number. - """ - binary = "" - remainders = [] - while decimal > 0: - remainders.append(str(decimal % 2)) - decimal /= 2 - remainders.reverse() - binary = "".join(remainders) - return binary - -if __name__ == '__main__': - print """ - 1. Binary to Decimal - 2. Decimal to Binary\n - """ - - choice = input("Make a choice: ") - - if choice == 1: - binary = input("Binary to convert: ") - print "The binary number %d in decimal is %d" % \ - (binary, binary_to_decimal(binary)) - elif choice == 2: - decimal = input("Decimal to convert: ") - print "The decimal number %d in binary is %s" % \ - (decimal, decimal_to_binary(decimal)) - else: - print "Invalid choice" diff --git a/Numbers/calc.py b/Numbers/calc.py deleted file mode 100644 index e6ea5f7f2..000000000 --- a/Numbers/calc.py +++ /dev/null @@ -1,17 +0,0 @@ -""" -Calculator - A simple calculator to do basic operators. -""" - -if __name__ == '__main__': - try: - num1 = int(raw_input("Number 1: ")) - num2 = int(raw_input("Number 2: ")) - except: - print 'Invalid input' - else: - op = raw_input("Operation (+, -, /, *): ") - if op not in '+-/*': - print "Invalid operator" - else: - print "%d %s %d = %d" % \ - (num1, op, num2, eval(str(num1) + op + str(num2))) diff --git a/Numbers/change.py b/Numbers/change.py deleted file mode 100644 index 8bce7273e..000000000 --- a/Numbers/change.py +++ /dev/null @@ -1,39 +0,0 @@ -# Change Return Program - The user enters a cost and -# then the amount of money given. The program will figure -# out the change and the number of quarters, dimes, nickels, -# pennies needed for the change. - -if __name__ == '__main__': - cost = input("What's the cost in dollars? ") - given = input("What's the amount of dollars given? ") - - change = given - cost - - print "\n" - if change < 0: - print "Please ask for $%.2f more from the customer." % (-change) # double negation - else: - print "The change is $%.2f." % change - - q = 0 # 0.25 - d = 0 # 0.10 - n = 0 # 0.05 - p = 0 # 0.01 - - change = int(change * 100) # let's talk about cents - - if change >= 25: - q = int(change / 25) - change = change % 25 - if change >= 10: - d = int(change / 10) - change = change % 10 - if change >= 5: - n = int(change / 5) - change = change % 5 - if change >= 1: - p = change # rest all change is in pennies - - print "Give the following change to the customer:" - print "Quarters: %d\tDimes: %d\tNickels: %d\tPennies: %d" \ - % (q, d, n, p) diff --git a/Numbers/credit_card_validator.py b/Numbers/credit_card_validator.py deleted file mode 100644 index 7bb0a39cf..000000000 --- a/Numbers/credit_card_validator.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -Credit Card Validator - Takes in a credit card number from a -common credit card vendor (Visa, MasterCard, American Express, -Discoverer) and validates it to make sure that it is a valid -number (look into how credit cards use a checksum). - -This program works with *most* credit card numbers. - -Uses Luhn Algorithm (http://en.wikipedia.org/wiki/Luhn_algorithm). - -1. From the rightmost digit, which is the check digit, moving -left, double the value of every second digit; if product of this -doubling operation is greater than 9 (e.g., 7 * 2 = 14), then -sum the digits of the products (e.g., 10: 1 + 0 = 1, 14: 1 + 4 = 5). - -2. Add together doubled digits with the undoubled digits from the -original number. - -3. If the total modulo 10 is equal to 0 (if the total ends in zero) -then the number is valid according to the Luhn formula; else it is -not valid. -""" - -if __name__ == '__main__': - number = raw_input('Enter the credit card number of check: ').replace(' ', '') - #if not number.isdigit(): - # raise Exception('Invalid credit card number. Make sure it\'s all digits (with optional spaces in between).' - - digits = [int(char) for char in number] - - # double alternate digits (step 1) - doubled = [(digit * 2) if (i % 2 == 0) else digit \ - for (i, digit) in enumerate(digits)] # i <3 python - # sum digits of number > 10 (step 2) - summed = [num if num < 10 else sum([int(dig) for dig in str(num)]) \ - for num in doubled] # i <3 python ** 2 - # step 3 - if sum(summed) % 10 == 0: - print 'The number is valid' - else: - print 'The number is invalid' diff --git a/Numbers/distance.py b/Numbers/distance.py deleted file mode 100644 index 65cfc9a9b..000000000 --- a/Numbers/distance.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python - -""" -Distance Between Two Cities - Calculates the distance between -two cities and allows the user to specify a unit of distance. -This program may require finding coordinates for the cities -like latitude and longitude. - -Uses the Haversine formula -(http://www.movable-type.co.uk/scripts/latlong.html) - -Dependencies: -geopy - pip install geopy -""" - -from geopy import geocoders # to find lat/lon for the city -import math - -R = 6373 # km - -city1 = raw_input('Enter city 1: ') -city2 = raw_input('Enter city 2: ') -unit = raw_input('Enter unit of distance (Enter "K" for KM or "M" for MI): ').lower() - -if unit in 'km': - - g = geocoders.GoogleV3() - - try: - city1, (lat1, lon1) = g.geocode(city1) - city2, (lat2, lon2) = g.geocode(city2) - except: - raise Exception('Unable to locate the citites. Check the city names.') - - # convert decimal locations to radians - lat1 = math.radians(lat1) - lon1 = math.radians(lon1) - lat2 = math.radians(lat2) - lon2 = math.radians(lon2) - - # start haversne formula - dlon = lon2 - lon1 - dlat = lat2 - lat1 - a = (math.sin(dlat/2) ** 2) + math.cos(lat1) * math.cos(lat2) * \ - (math.sin(dlon/2) ** 2) - c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) - d = R * c - - if unit == 'k': - print 'Distance between %s and %s is %.04f km' % (city1, city2, d) - else: - print 'Distance between %s and %s is %.04f mi' % (city1, city2, d / 1.60934) -else: - print 'Invalid unit input!' diff --git a/Numbers/factorial.py b/Numbers/factorial.py deleted file mode 100644 index b09d5e2f4..000000000 --- a/Numbers/factorial.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -Factorial Finder - The Factorial of a positive integer, n, -is defined as the product of the sequence n, n-1, n-2, ...1 -and the factorial of zero, 0, is defined as being 1. Solve -this using both loops and recursion. -""" - -def fact_loop(n): - """ - Returns the factorial of a given positive, non-zero integer - using loops. - """ - fact = 1 - while n > 0: - fact *= n - n -= 1 - return fact - -def fact_recursion(n): - """ - Returns the factorial of a given positive, non-zero integer - using recursion. - """ - return 1 if n == 0 else n * fact_recursion(n - 1) # if user as ternary operator - -if __name__ == '__main__': - n = input('Enter a positive number: ') - - if n >= 0: - print 'Factorial of %d by loops is %d' % (n, fact_loop(n)) - print 'Factorial of %d by recursion is %d' % (n, fact_recursion(n)) - else: - print 'Not a valid number' diff --git a/Numbers/fibonacci.py b/Numbers/fibonacci.py deleted file mode 100644 index a6692a94f..000000000 --- a/Numbers/fibonacci.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: cp1252 -*- -# Fibonacci Sequence - Enter a number and have the -# program generate the Fibonacci sequence to that number -# or to the Nth number - -n = int(raw_input('How many numbers do you need? ')) -series = [1] - -while len(series) < n: - if len(series) == 1: - series.append(1) - else: - series.append(series[-1] + series[-2]) - -print series diff --git a/Numbers/happy_numbers.py b/Numbers/happy_numbers.py deleted file mode 100644 index a50f05f92..000000000 --- a/Numbers/happy_numbers.py +++ /dev/null @@ -1,40 +0,0 @@ -""" -Happy Numbers - A happy number is defined by the -following process. Starting with any positive integer, -replace the number by the sum of the squares of its -digits, and repeat the process until the number equals -1 (where it will stay), or it loops endlessly in a -cycle which does not include 1. Those numbers for which -this process ends in 1 are happy numbers, while those -that do not end in 1 are unhappy numbers. Take an input -number from user, and find first 8 happy numbers from -that input. -""" - -NUMBERS_REQUIRED = 8 # number of happy numbers required - -def is_happy_number(num): - seen = [] - while True: - sum_digits = sum(int(digit) ** 2 for digit in str(num)) - if sum_digits == 1: - return True - elif sum_digits in seen: - return False - else: - num = sum_digits - seen.append(num) - -if __name__ == '__main__': - - happies = [] # list of happy numbers found - - num = input('Start at: ') - - while len(happies) != NUMBERS_REQUIRED: - if is_happy_number(num): - happies.append(num) - num += 1 - - print happies - diff --git a/Numbers/next_prime.py b/Numbers/next_prime.py deleted file mode 100644 index 0f356acee..000000000 --- a/Numbers/next_prime.py +++ /dev/null @@ -1,25 +0,0 @@ -# Next Prime Number - Have the program find prime -# numbers until the user chooses to stop asking for -# the next one. - -def next_prime(current): - next_prime = current + 1 # start checking for primes 1 number after the current one - i = 2 - while next_prime > i: # check with numbers up to next_prime - 1 - if next_prime % i == 0: # if number is divisible - next_prime += 1 # ready to check the next number - i = 2 # reset i to check divisibility again from 2 - else: - i += 1 # increment the divisor - return next_prime - -if __name__ == '__main__': - current_prime = 2 - while True: - response = raw_input('Do you want the next prime? (Y/N) ') - - if response.lower().startswith('y'): - print current_prime - current_prime = next_prime(current_prime) - else: - break diff --git a/Numbers/pi.py b/Numbers/pi.py deleted file mode 100644 index 559480110..000000000 --- a/Numbers/pi.py +++ /dev/null @@ -1,10 +0,0 @@ -# Find PI to the Nth Digit - -from math import * - -digits = raw_input('Enter number of digits to round PI to: ') - -# print ('{0:.%df}' % min(20, int(digits))).format(math.pi) # nested string formatting - -# calculate pi using Machin-like Formula -print ('{0:.%df}' % min(30, int(digits))).format(4 * (4 * atan(1.0/5.0) - atan(1.0/239.0))) diff --git a/Numbers/prime.py b/Numbers/prime.py deleted file mode 100644 index ffa1ea83c..000000000 --- a/Numbers/prime.py +++ /dev/null @@ -1,23 +0,0 @@ -# Prime Factorization - Have the user enter a number -# and find all Prime Factors (if there are any) and -# display them. - - -def is_a_prime(x): - for i in range(2, x): - if x % i == 0: - return False - return True - -# standard boilerplate -if __name__ == '__main__': - n = int(raw_input('Enter the number to find prime factors of: ')) - - factors = [] - - for i in range(2, n + 1): - while n % i == 0: # Thanks @madsulrik - if is_a_prime(i): - factors.append(i) - n /= i - print factors diff --git a/Numbers/tile.py b/Numbers/tile.py deleted file mode 100644 index 6f4d7cf62..000000000 --- a/Numbers/tile.py +++ /dev/null @@ -1,11 +0,0 @@ -# Find Cost of Tile to Cover W x H Floor - Calculate -# the total cost of tile it would take to cover a floor -# plan of width and height, using a cost entered by the user. - -# Use input as the input can be integer and float -cost = input("What's the cost per sq. feet? ") -width = input("What's the width of the floor? ") -height = input("What's the height of the floor? ") - -print "The total cost is $%.2f for %.2f square feet" \ - % (width * height * cost, width * height) diff --git a/Numbers/unit.py b/Numbers/unit.py deleted file mode 100644 index 383044e99..000000000 --- a/Numbers/unit.py +++ /dev/null @@ -1,91 +0,0 @@ -""" -Unit Converter (temp, currency, volume, mass and more) - Converts -various units between one another. The user enters the type of unit -being entered, the type of unit they want to convert to and then -the value. The program will then make the conversion. -""" - -from __future__ import division -from urllib2 import urlopen -import json - -# 1 (std unit) = these many units -MULTIPLIERS_TO_STD = { - 'length': { - 'cm': 0.01, - 'm': 1, # std unit - 'km': 1000, - 'mi': 1609.34, - 'ft': 0.3048 - }, - 'temp': { - 'C': 1, # std unit - 'F': 33.8 - } -} - -# These many units = 1 (std unit) -MULTIPLIERS_FROM_STD = { - 'length': { - 'cm': 100, - 'm': 1, # std unit - 'km': 0.001, - 'mi': 0.000621371, - 'ft': 3.28084 - }, - 'temp': { - 'C': 1, # std unit - 'F': -17.2222 - } -} - - -def get_user_input(choice): - units = ', '.join(MULTIPLIERS_TO_STD[choice].keys()) - source_unit = raw_input('\nEnter source unit (%s): ' % units) - source_val = float(raw_input('How many %s\'s? ' % source_unit)) - convert_to = raw_input('Convert to? (%s): ' % units) - return source_unit, source_val, convert_to - -def get_currency(source_unit, source_val, convert_to): - url = 'http://rate-exchange.appspot.com/currency?from=%s&to=%s&q=%s' % ( - source_unit, convert_to, str(source_val)) - content = urlopen(url).read() - return json.loads(content)['v'] - -def main(): - print """Unit Converter - 1. Length - 2. Temperature - 3. Currency""" - - choice = int(raw_input('What do you want to convert: ')) - - if choice == 1: - source_unit, source_val, convert_to = get_user_input('length') - print '%f%s = %f%s' % (source_val, source_unit, - source_val * \ - MULTIPLIERS_TO_STD['length'][source_unit] * \ - MULTIPLIERS_FROM_STD['length'][convert_to], \ - convert_to) - elif choice == 2: - source_unit, source_val, convert_to = get_user_input('temp') - if (source_unit, convert_to) == ('F', 'C'): # F -> C - value = (source_val - 32) * (5/9) - elif (source_unit, convert_to) == ('C', 'F'): # C -> F - value = (source_val * (9/5)) + 32 - else: - value = source_val - print '%f%s = %f%s' % (source_val, source_unit, - value, convert_to) - - elif choice == 3: - source_unit = raw_input('\nEnter source currency (eg USD, INR etc): ') - source_val = float(raw_input('How many %s\'s? ' % source_unit)) - convert_to = raw_input('Convert to? (eg USD, INR etc): ') - print '%f%s = %f%s' % (source_val, source_unit, - get_currency(source_unit, source_val, convert_to), - convert_to) - -if __name__ == '__main__': - main() From 4df12a1d80941ef09d852466230e39ee5860ce36 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 21:20:42 -0400 Subject: [PATCH 5/8] really add alarm --- Numbers/Makefile | 4 ++++ Numbers/src/alarm.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 Numbers/Makefile create mode 100644 Numbers/src/alarm.go diff --git a/Numbers/Makefile b/Numbers/Makefile new file mode 100644 index 000000000..70066d292 --- /dev/null +++ b/Numbers/Makefile @@ -0,0 +1,4 @@ +all: alarm + +alarm: + go build -v -o bin/alarm src/alarm.go diff --git a/Numbers/src/alarm.go b/Numbers/src/alarm.go new file mode 100644 index 000000000..a71212999 --- /dev/null +++ b/Numbers/src/alarm.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" + "time" + "os" +) + +func main() { + args := os.Args; + if len(args) < 2 { + fmt.Printf("USAGE: %s [delay2] ... [delayn]\n", args[0]); + os.Exit(1); + } + for i := 1; i < len(args); i++ { + pd, pderr := time.ParseDuration(args[i]); + if pderr != nil { os.Exit(-1); } + time.Sleep(pd); + } + fmt.Printf("\a"); +} From 2e47b48b9676c673c4ef01c496ae946e2aaac334 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Tue, 15 Oct 2013 21:23:56 -0400 Subject: [PATCH 6/8] remove ALL python --- Classes/product_inventory.py | 80 ----------------------------------- Classic Algorithms/collatz.py | 29 ------------- Text/count_vowels.py | 19 --------- Text/count_words.py | 26 ------------ Text/palindrome.py | 12 ------ Text/piglatin.py | 22 ---------- Text/reverse.py | 8 ---- Text/rss.py | 29 ------------- Web/page_scraper.py | 33 --------------- Web/time.py | 25 ----------- 10 files changed, 283 deletions(-) delete mode 100644 Classes/product_inventory.py delete mode 100644 Classic Algorithms/collatz.py delete mode 100644 Text/count_vowels.py delete mode 100644 Text/count_words.py delete mode 100644 Text/palindrome.py delete mode 100644 Text/piglatin.py delete mode 100644 Text/reverse.py delete mode 100644 Text/rss.py delete mode 100644 Web/page_scraper.py delete mode 100644 Web/time.py diff --git a/Classes/product_inventory.py b/Classes/product_inventory.py deleted file mode 100644 index df1ef1afa..000000000 --- a/Classes/product_inventory.py +++ /dev/null @@ -1,80 +0,0 @@ -""" -Product Inventory Project - Create an application which manages -an inventory of products. Create a product class which has a -price, id, and quantity on hand. Then create an inventory class -which keeps track of various products and can sum up the inventory -value. -""" - -class Product: - - def __init__(self, price, pid, qty): - """ - Class constructor that needs a price, a product id, - and quantity. - """ - self.price = price - self.pid = pid - self.qty = qty - - def update_qty(self, qty, method='add'): - """ - Updates the quantity of produts. By default, adds the - passed quantity. Pass method as 'subtract' to subtract - the quantity. - """ - if method == 'add': - self.qty += qty - elif method == 'subtract': - self.qty = max(0, self.qty - qty) - - def print_product(self): - """ - Prints a single product. - """ - print '%d\t%s\t%.02f each' % (self.pid, self.qty, self.price) - -class Inventory: - - def __init__(self): - """ - Initializes the class instance. - """ - self.products = [] # list to hold all products - - def add(self, product): - """ - Adds a passed Product to the list of products. - """ - self.products.append(product) - - def print_inventory(self): - """ - Prints the current inventory, and the total value - of products. - """ - value = 0 - for product in self.products: - print '%d\t%s\t%.02f each' % (product.pid, - product.qty, - product.price) - value += (product.price * product.qty) - print '\nTotal value: %.02f' % value - -if __name__ == '__main__': - p1 = Product(1.4, 123, 5) - p2 = Product(1, 3432, 100) - p3 = Product(100.4, 2342, 99) - - - i = Inventory() - i.add(p1) - i.add(p2) - i.add(p3) - i.print_inventory() - - p1.update_qty(10) - i.print_inventory() - - p1.update_qty(10, method='subtract') - i.print_inventory() diff --git a/Classic Algorithms/collatz.py b/Classic Algorithms/collatz.py deleted file mode 100644 index 3881ea11e..000000000 --- a/Classic Algorithms/collatz.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -Collatz Conjecture - Start with a number n > 1. -Find the number of steps it takes to reach one using -the following process: If n is even, divide it by 2. -If n is odd, multiply it by 3 and add 1. -""" - -def main(): - try: - n = int(raw_input('Enter a number: ')) - except ValueError: - print 'Enter only an integer value, n > 1.' - - steps = 0 - - print '\n%d' % n, - - while n > 1: - if n % 2 == 0: - n /= 2 - else: - n = (n * 3) + 1 - steps += 1 - print ' -> %d' % n, - - print '\n\n%d steps take to reach ONE.' % steps - -if __name__ == '__main__': - main() diff --git a/Text/count_vowels.py b/Text/count_vowels.py deleted file mode 100644 index fe55626f1..000000000 --- a/Text/count_vowels.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -Count Vowels - Enter a string and the program counts -the number of vowels in the text. For added complexity -have it report a sum of each vowel found. -""" - -from collections import defaultdict - -if __name__ == '__main__': - string = raw_input('Enter a string: ').lower() - - vowels = ['a', 'e', 'i', 'o', 'u'] - counts = defaultdict(int) - - for char in string: - if char in vowels: - counts[char] += 1 - - print counts.items() diff --git a/Text/count_words.py b/Text/count_words.py deleted file mode 100644 index 113c31f81..000000000 --- a/Text/count_words.py +++ /dev/null @@ -1,26 +0,0 @@ -""" -Count Words in a String - Counts the number of individual -words in a string and display the top 5/10 most used words. -""" - -from collections import defaultdict -import operator - -if __name__ == '__main__': - text = raw_input('Enter some text: \n') - words = text.split() # very naive approach, split at space - - counts = defaultdict(int) # no need to check existence of a key - - # find count of each word - for word in words: - counts[word] += 1 - - # sort the dict by the count of each word, returns a tuple (word, count) - sorted_counts = sorted(counts.iteritems(), \ - key=operator.itemgetter(1), \ - reverse=True) - - # print top 5 words - for (word,count) in sorted_counts[:5]: # thanks @jrwren for this! - print (word, count) diff --git a/Text/palindrome.py b/Text/palindrome.py deleted file mode 100644 index 43c7f4145..000000000 --- a/Text/palindrome.py +++ /dev/null @@ -1,12 +0,0 @@ -""" -Check if Palindrome - Checks if the string entered -by the user is a palindrome. That is that it reads -the same forwards as backwards like "racecar" -""" - -string = raw_input('Enter a string: ').lower() - -if string == string[::-1]: - print '%s is a palindrome' % string -else: - print '%s is not a palindrome' % string diff --git a/Text/piglatin.py b/Text/piglatin.py deleted file mode 100644 index 07af62233..000000000 --- a/Text/piglatin.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Pig Latin - Pig Latin is a game of alterations played -on the English language game. To create the Pig Latin -form of an English word the initial consonant sound is -transposed to the end of the word and an ay is affixed -(Ex.: "banana" would yield anana-bay). Read Wikipedia -for more information on rules. -""" - -word = raw_input('What\'s your word? ').lower() -vowels = 'aeiou' - -pig = 'ay' - -first = word[0] - -if first in vowels: - new = word + pig -else: - new = word[1:] + first + pig - -print new diff --git a/Text/reverse.py b/Text/reverse.py deleted file mode 100644 index 5cec022c3..000000000 --- a/Text/reverse.py +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: cp1252 -*- -""" -Reverse a String - Enter a string and the program -will reverse it and print it out. -""" - -string = raw_input("Whatchu wanna say to me? ") -print "You say %s, I say %s" % (string, string[::-1]) diff --git a/Text/rss.py b/Text/rss.py deleted file mode 100644 index 25f8c8f1d..000000000 --- a/Text/rss.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -RSS Feed Creator - Given a link to RSS/Atom Feed, -get all posts and display them. -""" - -import re -import urllib2 - - -def main(): - """ - Takes in a Feedburned feed URL. - - Eg: http://feeds.feedburner.com/WebDesignLedger - """ - feed_url = raw_input('Enter Feedburner RSS URL: ') - content = urllib2.urlopen(feed_url).read() # get the source code of feed - - link_pattern = re.compile('(.*)') - title_pattern = re.compile('(.*)') - - links = re.findall(link_pattern, content)[1:] # skip blog url - titles = re.findall(title_pattern, content)[1:] # skip the page title - - for (link, title) in zip(links, titles): - print '{0}\n{1}\n'.format(title, link) - -if __name__ == '__main__': - main() diff --git a/Web/page_scraper.py b/Web/page_scraper.py deleted file mode 100644 index ccfd191fa..000000000 --- a/Web/page_scraper.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: cp1252 -*- -""" -Page Scraper - Create an application which connects to a -site and pulls out all links, or images, and saves them to -a list. Optional: Organize the indexed content and don�t -allow duplicates. Have it put the results into an easily -searchable index file. -""" - -import urllib2 -from bs4 import BeautifulSoup - - -def print_list(stuff): - print '\n'.join(stuff) - print '\n====================\n' - -if __name__ == '__main__': - - url = raw_input('Enter a URL: ') - - choice = input('What to scrape?\n1. Links\n2. Images\n3. Both\n') - - soup = BeautifulSoup(urllib2.urlopen(url).read()) - - if choice == 1 or choice == 3: - urls = [link.get('href') for link in soup.findAll('a')] - print 'URLs:' - print_list(urls) - if choice == 2 or choice ==3: - images = [image['src'] for image in soup.findAll("img")] - print 'Images:' - print_list(images) diff --git a/Web/time.py b/Web/time.py deleted file mode 100644 index 073d75f47..000000000 --- a/Web/time.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -Get Atomic Time from Internet Clock - This program will get -the true atomic time from an atomic time clock on the Internet. -Use any one of the atomic clocks returned by a simple Google search. -""" - -import re -from urllib2 import urlopen - - -def main(): - url = 'http://time.is/just' - content = urlopen(url).read() - pattern = re.compile('
(.*)(AM|PM)
') - - find_match = re.search(pattern, content) - - location_pat = re.compile('

(.*)

') - location_match = re.search(location_pat, content) - - print 'The time in %s is %s %s' % \ - (location_match.group(1), find_match.group(1), find_match.group(2)) - -if __name__ == '__main__': - main() From 8a453b354c46f630ee635324dcba528428688ae9 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Thu, 17 Oct 2013 00:48:38 -0400 Subject: [PATCH 7/8] gotta go speed --- Networking/src/portscan.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Networking/src/portscan.go b/Networking/src/portscan.go index 963d1a5e0..af11ff9f8 100644 --- a/Networking/src/portscan.go +++ b/Networking/src/portscan.go @@ -8,6 +8,16 @@ import ( "time" ) +func checkPort(p int, address string, t time.Duration, chanind int, chans []chan int) { + conn, err := net.DialTimeout("tcp", address + ":" + strconv.Itoa(p), t); + if err == nil { + fmt.Printf("%d open on TCP.\n", p); + chans[chanind] <- 0; + } + if conn == nil {} + //fmt.Printf("%d Nope %d\n", p, chanind); + chans[chanind] <- 0; +} func main() { args := os.Args; if len(args) != 4 { @@ -21,14 +31,16 @@ func main() { fmt.Printf("Invalid port received."); } to, toerr := time.ParseDuration("300ms"); + var quits_received = make([]chan int, 500, 1000); + for quit := range quits_received { + quits_received[quit] = make(chan int) + } if toerr != nil {} for i := lport; i <= uport; i++ { + go checkPort(i, ipaddr, to, uport - i, quits_received); //fmt.Printf("Scanning port %d\n", i); - conn, err := net.DialTimeout("tcp", ipaddr + ":" + strconv.Itoa(i), to); - if err == nil { - fmt.Printf("%d open on TCP.\n", i); - continue; - } - if conn == nil {} + } + for j := lport; j <= uport; j++ { + <-quits_received[uport - j]; } } From 02c496ace8c93e2f1ad5c0e095562902c839e0b3 Mon Sep 17 00:00:00 2001 From: James Forcier <2014jforcier@tjhsst.edu> Date: Thu, 17 Oct 2013 08:40:14 -0400 Subject: [PATCH 8/8] minor changes --- Networking/src/portscan.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Networking/src/portscan.go b/Networking/src/portscan.go index af11ff9f8..fbf1c570f 100644 --- a/Networking/src/portscan.go +++ b/Networking/src/portscan.go @@ -15,9 +15,9 @@ func checkPort(p int, address string, t time.Duration, chanind int, chans []chan chans[chanind] <- 0; } if conn == nil {} - //fmt.Printf("%d Nope %d\n", p, chanind); chans[chanind] <- 0; } + func main() { args := os.Args; if len(args) != 4 { @@ -28,17 +28,16 @@ func main() { lport, ce1 := strconv.Atoi(args[2]); uport, ce2 := strconv.Atoi(args[3]); if ce1 != nil || ce2 != nil { - fmt.Printf("Invalid port received."); + fmt.Printf("Invalid port received.\n"); } to, toerr := time.ParseDuration("300ms"); - var quits_received = make([]chan int, 500, 1000); + var quits_received = make([]chan int, 500, 10000); for quit := range quits_received { quits_received[quit] = make(chan int) } if toerr != nil {} for i := lport; i <= uport; i++ { go checkPort(i, ipaddr, to, uport - i, quits_received); - //fmt.Printf("Scanning port %d\n", i); } for j := lport; j <= uport; j++ { <-quits_received[uport - j];