Skip to content

Instantly share code, notes, and snippets.

View thannaske's full-sized avatar
🏠
Working from home

Tobias thannaske

🏠
Working from home
View GitHub Profile
@thannaske
thannaske / gist:560abbbbe9e6382fe6869e366bd931ff
Created June 15, 2016 15:30
Send a Pushover notification when @RMVInfo tweets about a subway- or train-line I take
#!/usr/bin/python
import json
import datetime
import httplib
import urllib
import sys
from tweepy import Stream, OAuthHandler
from tweepy.streaming import StreamListener
@thannaske
thannaske / search_dict.py
Last active July 8, 2016 10:17
Search a Python dictionary recursively for a specified key value pair
'''
Search dictionary d containing other dictionaries or lists recursively for a specified key k with value v
dict d: Dictionary to search through
string k: Key to search for
object v: Value the key shall have
'''
def search_key_value(d, k, v):
if isinstance(d, dict):
for key, value in d.iteritems():
@thannaske
thannaske / gist:46ed02a23217afd515504cd008ef8562
Created November 4, 2016 17:27
Let's Encrypt Auto-Renew
# Assuming you are running Apache2 and managing the certificates yourself
certbot-auto renew --standalone --non-interactive -m [email protected] --force-renewal --agree-tos --no-self-upgrade --pre-hook "service apache2 stop" --post-hook "service apache2 start" --quiet
@thannaske
thannaske / combine-certificates.py
Created November 14, 2016 21:27
Combine Let's Encrypt certificate files to a fully combined PEM certificate that is compatible with LiveConfig
import argparse
parser = argparse.ArgumentParser(description='Combines Let\'s Encrypt certificate to a fully PEM certificate file to use with LiveConfig.')
parser.add_argument('private_key', action='store', help='Path to private key file')
parser.add_argument('full_chain', action='store', help='Path to full chain certificate file')
parser.add_argument('output', action='store', help='Output file for combined PEM certificate')
args = parser.parse_args()
try:
@thannaske
thannaske / create_users_table.php
Created May 18, 2018 17:48
Migration for the Laravel e-mail address confirmation functionality
<?php
public function up()
{
Schema::create('users', function (Blueprint $table) {
// Default Laravel stuff
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
<?php
// [...]
/**
* Generate a random hexadecimal token by hashing the current time in microseconds as float
*
* @return string Random 32-characters long hexadecimal token
*/
public static function generateToken() {
<?php
// [...]
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
<?php
// [...]
/**
* Perform the confirmation of the user's e-mail address.
*
* @param User $user The provided user instance
* @param $token string The provided confirmation token
* @return mixed
<?php
// [...]
Route::get('users/{user}/{token}/confirm', 'Auth\\RegisterController@confirm')->name('confirm');
// [...]
<?php
// [...]
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/