Skip to content

Instantly share code, notes, and snippets.

View nicholastjohnson's full-sized avatar

Nicholas Johnson nicholastjohnson

View GitHub Profile
import gmpy2
def find_closest_prime(n):
up = gmpy2.next_prime(n)
return up
pass
@nicholastjohnson
nicholastjohnson / pythonSendText.py
Created November 14, 2014 16:06
Send text to any number in the US through Python
import requests
def send_text(numstring, message):
message = {"number":numstring, "message":message}
r = requests.post("http://textbelt.com/text", data=message)
return r.status_code, r.text
@nicholastjohnson
nicholastjohnson / deleteFilesBySize.py
Created October 10, 2014 15:33
Python script to delete all files less than a certain size in a directory and subdirectories
import os, os.path
for root, _, files in os.walk("C:/some/dir"):
for f in files:
fullpath = os.path.join(root, f)
try:
if os.path.getsize(fullpath) < 10 * 1024: #set file size in kb
print fullpath
os.remove(fullpath)
except WindowsError:
@nicholastjohnson
nicholastjohnson / renameFilesRecursively.py
Last active August 29, 2015 14:04
Recursively remove or replace unwanted characters from filenames in a directory using Python
import os
paths = (os.path.join(root, filename)
for root, _, filenames in os.walk('C:\FolderName')
for filename in filenames)
for path in paths:
# the '#' in the example below will be replaced by the '-' in the filenames in the directory
newname = path.replace('#', '-')
if newname != path: