Skip to content

Instantly share code, notes, and snippets.

View cutterkom's full-sized avatar

Katharina Brunner cutterkom

View GitHub Profile
@cutterkom
cutterkom / redirect category to post
Last active September 20, 2020 20:28
WordPress: Redirect from category.php to first post in category
function strytllr_redirect_from_story_to_first_slide(){
global $wp_query;
if( is_archive() && $wp_query->query('showposts=1&order=ASC') ){
the_post();
// Get permalink
$post_url = get_permalink();
// Redirect to post page
wp_redirect( $post_url );
}
}
@cutterkom
cutterkom / r_to_nextcloud.R
Created June 22, 2019 10:04
Uploading a file to Nextcloud from R via webdav
library(httr)
# webdav target and login
dav <- "https://your-nextcloud.com/remote.php/webdav"
username <- "<username>"
password <- "<password>"
# the file to upload
img <- "image.png"
@cutterkom
cutterkom / humidity_telegram.py
Created November 23, 2019 15:03
Measure humidity and temperature with a Raspberry Pi, save the result as a csv file and send a Telegram message
### Measure Temperature and Humidity very 30 secs and save it csv file
# code https://pimylifeup.com/raspberry-pi-humidity-sensor-dht22/
### Create a Telegram Bot
# - create a bot by texting to BotFather `/newbot` and receive a token
# - go to `https://api.telegram.org/botYOUR_TOKEN/getUpdates`
# - send a text to your bot
# - the JSON on `https://api.telegram.org/botYOUR_TOKEN/getUpdates` will update and you get the `chat_id`
# send a message to chat: `https://api.telegram.org/botYOUR_TOKEN/sendMessage?chat_id=CHAT_ID&text=I+can+talk+to+you`
# link: [Creating a Telegram bot for personal notifications](https://www.forsomedefinition.com/automation/creating-telegram-bot-notifications/)
@cutterkom
cutterkom / delete_shiny.md
Created December 9, 2020 08:45
how to delete shiny from a linux server
  • Delete/Remove Software/Package, Link

    1. Search in list of packages with dpkg --list
    2. Find name of package and delete sudo apt-get --purge remove shiny-server
    • --purge removes config files, too
    • --autoremove: delete unused packages
    • in combination sudo apt-get --purge --autoremove remove shiny-server
    1. maybe also look for all files with the package name and delete them: find -name shiny-server
  • Find all files with string in name: find -name string

  • Find all files with string and delete them: ``find . -name "FILE-TO-FIND" -exec rm -rf {} ;` (folder, too), link

@cutterkom
cutterkom / get_var.R
Created December 9, 2020 08:46
get column stored as variable in R, alternative zu eval()
# get column stored as variable
# alternative to eval()
column <- "name"
df %>% filter(get(column)==1)
@cutterkom
cutterkom / save-df-as-xlsx-group-var-as-sheet.R
Last active October 14, 2021 13:34
R: Save a dataframe als xlsx with each group a separate sheet
# Save a dataframe als xlsx with each group a separate sheet
# plus formatting and highlighting
library(dplyr)
library(purrr)
library(openxlsx)
# some configs
filename <- "test.xlsx"
@cutterkom
cutterkom / spacy_german_address_patterns.py
Last active April 14, 2022 10:26
Spacy German address patterns
# Goal: Fetch German street addresses
# Works on:
# Müllerstr. 26
# Müllerstr 26
# Müllerstraße
# Müllerstraße 26
# Müllerplatz
# Müllerstraße 26a
# Müller Straße 26
@cutterkom
cutterkom / spacy_german_date_patterns.py
Created April 11, 2022 14:43
Spacy German date patterns
date_marker_start = "[Aa]b$|[Zw]ischen$|[Bb]is$|[Ss]eit$|[Vv]on$"
date_marker_between = "\\-|und|bis"
date_marker_decade = "er|er Jahre"
day = "0?[1-9]|[12]\d|3[01]"
month = "Januar|Februar|März|April|Mai|Juni|Juli|August|September|Oktober|November|Dezember|0?1\.|0?2\.|0?3\.|0?4\.|0?5\.|0?6\.|0?7\.|0?8\.|0?9\.|10\.|11\.|12\."
year = "[12][0-9]{3}" # years from 1000 to 2999
decade_years = "[12][0-9]{2}0ern?" # 1970er, 1990er
daymonthyear = "^(((0?[1-9]|[12]\d|3[01])\.(0[13578]|[13578]|1[02])\.((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|[12]\d|30)\.(0[13456789]|[13456789]|1[012])\.((1[6-9]|[2-9]\d)\d{2}))|((0?[1-9]|1\d|2[0-8])\.0?2\.((1[6-9]|[2-9]\d)\d{2}))|(29\.0?2\.((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$" # all combinations of German compact dates
@cutterkom
cutterkom / nunjucks_obsidian_hypothesis.js
Created November 7, 2022 13:20
Obsidian Hypothes.is Export Template
{% if is_new_article %}
# {{title}} - hypothes.is
## Metadata
{% if author %}{{author}}{% endif %}, {{title}}, {% if url %}{{url}}{% endif %}
{% endif %}
{%- if is_new_article %}
{% if page_notes|length %}
## Page Notes
@cutterkom
cutterkom / df_to_sqlite.R
Created June 3, 2023 17:00
Create sqlite from R dataframes
library(DBI)
library(tidyverse)
# Import SPSS -------------------------------------------------------------
cleaned_dataframe_with_spss_data <- ....
# Write to DB -------------------------------------------------------------