Skip to content

Instantly share code, notes, and snippets.

@BasementCat
BasementCat / uploadfile.php
Created January 11, 2012 04:38
A simple PHP file upload script, that handles exactly one file
<?php
/*First of all I'm going to DEFINE a few constants because it makes more sense
to use DEFINE for variables that do not change during the execution of the code.*/
//Max. size of uploaded files in MB
define('F_UPLOAD_MAX_SIZE_MB', 12);
//Directory to save uploaded files in
define('F_UPLOAD_DIR', './uploads');
@BasementCat
BasementCat / bottle-example.py
Created July 6, 2012 23:43
Very, very basic Bottle.py app
from bottle import app, route
@route("/")
@route("/<name>")
def index(name=None):
out=[]
if name is not None:
out.append("%s says "%(name,))
out.append("Hello, World")
return out
@BasementCat
BasementCat / gist:4185986
Created December 1, 2012 23:47
Splitting an ipv6 address in python
#!/usr/bin/python
import itertools
address="fe80::224:8cff:fe09:98dd"
#verbose
addressLeft, addressRight=[x.split(":") for x in address.split("::")]
addressZeros=["0" for i in range(0, 8-(len(addressLeft)+len(addressRight)))]
print itertools.chain(addressLeft, addressZeros, addressRight)
import re
with open("infile.txt", "r") as fp:
queue=""
match=r"[?!.]+\s+"
for rawLine in fp:
rawLine=" ".join((queue, rawLine))
queue=""
lines=rawLine.split(match)
if re.search(match+"$", rawLine):
@BasementCat
BasementCat / gist:8883c5278e87387289e0
Created January 20, 2015 16:08
Check HTTP response code for multiple URLs
for URL in url1 url2 url3;
do
curl -sLI -w "%{http_code} %{url_effective}\\n" "$URL" -o /dev/null |tee -a output.txt;
done;