Skip to content

Instantly share code, notes, and snippets.

@svenk
svenk / demo.sh
Created May 28, 2013 08:56
Das Bash-1x1 für den theoretischen Physiker, der C(pp) mit GCC programmiert
# Begrifflichkeiten: Shell = Kommandozeile Linux, Bash = Verbreitestes Shell-Programm
Angenommen du hast ein C++-File namens "hello.cc"
#include <stdio.h>
int main() {
printf("Hallo Welt\n");
return 0;
}
@svenk
svenk / website-notify.sh
Created July 22, 2013 08:48
A website change checker / detection changer / script to keep track of changes of any website (URL). Intended to be run on a 24/7 running server like a login server in your university institute.
#!/bin/bash
#
# Notify when website changes-script:
# This is a simple mini program that informs you whenever a website
# changes. Can perform any job when triggered.
# Usage:
# ./notify "jobname fuer mail" "http://abc.def/interessant.html"
# The script will run "in foregrund". You can e.g. use GNU screen to detach it
# and run it in the background on a 24h-running-server:
# $ screen
@svenk
svenk / PyPunchcards
Last active January 24, 2016 18:07
Proposal for Punchcard modeling in Python
This gist was an experiment to explore ways to model punch cards with Python nicely.
Focus was spent on good reability/introspection and fault tolerance (incomplete
punch cards/tristates) and not on performance.
@svenk
svenk / 3FarbenLED.cpp
Last active November 2, 2016 18:40
3Farben LED Arduino für Heribert
/**
* Kommentierte Fassung fuer ein Arduino-Testprogramm
**/
// Anschlussbelegung:
#define PIN_ROT 2
#define PIN_GRUEN 3
#define PIN_BLAU 4
// Taste (Button) an Pin 7 anschließen!
@svenk
svenk / Makefile
Created December 15, 2016 22:16
Some Fortran/C linking test
CC=gcc
F90=gfortran
all:
${CC} -Wall -c main.c
${F90} -c aux.f90
${CC} -o test main.o aux.o -lgfortran
clean:
rm *.o test
@svenk
svenk / snippet.py
Created September 10, 2018 21:37
Python: Display scientific number with 10 power something (suitable for LaTeX) instead of the "e" suffix
import re
sci = lambda d: re.sub(r'e\+?(-?)?0?(\d+)', r" x 10^{\1\2}" ,"%.2e"%d)
"""
### Examples:
In [34]: sci(1)
Out[34]: '1.00 x 10^{0}'
@svenk
svenk / yaml-reader.php
Created November 3, 2017 17:53
Multi document YAML reader for PHP
<?php
/*
* There is currently no pure PHP yaml parser capable of reading
* multi documents (--- separated). I have tested both spyc and Symfony's YAML.
*
* Therefore I parse YAML with Python, encode it to json and read the json in
* PHP. The json is cached on disk.
*
* Public Domain by http://github.com/svenk
*/
@svenk
svenk / ViewSourceWith.ps1
Created November 17, 2017 11:59
A Firefox Quantum ViewSourceWith extension workaround with Firefox's source.editor.external
# A Firefox Quantum ViewSourceWith replacement for Windows
#
# Usage:
# (1) Save as C:\path\to\script.ps1
# (2) In order to run your own powershell scripts, start PowerShell
# as Administrator and run the command
#
# Set-ExecutionPolicy RemoteSigned
#
# (2) You can test the proper running (from a user cmd):
@svenk
svenk / resolver.c
Created November 21, 2017 12:26
ViewSourceWith.cpp
/**
* A Firefox Quantum ViewSourceWith replacement for Windows.
* When compiled, this behaves like an editor, i.e. you call
* it with a file as an argument. It tries to extract then
* the real file to open.
*
* Todo:
*
* 1) Read editor path from INI file with GetPrivateProfileString
* 2) hide the console when opening the real notepad
@svenk
svenk / vprintf.cpp
Created July 3, 2019 08:19
Convenient C's printf in C++
// this is a buffer-overflow-safe version of sprintf
// source: http://stackoverflow.com/a/69911
// if you need something more mature, consider https://github.com/fmtlib/fmt
// the advantage of this snippet is that it can be really easily added to smallish
// codes/libraries. Usage is like C's vprintf et al. but with a C++ std::string as a result.
std::string vformat (const char *fmt, va_list ap) {
// Allocate a buffer on the stack that's big enough for us almost
// all the time. Be prepared to allocate dynamically if it doesn't fit.
size_t size = 1024;
char stackbuf[1024];