Skip to content

Instantly share code, notes, and snippets.

View kkroesch's full-sized avatar

Karsten Kroesch kkroesch

View GitHub Profile
@kkroesch
kkroesch / ips.py
Last active January 28, 2019 14:58
Iterate IP range
from ipaddress import ip_address
""" Two IP addresses are known """
start = ip_address('192.168.1.0')
end = ip_address('192.168.1.254')
print("From {} to {}".format(start, end))
for ip in range(int(start), int(end)):
print(ip_address(ip))
""" Network address is known """
@kkroesch
kkroesch / aes.py
Created January 11, 2019 11:18
Ecryption/Decryption REST Service
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Ecryption/Decryption REST Service
=================================
INSTALLATION
------------
@kkroesch
kkroesch / mailbox.cql
Last active April 11, 2018 07:56
Storing mail metadata in Cassandra DB.
CREATE KEYSPACE mail
WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
CREATE TABLE mailbox (
box_id text, year int,
received timestamp,
@kkroesch
kkroesch / test_certificate.py
Last active March 27, 2018 09:09
Test the expiry of a SSL certificate.
"""
Test validity of certificates.
Tested on Ubuntu with Python 3.5 and python3-openssl package.
"""
import ssl
from datetime import datetime
from warnings import warn
@kkroesch
kkroesch / search_query.py
Created October 18, 2016 15:37
A primitive search for keywords in a text.
import string
from collections import Counter
george_takei_tweet = "When the media gave him millions in free air time, Trump loved them. Now when they do their job and ask questions, it's a global conspiracy."
tweet = george_takei_tweet.lower()
tweet = ''.join(ch for ch in tweet if ch not in set(string.punctuation))
contains = Counter(tweet.split(' '))
eval("contains['trump'] and contains['conspiracy']")
# ==> 1
@kkroesch
kkroesch / gallery.sh
Last active October 11, 2016 08:06
Minimalistic approach to create a gallery page from image directory.
@kkroesch
kkroesch / isnat.sh
Created July 13, 2016 12:45
Figure out if your computer is behind NATing firewall.
INTERFACE=$(ifconfig en0 | grep 'inet ' | cut -f2 | awk '{ print $2}')
PUBLIC=$(curl -s http://ifconfig.co)
[ $INTERFACE = $PUBLIC ] || echo NAT
@kkroesch
kkroesch / asset_finder.py
Created June 30, 2016 10:34
Finds references to external scripts and stylesheets from HTML page and prints download instructions for those files.
import sys
import argparse
from HTMLParser import HTMLParser
file_list = []
class AssetFinder(HTMLParser):
def handle_starttag(self, tag, attrs):
@kkroesch
kkroesch / index.htm
Created June 28, 2016 13:51
Angular Material Start
<html lang="en" >
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style type="text/css">
.location-item { padding: 0.5em; cursor: pointer; }
.level-2 { padding-left: 1.5em; }
.level-3 { padding-left: 2.5em; }
.level-4 { padding-left: 3.5em; }
@kkroesch
kkroesch / app.js
Last active April 18, 2016 12:12
Failsafe setting of NODE_PATH in scripts. Put this line before importing your own modules to avoid statements like `require('../../middleware')'.
process.env.NODE_PATH || (process.env.NODE_PATH = __dirname)