Skip to content

Instantly share code, notes, and snippets.

@Frimkron
Frimkron / gist:5417267
Created April 19, 2013 00:28
Quick proof-of-concept for comparing python code using the abstract syntax tree as an alternative to pattern matching . It's a little more forgiving with whitespace, comments etc. First arg is the solution file, second is the attempt
import ast
import sys
def find_difference(a,b,lastpos=(0,0)):
if isinstance(b,ast.expr) or isinstance(b,ast.stmt):
lastpos = b.lineno,b.col_offset
if type(a) != type(b): return lastpos
if isinstance(a,ast.AST):
for field in a._fields:
@Frimkron
Frimkron / gist:5670205
Created May 29, 2013 13:19
Minecraft server info check
#!/usr/bin/python
import socket
import argparse
import sys
ap = argparse.ArgumentParser()
ap.add_argument("host")
ap.add_argument("port",nargs="?",type=int,default=25565)
args = ap.parse_args()
@Frimkron
Frimkron / pyconical.py
Created October 25, 2017 23:17
PyCon UK 2017 Schedule to iCalendar script
#!/usr/bin/env python3
import re
import sys
import os
import os.path
import begin
import icalendar
import yaml
import pytz