Skip to content

Instantly share code, notes, and snippets.

@davidlenz
davidlenz / stopwords.py
Last active June 5, 2018 10:26
Function to generate a list of stopwords from different sources.
import stop_words
from langdetect import detect
import nltk
nltk.download('stopwords')
from nltk.corpus import stopwords
import ast
@davidlenz
davidlenz / spacy_lemmatizer.py
Last active May 25, 2018 09:57
Usage of Spacy lemmatizer. Convert list of strings to lemmatized version.
import spacy
settings.LEMMATIZER_BATCH_SIZE = 250
settings.LEMMATIZER_N_THREADS = -1
nlp = spacy.load('de')
nlp.disable_pipes('tagger', 'ner')
def spacy_lemmatizer(text, nlp):
"""text is a list of string. nlp is a spacy nlp object. Use nlp.disable_pipes('tagger','ner') to speed up lemmatization"""
@davidlenz
davidlenz / textblob_de_lemmatizer.py
Created May 25, 2018 09:55
Usage of german textblob lemmatizer. Takes a list of strings and returns the lemmatized version.
from textblob_de import TextBlobDE as TextBlob
def textblob_lemmatizer(doclist):
"""Takes a list of strings as input and returns a list of lemmatized strings"""
docs=[]
for doc in doclist:
blob = TextBlob(doc)
docs.append(' '.join(list(blob.words.lemmatize())))
return docs
@davidlenz
davidlenz / arxiv_query.py
Last active June 4, 2018 17:51
Download pdf files from arxiv based on a search query. https://github.com/lukasschwab/arxiv.py
import time, os
import arxiv
QUERY = 'ECB'
NUM_RESULTS = 10 #
SLEEPTIME = 0.1 # seconds
savedir = './arxiv_papers/{}/'.format(QUERY)
if not os.path.exists(savedir):
os.makedirs(savedir)
@davidlenz
davidlenz / collect_environment.py
Last active June 16, 2018 18:39
Collect environment information and store to file.
import socket
import os, json
import pip, sys
import platform
env = {}
import aetros
env['aetros_version'] = aetros.__version__
@davidlenz
davidlenz / 20_newsgroup_to_csv.py
Last active July 1, 2025 06:18
20 newsgroup dataset from sklearn to csv.
from sklearn.datasets import fetch_20newsgroups
import pandas as pd
def twenty_newsgroup_to_csv():
newsgroups_train = fetch_20newsgroups(subset='train', remove=('headers', 'footers', 'quotes'))
df = pd.DataFrame([newsgroups_train.data, newsgroups_train.target.tolist()]).T
df.columns = ['text', 'target']
targets = pd.DataFrame( newsgroups_train.target_names)
@davidlenz
davidlenz / heise_scraper.py
Last active August 6, 2019 18:12
Scrape the heise newsticker archive (https://www.heise.de/newsticker/archiv) using beatifulsoup.
import requests
import bs4 as bs
from bs4 import BeautifulSoup
import pandas as pd
import os
def get_timestamp():
import time, datetime
date_n_time = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d %H-%M-%S')
return date_n_time
@davidlenz
davidlenz / sendmails.py
Created July 25, 2018 09:40
Send Emails using python.
#!/usr/bin/env python
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib
subject = 'Example header'
message = 'Subject: Happy Australia Day!\nHi Everyone! Happy Australia Day! Cheers, Julian'
@davidlenz
davidlenz / Export-Chocolatey.ps1
Created May 17, 2019 14:16 — forked from alimbada/Export-Chocolatey.ps1
Export installed Chocolatey packages as packages.config - thanks to Matty666
#Put this in Export-Chocolatey.ps1 file and run it:
#Export-Chocolatey.ps1 > packages.config
#You can install the packages using
#choco install packages.config -y
Write-Output "<?xml version=`"1.0`" encoding=`"utf-8`"?>"
Write-Output "<packages>"
choco list -lo -r -y | % { " <package id=`"$($_.SubString(0, $_.IndexOf("|")))`" version=`"$($_.SubString($_.IndexOf("|") + 1))`" />" }
Write-Output "</packages>"
@davidlenz
davidlenz / cancel jobs in aws batch job queue
Last active February 25, 2022 17:41
cancel all jobs in a job queue
import time
import boto3
job_queue = <'job-queue-name'>
client=boto3.client("batch")
states = ['RUNNABLE','SUBMITTED','PENDING','STARTING','RUNNING']
for state in states:
print(state)