Skip to content

Instantly share code, notes, and snippets.


Vít Šesták v6ak

View GitHub Profile
View gist:9445287
val key: PGPPublicKey = ...
def encrypt(plaintext: String): String = {
val baos = new ByteArrayOutputStream()
val literalDataGenerator = new PGPLiteralDataGenerator()
val comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZLIB) // I've also tried other compression algorithms
val bytes = plaintext.getBytes("utf-8")
val BufferSize = 1 << 16
import resource.managed // The "managed" method with for is just a nice replacement of try/catch/finally{x.close()}
View gist:b3426f858b12723334fa
// An ugly hack for Bittorrent sync; hope to write more later
// separate function for easier debugging
show = function(x){console.log(["X:"{return {folder: x, active_peers: x.peers.filter(function(peer){return peer.down_diff || peer.up_diff;})};}).filter(function(x){return x.active_peers.length > 0;}).map(function(x){return;})])}
var origRequest = utWebUI.request; utWebUI.request= function(a, e, d, b){return, a, function(f){e && e(f); console.log(f.folders);}, d, b); };
View main.cpp
#include <iostream>
#include "json.h"
using namespace std;
int main() {
Json::Number num(3.14159265358972);
Json::String s("5.\" ' \1 0");
Json::Boolean t(true);
Json::Boolean f(false);
v6ak /
Last active Aug 29, 2015
This script does a configurable intelligent exponential backoff with maximum. If the app runs for some time without any problem, the interval is resetted.
# 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/". It might be a good idea to add some notification or logging there.
# 3. Configure WAIT_TIME_* variables.
# 4. Adjust if needed.
v6ak / idea-debug
Last active Aug 29, 2015
IDEA debug info dump
View idea-debug
# 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 /
Last active Aug 29, 2015
Don't want to wait for computations (e.g. checksums) on large files after they are downloaded? Do the computation during the download!
# 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 / weird.scala
Created Dec 8, 2014
The methods can't be called from Java directly...
View weird.scala
% 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();
View scala-test-opt-fail.txt
% ant test-opt -v
[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
View gist:e80298cd245bfc24ad95
<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(
at org.ops4j.pax.swissbox.framework.ServiceLookup.getService(
at org.ops4j.pax.swissbox.framework.ServiceLookup.getService(
at org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactor.invoke(
at org.ops4j.pax.exam.junit.JUnit4TestRunner$2.evaluate(
at org.ops4j.pax.exam.junit.JUn
View gist:1d8cac69e87dff0e8631
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