Skip to content

Instantly share code, notes, and snippets.

View tbrlpld's full-sized avatar

Tibor Leupold tbrlpld

View GitHub Profile
@tbrlpld
tbrlpld / dynamic_square.html
Last active March 21, 2018 21:12
Square web element with dynamic size in pure CSS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
.square_spacer {
width: 300px;
background-color: steelblue;
border: solid;
position: relative;
@tbrlpld
tbrlpld / center_vert_hor.css
Created March 25, 2018 13:08
Center div in div, vertically and horizontally
.center-vertical-horizontal{
margin: 0;
position: absolute;
/* top and left define the position of the object relative to the parent in
dimensions of the parent.*/
top: 50%;
left: 50%;
/* transform translate shifts the element aways from the defined position
in dimensions of it self. That means these 50% are 50% of the element sizes
them selfs.*/
@tbrlpld
tbrlpld / lazylogging.py
Last active April 15, 2020 17:13
Avoid function execution for not logged messages
import logging
logger = logging.getLogger(__name__)
# Log level is INFO. So anything of lower level (DEBUG) should not execute
logger.setLevel(logging.INFO)
stream_handler = logging.StreamHandler()
logger.addHandler(stream_handler)
@tbrlpld
tbrlpld / randavg.py
Created April 15, 2020 17:18
Checking the average return value of Python's random
# -*- coding: utf-8 -*-
"""Checking the return of random number generator."""
from random import random
def random_avgerage(trails):
"""Return average of a given number of randomly generated numbers."""
@tbrlpld
tbrlpld / singleton.py
Created April 15, 2020 17:29
Python singleton
# -*- coding: utf-8 -*-
"""Trying to create a singleton."""
class Singleton(object):
"""The public class."""
instance = None
@tbrlpld
tbrlpld / decor.py
Created April 15, 2020 17:36
Python decorators
print(" NO AGRUMENTS ".center(30, "#"))
def this_adds_decoration(function_to_decorate):
def this_creates_decoration():
print("Before")
function_to_decorate()
print("After")
# Return the created decoration to add it to a function
@tbrlpld
tbrlpld / tunnel.py
Created April 15, 2020 17:38
Establish ssh tunnel via Python
import os
import time
from sshtunnel import SSHTunnelForwarder
# Set the environment variable that contains the passphrase for the given
# private key file.
KEY_PASSPHRASE = os.environ.get("SSH_PRIVATE_KEY_PASSPHRASE")
@tbrlpld
tbrlpld / base.css
Last active May 21, 2020 00:02
My basic CSS resets
* {
box-sizing: border-box;
font-family: 'Helvetica Neue', Arial, sans-serif;
}
html,
body,
h1,
h2,
@tbrlpld
tbrlpld / classinitnone.py
Last active April 23, 2020 00:14
Just playing around with the class init method and its return values
# -*- conding: uft-8 -*-
"""Just playing around with the class init method."""
class InitReturnNone():
def __init__(self, var):
self.var = var
return None
@tbrlpld
tbrlpld / email_via_sendgrid_client.py
Last active April 23, 2020 03:15
Send emails with Python (and Sendgrid)
# from here: https://github.com/sendgrid/sendgrid-python#quick-start
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
message = Mail(
from_email='alice@example.com',
to_emails='bob@example.com',
subject='Sending with Twilio SendGrid is Fun',