Skip to content

Instantly share code, notes, and snippets.

View v6ak's full-sized avatar

Vít Šesták v6ak

View GitHub Profile
@v6ak
v6ak / intelligent-exponential-backoff.sh
Last active August 29, 2015 14:08
This script does a configurable intelligent exponential backoff with maximum. If the app runs for some time without any problem, the interval is resetted.
#!/bin/bash
# This script does a configurable intelligent exponential backoff with maximum. If the app runs for some time without any problem, the interval is resetted.
# Requires: bash, genius
# Security considerations: Like in almost any other shell scripts, some info may leak via /proc/. This should be rather negligible in this case. A local adversary may read sleep values, application run time, wait time and some WAIT_TIME_* variables.
#
# 1. Replace {{run-the-app}}.
# 2. Replace {{clean}} by some clean procedure, e.g. rm -f "$BASE_DIR/play.pid". It might be a good idea to add some notification or logging there.
# 3. Configure WAIT_TIME_* variables.
# 4. Adjust if needed.
@v6ak
v6ak / idea-debug
Last active August 29, 2015 14:09
IDEA debug info dump
#!/bin/sh
IDEA_VERSION=14
# Note that thread dump will not work well when you have launched other IDEA-like IDE (e.g. CLion, PhpStorm, PyCharm, RubyMine), since it has the same main class.
time=$(date +%Y-%m-%d--%H:%M:%S)
jps -l | grep ' com.intellij.idea.Main$' | sed 's/ .*$//' | xargs jstack > "/tmp/idea-$time.threads"
cp ~/.IntelliJIdea$IDEA_VERSION/system/log/idea.log "/tmp/idea-$time.log"
notify-send "Saved as /tmp/idea-$time.{log,threads}."
@v6ak
v6ak / catdld.sh
Last active August 29, 2015 14:10
Don't want to wait for computations (e.g. checksums) on large files after they are downloaded? Do the computation during the download!
#!/bin/bash
# No warranty is provided!
#
# Rather hacky script for streaming downloaded files through pipe.
# Requires inotify-tools package installed.
# It does not handle some failures properly!
#
# Assumes that a browser saves the temporary result into the .part file and the browser is the only process that opens the file for writing.
#
# How it works: The script streams the content of the .part file to stdout. When the .part file is closed, it stops streaming.
@v6ak
v6ak / weird.scala
Created December 8, 2014 21:30
The methods can't be called from Java directly...
% scalac weird.scala && javap X
Compiled from "weird.scala"
public class X implements scala.ScalaObject {
public int 1();
public java.lang.String package();
public java.lang.String class();
public java.lang.String def();
public java.lang.String for();
public java.lang.String while();
public X();
@v6ak
v6ak / czech-noun-inflection.scala
Last active August 12, 2022 14:43
Czech noun inflection Scala-like pseudocode
/*
In Czech, there are various "templates" for noun inflection. (I am not completely sure if "template" is the correct term.) We divide the nouns by grammatical gender to manculines, feminines and neuters.
Masculines are divided to (grammaticaly) animate and (grammaticaly) inanimate. (Note that grammatical animateness may differ from the actual animateness. For example, "sněhulák" (snowman) and "umrlec" (dead man) are grammatically animate.)
Templates according to https://cs.wikipedia.org/wiki/%C4%8Cesk%C3%A1_podstatn%C3%A1_jm%C3%A9na#Rod_mu.C5.BEsk.C3.BD_.C5.BEivotn.C3.BD :
masculine, animate:
pán
muž
% ant test-opt -v
test.osgi:
[echo] Running OSGi JUnit tests. Output in …/scala/build/osgi
[mkdir] Skipping …/scala/build/osgi/classes because it already exists.
[junit] Implicitly adding /usr/share/ant/lib/junit.jar:/usr/share/java/ant-launcher-1.8.2.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/ant-junit.jar:/usr/share/ant/lib/ant-junit4.jar to CLASSPATH
[junit] Executing '/usr/lib/jvm/java-8-oracle/jre/bin/java' with arguments:
[junit] '-classpath'
[junit] '…/scala/build/osgi/classes:…/scala/build/osgi/org.scala-lang.scala-library.jar:…/scala/build/osgi/org.scala-lang.scala-reflect.jar:…/scala/build/osgi/org.scala-lang.scala-compiler.jar:…/scala/build/osgi/org.scala-lang.scala-actors.jar:…/.m2/repository/org/ops4j/pax/exam/pax-exam-container-native/2.6.0/pax-exam-container-native-2.6.0.jar:…/.m2/repository/org/ops4j/pax/exam/pax-exam/2.6.0/pax-exam-2.6.0.jar:…/.m2/repository/org/ops4j/base/ops4j-base-lang/1.4.0/ops4j-base-lang-1.4.0.jar:…/.m2/repository/org/ops4j/base/ops4j-b
<testcase classname="tools.test.osgi.BasicTest" name="everythingLoads:tools.test.osgi.BasicTest.everythingLoads:NativeContainer:org.apache.felix.framework.FrameworkFactory@5606c0b" time="10.442">
<error message="gave up waiting for service org.ops4j.pax.exam.ProbeInvoker" type="org.ops4j.pax.swissbox.framework.ServiceLookupException">org.ops4j.pax.swissbox.framework.ServiceLookupException: gave up waiting for service org.ops4j.pax.exam.ProbeInvoker
at org.ops4j.pax.swissbox.framework.ServiceLookup.getService(ServiceLookup.java:161)
at org.ops4j.pax.swissbox.framework.ServiceLookup.getService(ServiceLookup.java:104)
at org.ops4j.pax.swissbox.framework.ServiceLookup.getService(ServiceLookup.java:87)
at org.ops4j.pax.exam.nat.internal.NativeTestContainer.call(NativeTestContainer.java:94)
at org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactor.invoke(AllConfinedStagedReactor.java:74)
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(JUnit4TestRunner.java:285)
at org.ops4j.pax.exam.junit.JUn
0: 0, 100, 200
1: 1, 101, 201
2: 2, 102, 202
3: 3, 103, 203
4: 4, 104, 204
5: 5, 105, 205
6: 6, 106, 206
7: 7, 107, 207
8: 8, 108, 208
9: 9, 109, 209
@v6ak
v6ak / run-once-gui
Last active August 29, 2015 14:15
Starts a GUI application if not running. If it is running, it switches to it. It is unlikely to work well with multiwindow applications without modification because it focuses all of application's windows. Does not work well with "minimize to tray", because it can't find the app's window.
#!/bin/bash
set -u
set -e
set -o pipefail
# Settings
NAME=GQueues
COMMAND=firefox-gqueues
#!/bin/bash
# Intended for installing the corresponding VirtualBox Extension Pack with secure verification. (A local network adversary can't forge the installed package.)
# This version uses a temporary directory.
#
# It is written to be as fail-safe and fail-secure as possible, but no warranty is provided.
#
# safety settings
set -u # Not strictly needed, but it is safer
set -e # NEEDED for safety and security!