Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dracos
dracos / three-data-checker.py
Created April 2, 2017 13:51
Script to tell me how much data I have left on my 3 SIM
#!/usr/bin/env python
import os
import re
import requests
s = requests.Session()
class ThreeWebsite(object):
username = os.environ['PHONE_NUMBER']
@dracos
dracos / proxy.py
Created March 16, 2017 10:19
A python proxy
import re
import socket
import signal
import sys
import threading
def sigint_received(signum, frame):
sys.exit(0)
signal.signal(signal.SIGINT, sigint_received)
@dracos
dracos / new.py
Created March 14, 2017 15:33
Sarah & Duck upcoming episodes
PID = 'b04drklx'
for date in arrow.Arrow.range('day', arrow.now(), arrow.now().replace(weeks=1)):
soup = BeautifulSoup(get_contents('http://www.bbc.co.uk/cbeebies/programmes/schedules/%s' % date.format('YYYY/MM/DD')))
for series in soup.findAll('span', resource=re.compile(PID)):
root = series.findParents(typeof="BroadcastEvent")[0]
season = root.find(typeof='TVSeason')
start_time = root.find(property='startDate')['content']
title = season.nextSibling.string
series_num = season.find(property='name').string
episode_num = root.find('abbr').find(property='position').string
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('args', nargs='*') # from __init__.py execute()
parser.add_argument('args', nargs='+') # from base.py LabelCommand add_arguments
print parser.parse_args(['foo1', 'foo2', 'foo3', 'foo4'])
# Outputs Namespace(args=['foo4'])
@dracos
dracos / output.txt
Created December 24, 2016 20:17
Days when other festivals overlap Christmas Day
Hanukah
[...]
1902-12-24
1905-12-22
1908-12-18
1910-12-25
1913-12-23
1916-12-19
1921-12-25
1924-12-21
@dracos
dracos / microproxy.py
Created December 18, 2016 11:26
A very small python HTTP proxy
#!/usr/bin/env python
"""
Microproxy
This code is based on http://pastebin.com/mdsAjhdQ based on code based on microproxy.py written by ubershmekel in 2006.
Microproxy is a very small HTTP proxy. It relays all bytes from the client to the server at a socket send and recv level.
It looks at the Host: header to recognise where to connect to.
"""
@dracos
dracos / venv-setup.sh
Created March 10, 2016 13:56
Installing python2 & python3 and virtualenv (Ubuntu 14.04)
# Python 2
sudo apt-get install python-pip
pip install --user virtualenv
python ~/.local/bin/virtualenv venv2
# Python 3, option 1
sudo apt-get install python3-pip
pip3 install --user virtualenv
python3 ~/.local/bin/virtualenv venv3
# Python 3, option 2
sudo apt-get install python3.4-venv
1,2c1
<
< <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
---
> <!DOCTYPE html>
18a18,58
> <meta name=viewport content="initial-scale=1">
> <style>
> @media (max-width: 730px) {
>
$ cpanm -L local Catalyst
$ cpanm -L local Catalyst::Devel
$ cpanm -L local Catalyst::View::TT
$ PERL5LIB=local/lib/perl5 local/bin/catalyst.pl MyApp
$ cd MyApp/
$ PERL5LIB=../local/lib/perl5 script/myapp_create.pl view Web TT
$ vim lib/MyApp/Controller/Root.pm # Change index line to $c->stash->{template} = 'foo.html';
$ PERL5LIB=../local/lib/perl5 script/myapp_server.pl
[info] *** Request 1 (0.200/s) [89599] [Thu Oct 8 17:44:14 2015] ***
[debug] Path is "/"