Skip to content

Instantly share code, notes, and snippets.

View tombasche's full-sized avatar

Thomas Basche tombasche

  • Helsinki, Finland
View GitHub Profile
@tombasche
tombasche / random.html
Created September 3, 2018 09:40
Generate random numbers up to 10
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Maths Group - Negative Numbers</title>
<style>
.header-body {
width: 100%;
height: 100%;
text-align: center;
@tombasche
tombasche / validate_email.py
Last active July 20, 2018 20:28
Simple function and test to show off hypothesis
import re
from hypothesis import given, strategies as st
EMAIL_REGEX = re.compile(r'[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+')
def validate_email(email):
""" Validates an email address"""
if EMAIL_REGEX.match(email):
@tombasche
tombasche / process.py
Created August 17, 2017 22:52
Index a json file into elasticsearch pip install elasticsearch
import json
import sys
import elasticsearch
def send_to_es(payload, _id, list_name):
es = elasticsearch.Elasticsearch()
es.index(index=list_name, doc_type='item', id=_id, body=payload)
@tombasche
tombasche / scan.py
Created April 11, 2017 09:53
Python port scanner
import socket
import subprocess
import sys
url = str(sys.argv[1])
remoteIp = socket.gethostbyname(url)
print "Scanning " + url + " (" + remoteIp + ")"
try:
for port in range(1,5000):
@tombasche
tombasche / urlfuzzer.py
Last active April 11, 2017 09:54
Fuzzer to find folders and common files on websites
import requests
import os, sys
url = sys.argv[1]
dicts_dir = sys.argv[2]
result_dir = sys.argv[3]
def import_dict(dir, filepath):
file = open(os.path.join(dir,filepath), 'r')
return [item for item in file]
@tombasche
tombasche / popclock.py
Last active March 1, 2017 22:15
Population Clock - using the ABS population API
import requests, json, time, os
ABS_URL = 'http://www.abs.gov.au/api/demography/populationprojection'
def getData():
r = requests.get(ABS_URL)
return json.loads(r.text)
def getPopulation():
text = getData()
param (
[Parameter(Mandatory=$true)][string]$Hostname
)
$failure = ""
while (!$failure) {
try {
$net = [System.Net.Dns]::GetHostAddresses($Hostname)
$Host.UI.RawUI.BackgroundColor = ($bckgrnd = 'DarkGreen')
} catch [Exception] {
$failure = "yes"
@tombasche
tombasche / merge.py
Last active January 12, 2017 22:48
Merges all pdf files in a directory (needs pypdf - get using pip). Instructions: pip install pillow pip install pypdf Backup any images first Ensure any mergedpdf files are deleted run python merge.py in the directory with the images/pdfs
import os
import copy
from PIL import Image
from pyPdf import PdfFileWriter, PdfFileReader
def append_pdf(input,output):
[output.addPage(input.getPage(page_num)) for page_num in range(input.numPages)]
output = PdfFileWriter()
cwd = os.getcwd()
@tombasche
tombasche / cdver.py
Last active November 4, 2016 08:03
Dronever
#inspired by http://cube-drone.com/comics/c/version-sacrifice
# note: you'll need to pip install pygithub
import time
import urllib2
import random
from github import Github
def nvl(var, val):
if var is None:
return val
@tombasche
tombasche / removeEmptyFolders.bat
Created April 30, 2016 06:52
Run in a directory to remove all empty folders (in windows)
for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do rd "%%d"