Skip to content

Instantly share code, notes, and snippets.

@kozmonaut
kozmonaut / quicksort.py
Last active January 15, 2021 16:21
Quicksort in Python
def quicksort(list):
# Define lists
less = []
equal = []
greater = []
if len(list) > 1: # Check if list have more than 1 element
pivot = list[0] # This is now pivot value
for number in list: # Go through numbers in list
@kozmonaut
kozmonaut / scrape.py
Created January 30, 2015 08:12
Extract links from "beautiful soup"
from bs4 import BeautifulSoup
import csv
import re
import requests
# Copy URL you wanna crawl
print ("Copy the link you wanna scrap:")
url = raw_input("->")
# Fetch url
request = requests.get(url)
@kozmonaut
kozmonaut / geocoder.py
Created January 30, 2015 08:15
Extract company address and coordinates using geocoder
import geocoder
def company(name):
results = geocoder.google(name)
print ("Coordinates: Latitude - %s, Longitude - %s" %(results.lat, results.lng))
print ("Address: %s" % results.address)
if __name__ == '__main__':
print ("Type name of the place:")
name = raw_input()
@kozmonaut
kozmonaut / network.py
Created January 30, 2015 08:18
Networking workbook in py
# Import socket library
import socket
# Import hexlify for ip address conversion
from binascii import hexlify
# Use NTP protocol
import ntplib
from time import ctime
# Print hostname
hostname = socket.gethostname()
@kozmonaut
kozmonaut / rss-parse.py
Created February 11, 2015 14:08
Parse RSS feed and store it to file
from urllib import urlopen
from xml.etree.ElementTree import parse
rss_url = urlopen('http://www.dropsql.com/feed')
xml = parse(rss_url)
f = open('dropsql-feeds.txt', 'w')
# Looks for all item elements under channel tag
for item in xml.iterfind('channel/item'):