Skip to content

Instantly share code, notes, and snippets.

View luerhard's full-sized avatar

Lukas Erhard luerhard

  • University of Stuttgart
  • Germany
View GitHub Profile
@luerhard
luerhard / edge_gravity.py
Last active January 20, 2019 13:56
This calculates edge gravity for directed networks. It is cythonized and to be used in a jupyter notebook
%%cython
from collections import defaultdict, Counter
from concurrent.futures import ProcessPoolExecutor
from itertools import islice
import math
from multiprocessing import cpu_count
import random
import networkx as nx
@luerhard
luerhard / linux_on_thinkpad.md
Last active October 11, 2018 23:24
Funny things and tricks I found out about Linux Mint configuration options and bugfixes

Fix Two-Finger-Scroll Bug on Lenovo Thinkpad (multiple versions)

A lot of people have problems with the Touchpad on Thinkpads after suspends in multiple kernel versions. A lot of times, the scrolling does not work anymore after wakeup. Here is a way to fix it.

  • go to /etc/default/grub
  • find the line GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
  • change the line to GRUB_CMDLINE_LINUX_DEFAULT="quiet splash psmouse.synaptics_intertouch=0"
  • execute command in terminal "sudo update-grub"
  • restart

Width of Jupyter Noteboooks

@luerhard
luerhard / example_for_data_school.ipynb
Last active February 6, 2018 16:56
my example for data school
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@luerhard
luerhard / SqliteCorpusReader.py
Last active January 20, 2018 11:17
A SqliteCorpusReader for nltk. To use it, instantiate a SqliteCorpusReader-Instance with keyword-arguments dbpath, table and field. to directly access other columns, add methods like SqliteCorpusReader.timestamps or .articles oder .folder. It recognizes the DB-Structure automatically.
import sqlite3 as sq
from nltk.data import LazyLoader
from nltk.util import AbstractLazySequence, LazyMap, LazyConcatenation
from nltk.tokenize import WordPunctTokenizer, sent_tokenize
from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine
from sqlalchemy.inspection import inspect
import logging
def setup_logging(file_level=logging.DEBUG, filename='logfile.log', mode="w", console_level=logging.WARNING):
'''
Creates logger with file and console support and different logging levels.
'''
if not logging.getLogger().handlers:
file_handler = logging.FileHandler(filename=filename, mode=mode, delay=False, encoding='utf-8')
file_formatter = logging.Formatter('%(message)s')
@luerhard
luerhard / BokehGraph.py
Last active April 16, 2021 18:45
The BokehGraph class creates super easy to use interactive plots for one-mode networkx graphs. Hover over nodes to see their attributes and color nodes by communities as shown in the docstring.
import networkx as nx
from collections import namedtuple
from math import sqrt
import bokeh
from bokeh import models, plotting, io
from bokeh.colors import RGB
import random
#corresponding package on pypi is confusingly called python-louvain
@luerhard
luerhard / rtf_to_txt.py
Created May 12, 2017 22:58
Script that converts all .rtf-files in a Folder to .txt on Linux
import subprocess
import os
cwd = os.getcwd()
complete_dir = os.listdir()
rel_docs = [doc for doc in complete_dir if doc.endswith('.rtf')]
for doc in rel_docs:
if doc.find('(') != -1:
doc = "'{}'".format(doc)
@luerhard
luerhard / send_email.py
Last active July 3, 2017 12:47
Send email from within a python script from one email-adress to another
import smtplib
from email.mime.text import MIMEText
from email.header import Header
def send_mail(message, *subject,**kwargs):
smtp_host = 'smtp.xxx.de'
login, password = 'login-email', 'password'
recv = 'receiving-email'