Skip to content

Instantly share code, notes, and snippets.

@hackerdem
hackerdem / bingo_board_gui
Created April 22, 2016 15:14
bingo board with gui, simpl python programming example including tkinter
import random
from tkinter import *
chosen_number_list=[]
numbers=[]
for i in range(1,101):
numbers.append(i)
def random_number_selection():
global c
c=[]
@hackerdem
hackerdem / Simple_gui_example
Created April 21, 2016 08:24
python script for simple GUI design with tkinter
from tkinter import *
from random import randrange
def drawshape():
x1,x2,x3=150,400,250
y1,y2,y3=250,150,350
can1.create_line(y2,x3,y3,x3,width=2,fill=coul)
can1.create_line(y1,x1,y1,x2,width=2,fill=coul)
def change_shape_colour():
global coul
pal=['purple','red','blue','orange','yellow']
@hackerdem
hackerdem / happy_prime_numbers
Created April 18, 2016 07:27
given to list of numbers, from a website, which contain happy numbers and prime numbers, find common numbers
import urllib.request
# get data
def get_data(target):
listo=[]
response=urllib.request.urlopen(target).read().decode('utf-8').split('\n')
for line in response:
listo.append(line)
return listo
#find common values
def find_intersection(data):
@hackerdem
hackerdem / find_happy_numbers
Created April 17, 2016 17:07
find happy numbers for a given interval
import threading
import queue
import argparse
def happy_number_finder(num,re_list):
top=0
if len(re_list)==2:del re_list[-1]
re_list.append(num)
for ch in num:
top+=(int(ch))**2
@hackerdem
hackerdem / OpenSSL_Checker
Last active April 17, 2016 04:38
Getting server addresses from a csv file, check OpenSSL version to see if the are vulnerable to Heartbleed
import ssl
import socket
import csv
import queue,threading
def checker(value):
try:
a=[]
target='{}'.format(value)
port=443
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
@hackerdem
hackerdem / Roman_Number_converter.py
Created April 14, 2016 12:57
Write a Python program to convert a roman numeral to an integer.
class A:
def convert(self,roman):
num_list=[1,4,5,9,10,40,50,90,100,400,500,900,1000]
rom_list=['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M']
next_val= 0
for i in range(len(roman)):
if i!=len(roman)-1:
if rom_list.index(roman[i])>=rom_list.index(roman[i+1]):
next_val+=num_list[rom_list.index(roman[i])]
else:
@hackerdem
hackerdem / Roman Number Coversion
Created April 14, 2016 07:52
Convert numbers to roman numbers using a class instances
class A:
def __init__(self,num):
self.num=num
self.num_list=[1,4,5,9,10,40,50,90,100,400,500,900,1000]
self.rom_list=['I','IV','V','IX','X','XL','L','XC','C','CD','D','CM','M']
self.roman_num=" "
self.next_val= num
def convert(self,num):
while self.next_val!=0:
if self.next_val<1000:
@hackerdem
hackerdem / threading.py
Created April 6, 2016 13:53
Python threading example
import threading
import time
import queue
num_list=[i for i in range(500)]
prime_list=[]
listo=[]
#if you take a look at processing time,you will see that threading takes more time than normal calculation, it is because of time to be needed to
#create threads.Threading OS dependent and time taking process and in simple calculations like this one is not a good example to show threading.
#so,I have added time sleep to check_prime function to show efficiency of threading.Try it with and without time sleep.
def check_prime(num):
@hackerdem
hackerdem / csv_airport_distance_calculator.py
Last active April 6, 2016 13:36
Python code to calculate distance of pairs of longitude and latitude using Haversine formula. Data will be retrieved from two files containing airports and routes from every airports.Distance between two destination will be calculated and listed.
import csv
import math
def deg_to_rad(deg):
return deg*(math.pi/180)
def calculate_distance(a,b):
#distance calculation according to Haversine formula
new_listo=[]
new_listo.extend(a)
new_listo.extend(b)
@hackerdem
hackerdem / lynda_challange_1.py
Last active April 6, 2016 13:39
A python challenge from Lynda. Air temperature, barometric pressure and wind speed data will be retrieved from a web page and mean and median will be calculated for the given set of data.
import urllib.request
import ssl
import statistics
def calculate_mean(d):
x=statistics.mean(d['Air_temp'])
y=statistics.mean(d['Barometric_press'])
z=statistics.mean(d['Wind_Speed'])
return x,y,z
def calculate_median(d):
x=statistics.median(d['Air_temp'])