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 / f_to_c.rs
Created September 15, 2018 12:03
Fahrenheit to celsius
// Fahrenheit to Celsius
// (F - 32) * (5/9) = C
use std::io;
fn main() {
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
@tombasche
tombasche / rando_ts.rs
Created September 15, 2018 10:35
Oxidised random tea
extern crate sqlite;
use std::fs::File;
use std::io::{BufRead, BufReader};
fn db_connection(db_name: &String) -> sqlite::Connection {
let connection = sqlite::open(db_name).unwrap();
connection.execute("CREATE TABLE teas (name text, variety text, last_used date)").unwrap();
@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()