Skip to content

Instantly share code, notes, and snippets.

@at1as
at1as / reverseAndAdd.py
Created November 15, 2013 02:51
Add a number to its reverse until a palindrome is found
#!/usr/bin/env python2.7
'''
This program will add a number to its reverse until a palindrome is found
It will try up to 1000 iterations (configurable), or else notify the user a palindrome was not found
'''
count, maxIterations, currentValue = 1, 1000, ''
#Accept integers in range(1,100)
@at1as
at1as / zerosInRange.py
Created November 15, 2013 04:25
Returns the count of zeros contained in the numbers within a specified range
#!/usr/bin/env python2.7
'''
Return the count of zeros contained in the numbers within a specified range
'''
index, increment, count = 1, 2, 0
ceiling = int(raw_input("\nCeiling: "))
oddEven = raw_input("Search through:\nOdd numbers \t- 1 \nEven numbers \t- 2 \nOdd & Even \t- 3\n\nInput(1,2,3)? ")
@at1as
at1as / personalisePDF
Last active December 28, 2015 09:29
Inserts a personalised page containing customer information into an existing PDF. Then edits document metadata and uploads to a publicly accessible Dropbox folder, returning the URL.
This tool will take an existing PDF and insert into it (at a given index) a page containing user details, then edit the metadata to match those details (such as a customer name). Finally, it will upload to file to a shared dropbox folder and return its URL.
Requirements:
* exiftool www.sno.phy.queensu.ca/~phil/exiftool/
* DropBox Access Token
* Python 2.7 (dependencies will not work in Python 3)
Limitations:
* pyPDF2 is unreliable. Does not work on all PDFs
* ReportLab PDF size is not reliable - may need to be hardcoded to match document
@at1as
at1as / fibanacciInRange.py
Created November 15, 2013 23:30
Returns a list of Fibanacci numbers that fall within a given (user-specified) range
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
'''
Returns list of Fibanacci numbers within a given range
'''
n = [0,1,0] #placeholder: prev,curr,next fibanacci numbers
matches = 0
@at1as
at1as / waterfall
Last active December 28, 2015 17:39
Visual representation of area contained within the local maximums of an array of values
A visual representation of area contained within the local maximums of an array of values. Visualised as pools of water between the walls of a structure. Example below.
jason$ python waterfall.py
Define your structure (comma seperated): 5,1,6,2,4,3,4
| | | | | | | |
| | | | | | | |
| | | -S- | | | | |
| -S- | W | -S- | | | | |
| -S- | W | -S- | W | -S- | W | -S- |
@at1as
at1as / limitedNaturalSort.py
Created November 19, 2013 04:58
A very basic natural ordering sorting algorithm (will take two user given inputs and sort them in order using a natural sort - i.e., instead of being seen as strings, numbers within a string are assigned their magnitudes)
import re
'''
Will sort two user inputed strings using a natural sorting algorithm (i.e., numbers are assigned their magnitudes)
ex. [file2, file10] or [file3abc, file10abc]
'''
filenames = raw_input("Enter two filenames (comma seperated, no space): ").split(",")
def naturalSort(a,b):
@at1as
at1as / factorBranches
Created November 20, 2013 00:22
Given an integer, will return a list of all factor branches from the integer to 1. Range of divisors to use can be set through maxDivisor
Given an integer, will return a list of all factor branches from the integer to 1. Range of divisors to use can be set through maxDivisor
ex. using input 72, and divisors of less than 10:
jason$ python factorBranches.py
Enter a positive integer (large numbers will yield high runtime): 72
[72, 8, 1]
[72, 9, 1]
[72, 12, 2, 1]
[72, 12, 3, 1]
@at1as
at1as / simpleSubstitutionCipher.py
Last active December 28, 2015 20:19
A simple substitution cipher with example output. Fixed-length 2 digit keys yield single character defined in dictionary, d.
#!/bin/usr/env python2.7
# -*- coding: utf-8 -*-
d = { '5E': 't', '5D': 'w', '5F': 'u', '5A': 'p', '5C': 'v', '5B': 'q', '48': 'b', '49': 'c', '46': 'l', '47': 'm', '44': 'n', '45': 'o',
'42': 'h', '43': 'i', '40': 'j', '41': 'k', '0A': ' ', '4F': 'e', '4D': 'g', '4E': 'd', '4B': 'a', '6B': 'A', '59': 's', '58': 'r',
'6F': 'E', '50': 'z', '53': 'y', '52': 'x', '6D' : 'G', '0B' : '!', '07' : '-', '06' : ',', '27' : '\\', '20' : 'n', '4C' : 'f', '6C' : 'F',
'C7' : 'í', '64' : 'N', 'C1' : 'ë' }
ct = '6B0A6F46484F584F5E420A6D43465E42454443C1462720594346435C584F440A5A4F44444B0A47C75843C1462720450A474F444F460A4B4D464B580A4F464F444B5E420B2720644B0749424B4F584F4E0A5A4B464B44074EC75843C1462720450A4D4B464B4E42584F474743440A4F444445584B5E420627206C4B445F43464559060A464F0A464344444B5E4245442720444F4C0A4B4F4B58060A59C70A444F4C0A4B4F4B5845440B'
@at1as
at1as / carryOperations.py
Last active December 28, 2015 22:29
Will return the number of carry operations performed when adding two positive numbers
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-
'''
Will return the number of carry operations performed in positive integer addition
'''
carryover, carryCount = False, 0
while True: #accept positive integer values as input
try:
@at1as
at1as / webServerData.py
Last active January 1, 2016 07:09
Simple python script to extract basic website information (derived from curl request + ping), and display is cleanly. Example output below:Status: HTTP/1.1 200 OK,Server: Apache,Server Time: Mon, 23 Dec 2013 22:00:00 GMT,Actual Time: 2013-12-23 22:00:12.601447,Encoding: UTF-8,Default Path: example.com/Home.html,URL Lowercase: False,Has Favicon: …
#!/bin/bash/env python2.7
from subprocess import Popen, PIPE, STDOUT
import re
import datetime
site = 'example.com' #enter website URL here
favicon = False
ssl_enabled = False