Skip to content

Instantly share code, notes, and snippets.

@dwerbam
dwerbam / run_wireguard.sh
Last active June 11, 2022 22:53
wireguard vpn setup
docker run \
-d \
--name=wireguard \
--cap-add=NET_ADMIN \
--cap-add=SYS_MODULE \
-e PUID=1000 \
-e PGID=1000 \
-e TZ=Europe/Madrid \
-e SERVERURL=3.71.216.2 \
-e SERVERPORT=51820 \
@dwerbam
dwerbam / modal_asyncawait.js
Created December 23, 2021 09:31
creating modal popups in javascript and keeping async/await thread
const modalWaitElem = async selector => {
while ( document.querySelector(selector) !== null) {
await new Promise( _ => setTimeout(_, 500) )
// // faster than setTimeout (not needed)
// await new Promise( _ => requestAnimationFrame(_) )
}
return document.querySelector(selector)
};
async function createVisualElement(parent, className) {
@dwerbam
dwerbam / runPysparkFromR.R
Last active October 24, 2021 08:52
run pyspark copy/move from R
library(processx)
library(stringr)
runPysparkCopy <- function(fsFrom, fsTo, move=FALSE) {
pyscript_file <- tempfile(tmpdir="/tmp")
fileh<-file(pyscript_file)
copy_or_move <- if(move) "mv" else "cp"
writeLines(stringr::str_interp("
from pyspark.dbutils import DBUtils
from pyspark.context import SparkContext
@dwerbam
dwerbam / RayParallelExec.py
Created October 9, 2021 23:29
example of how to use ray.io to execute multiple OS processes in parallel (something like GNU parallel is doing)
# example of how to use ray.io to execute multiple
# OS processes in parallel (even in multiple machines)
# (something like GNU parallel is doing)
pip install -U "ray[default]"
import ray
import os
import time
@dwerbam
dwerbam / case_when_raw.r
Last active October 8, 2021 06:40
spark case_when raw implementation
dfletters <- data.frame(letter=letters)
sparkletters <- sdf_copy_to(sc, dfletters, 'sometable', overwrite=T)
# or using sdf_register(name='sometable')
sparkletters
df2 <- sdf_sql(sc, "select letter as A1,
CASE WHEN letter = 'b' OR letter='d'
THEN 'itsBorD'
ELSE
CASE WHEN letter = 'c'
@dwerbam
dwerbam / loglapse.py
Last active October 4, 2021 08:16
calculates the time difference between the log lines and writes the 'next' line with the prefixed time lapse
## calculates the time difference between the log lines
## and writes the 'next' line with the prefixed time lapse
## use: python3 logplapse.py some.log > ts.log
from datetime import datetime
import re
import sys
FMT = '%Y-%m-%d %H:%M:%S'
TS_REGEXP = '\[([0-9:\- ]+)\]'
SPACER = "| ".rjust(10)
@dwerbam
dwerbam / sapo.ps1
Created March 19, 2020 10:59
SAP analysis for office automation
# CONFIGURE
## set environment variables SAP_ANALYSIS_USER and SAP_ANALYSIS_PASS
# TO ENABLE EXECUTION (if you see SecurityError:UnauthorizedAccess)
## 1. open a powershell console as Administrator
## 2. run "set-executionpolicy remotesigned"
# TO RUN
## 1. open powershell
## 2. run "./sapo.ps1 -file FULL_PATH_TO_EXCEL.xlsx"
@dwerbam
dwerbam / README.md
Created June 30, 2019 08:16
open steganos + cryptography in binder

Binder

@dwerbam
dwerbam / steganos.ipynb
Created June 30, 2019 07:32
Steganos with cryptography.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dwerbam
dwerbam / change_lid_action.sh
Created November 5, 2017 11:51
ubuntu change lid action: ignore, suspend, hibernate
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
replace_var_in_file() {
VAR=$1
VALUE=$2
FILENAME=$3