Skip to content

Instantly share code, notes, and snippets.

@mutsune
mutsune / psetime_converter.awk
Created October 17, 2018 07:40
Convert `ps -o etime` format into seconds https://stackoverflow.com/a/14653443
#!/usr/bin/awk -f
BEGIN { FS = ":" }
{
if (NF == 2) {
print $1*60 + $2
} else if (NF == 3) {
split($1, a, "-");
if (a[2] != "" ) {
print ((a[1]*24+a[2])*60 + $2) * 60 + $3;
} else {
@mutsune
mutsune / gcstat.sh
Created December 6, 2018 03:42
Number of GC events and GC time **per day**
#!/usr/bin/env bash
set -e
# Java process ID
PID="$(pgrep java)"
# convert `ps -o etime` output format to second
function psetime_converter() {
echo "$(cat -)" | awk '
@mutsune
mutsune / CustomStringEscapeUtil.java
Created December 6, 2018 03:46
(Part of) custom apache commons StringEscapeUtil like PHP htmlspecialchars
final private static CharSequenceTranslator quotes = buildAggregateTranslator(Mode.ENT_QUOTES);
final private static CharSequenceTranslator noquotes = buildAggregateTranslator(Mode.ENT_NOQUOTES);
private static AggregateTranslator buildAggregateTranslator(Mode mode) {
Map<CharSequence, CharSequence> map = new HashMap<>();
if (mode == Mode.ENT_QUOTES) {
map.put("\"", "&quot;"); // " - double-quote
map.put("'", "&apos;"); // ' - apostrophe
}
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
int main() {
int fd;
char buf[2];
fd = open("filename.txt", 2);
@mutsune
mutsune / segfault.c
Created December 17, 2018 07:53
Segmentation fault: 11
#include <stdio.h>
int main(int argc, char **argv)
{
unsigned long a[1];
a[3] = 0x7ffff7b36cebUL;
return 0;
}
trap '
pids="$(jobs -p)"
if [[ "${pids}" != "" ]]; then
echo "terminated procs are below:"
ps auxww ${pids}
kill ${pids} > /dev/null
fi' EXIT
@mutsune
mutsune / pattern1
Last active January 16, 2019 14:35
Day-O preference
MM/dd(EEEEE) HH:mm:ss.S
@mutsune
mutsune / darkmode.sh
Created January 17, 2019 04:37
enable/disable Dark Mode scripts
function enable_darkmode() {
set_darkmode "$1" "no"
}
function disable_darkmode() {
set_darkmode "$1" "yes"
}
function set_darkmode() {
app="$1"
@mutsune
mutsune / reading_list_on_chrome.scpt
Last active April 24, 2019 04:33
Add a opening tab on Chrome into Safari's Reading List
tell application "Google Chrome"
set myURL to get URL of active tab of first window
set myTitle to get title of active tab of first window
end tell
tell application "Safari" to add reading list item myURL with title myTitle
:root {
--multirow-n-rows: 3;
}
#tabbrowser-tabs {
min-height: unset !important;
padding-inline-start: 0px !important;
}
#tabbrowser-tabs > .tabbrowser-arrowscrollbox > .arrowscrollbox-scrollbox {
display: flex;
flex-wrap: wrap;