Skip to content

Instantly share code, notes, and snippets.

@DrAzraelTod
DrAzraelTod / duh.sh
Created January 10, 2022 14:17
actually just some alias, living in my bashrc not it's own shell script
#!/bin/sh
# small tool to make du default to -h and -d1
# also to sort output
if [ "$#" -ne 1 ]; then
du -hd1 . | sort -h;
else
du -h $@ | sort -h;
fi
@DrAzraelTod
DrAzraelTod / random_enum.java
Last active April 10, 2018 09:48
get a random enum
public static <ENUM_KIND extends Enum<?>> ENUM_KIND rndEnum(final Class<ENUM_KIND> enumType) {
final ENUM_KIND[] enumValues = enumType.getEnumConstants();
if (enumValues.length > 0) {
int rnd = new Random().nextInt(enumValues.length);
return enumValues[rnd];
} else {
// yeah, ok.. nobody knows that kind of exception
// do something else instead
throw EnumNotImplementedException.of(enumType);
}
@DrAzraelTod
DrAzraelTod / reduceSpecialChars.js
Last active February 9, 2018 14:17
quick and dirty way to clean a string from any non-word-characters, while keeping something that looks similar
var reduceSpecialChars = function(input) {
let normalized = input.toLocaleLowerCase().normalize("NFKD");
normalized = normalized.replace("ß","ss");
bytes = [];
for (var i = 0; i < normalized.length; ++i)
{
charCode = normalized.charCodeAt(i);
bytes.push(charCode & 0xFF);
}
temp = "";
@DrAzraelTod
DrAzraelTod / reduceSpecialChars.js
Created February 9, 2018 14:13
quick and dirty way to clean a string from any non-word-characters, while keeping something that looks similar
var reduceSpecialChars = function(input) {
let normalized = input.normalize("NFKD");
normalized = normalized.replace("ß","ss");
bytes = [];
for (var i = 0; i < normalized.length; ++i)
{
charCode = normalized.charCodeAt(i);
bytes.push(charCode & 0xFF);
}
temp = "";
@DrAzraelTod
DrAzraelTod / format_number.js
Created December 13, 2017 10:13
schamlos kopiert von irgendwoher
function change(strZahl){
// Mögliche Dezimalstellen auf 2 Stellen runden und Dez-Punkt durch Komma ersetzen
strZahl = String(Number(strZahl).toFixed(2)).replace(/\./,",");
// Solange noch mindestens vier Ziffern am Anfang gefunden werden
while(strZahl.match(/^(\d+)(\d{3}\b)/)){
// Tausendertrennzeichen einfügen
strZahl = strZahl.replace(/^(\d+)(\d{3}\b)/, RegExp.$1 + "." + RegExp.$2);
}
@DrAzraelTod
DrAzraelTod / Windows10-Setup.ps1
Created October 5, 2017 17:24 — forked from NickCraver/Windows10-Setup.ps1
(In Progress) PowerShell Script I use to customize my machines in the same way for privacy, search, UI, etc.
##################
# Privacy Settings
##################
# Privacy: Let apps use my advertising ID: Disable
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 0
# To Restore:
#Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo -Name Enabled -Type DWord -Value 1
# Privacy: SmartScreen Filter for Store Apps: Disable
Set-ItemProperty -Path HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppHost -Name EnableWebContentEvaluation -Type DWord -Value 0
@DrAzraelTod
DrAzraelTod / boxstarter.ps1
Created October 5, 2017 17:23 — forked from jessfraz/boxstarter.ps1
Boxstarter Commands for a new Windows box.
# Description: Boxstarter Script
# Author: Jess Frazelle <jess@linux.com>
# Last Updated: 2017-09-11
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
#
# You might need to set: Set-ExecutionPolicy RemoteSigned
#
# Run this boxstarter by calling the following from an **elevated** command-prompt:
@DrAzraelTod
DrAzraelTod / callee.name.js
Last active July 4, 2017 09:08
Kleiner JS-Spaß mit arguments.callee.name
x = function(foo) { console.log(arguments.callee.name) };
x("test")
> x
y = function(func) { func("bar") }
y(x)
> x
z = x
z()
@DrAzraelTod
DrAzraelTod / parse_template.js
Created June 15, 2017 08:44
shamelessly copied/extended, minimal JS-Templating engine - original: http://krasimirtsonev.com/blog/article/Javascript-template-engine-in-just-20-line
/**
* Parses complex HTML-Templates and inserts vars from a dictionary
* Simple Example:
* Template: "<p>Hello, my name is <%name%>. I\'m <%age%> years old.</p>"
* Options: {name: 'foobar', age: 23}
*
* More complex example:
* Template: "<% if(this.flowers.length > 0) { %>
* <ul>
* <% for(var i in this.flowers) { %>
@DrAzraelTod
DrAzraelTod / parse_template.js
Created June 15, 2017 08:40
shamelessly copied/extended, minimal JS-Templating engine
/**
* Parses complex HTML-Templates and inserts vars from a dictionary
* Simple Example:
* Template: "<p>Hello, my name is <%name%>. I\'m <%age%> years old.</p>"
* Options: {name: 'foobar', age: 23}
*
* More complex example:
* Template: "<% if(this.flowers.length > 0) { %>
* <ul>
* <% for(var i in this.flowers) { %>