Skip to content

Instantly share code, notes, and snippets.

View SubOptimal's full-sized avatar
🤓
the joy of coding - happy hacking

Frank Dietrich SubOptimal

🤓
the joy of coding - happy hacking
View GitHub Profile
@SubOptimal
SubOptimal / Main.java
Created July 11, 2014 17:06
text mode scroller like in the movie "The Matrix"
/**
*
* Today was on stackoverflow a question about how to convert a C++ source into
* Java source. The code was implementing a scoller like in the movie "The Matrix".
*
* As the question was not fulfilling the stackoverflow requirements for a valid
* questions, it has been deleted in the meantime by the moderators. Which is a
* little bit bad, as the code was nice.
*
* So I create this gist with my answer I would like to have posted to the
@SubOptimal
SubOptimal / solution
Created September 12, 2014 10:18
Java "Hello World" without keyword "class"
# Linux / Mac
echo 'java.lang.System.out.println("Hello World")' | java -cp ${JAVA_HOME}/lib/tools.jar com.sun.tools.script.shell.Main
# Windows
echo java.lang.System.out.println("Hello World") | java -cp %JAVA_HOME%/lib/tools.jar com.sun.tools.script.shell.Main
@SubOptimal
SubOptimal / Targz.java
Created October 31, 2014 08:49
extract a tar file with multibyte and reserved characters in filename on Windows
// anser for: http://stackoverflow.com/questions/26656427/how-to-extract-tar-gz-including-multi-byte-characters-and-prohibited-characters
package tar;
import org.apache.tools.tar.*;
import java.io.*;
import java.nio.file.*;
import java.util.zip.GZIPInputStream;
public class Targz {
package sub.optimal.benchmark;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
@SubOptimal
SubOptimal / pom.xml
Last active October 13, 2015 18:59
execute SquirrelSql with `mvn exec:exec -Dexec.executable="java"``
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sub.optimal</groupId>
<artifactId>SquirrelSqlCLI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
@SubOptimal
SubOptimal / tooltip.ps1
Created October 19, 2015 07:55
fix locked taskbar autohide in Windows
# sometimes the autohide of the Windows taskbar doesn't work anymore
# and the taskbar is showed permanently
#
# beside killing and restarting the explorer.exe process it's enough
# forcing to display a new tooltip
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.icon = [System.Drawing.SystemIcons]::Error
@SubOptimal
SubOptimal / AttachClient.java
Last active March 19, 2019 06:25
Java attach API - attach to JVM of different user
import com.sun.tools.attach.VirtualMachine;
public class AttachClient {
public static void main(String[] args) throws Exception {
String pid = args[0];
VirtualMachine vm = VirtualMachine.attach(pid);
System.out.println("vm = " + vm);
vm.detach();
}
@SubOptimal
SubOptimal / ReportCpuCount.java
Last active March 29, 2019 19:39 — forked from thomasdarimont/ReportCpuCount.java
Using LD_PRELOAD to pass a fake CPU count to Java on Linux
public class ReportCpuCount {
public static void main(String[] args) throws Exception{
while(true){
System.out.printf("#Found %d CPUs%n", Runtime.getRuntime().availableProcessors());
Thread.sleep(1000);
}
}
}
import static java.lang.System.out;
import java.lang.reflect.Field;
import java.util.AbstractList;
import java.util.ArrayList;
/**
* Related to an answer to this Twitter post
* https://twitter.com/JosePaumard/status/864938907183480832
*
* @author Frank Dietrich <Frank.Dietrich@gmx.li>
@SubOptimal
SubOptimal / InterceptorThing.ps1
Created January 31, 2018 06:45
Interceptor - Normal User No Admin Required.
<#
.SYNOPSIS
This script demonstrates the ability to capture and tamper with Web sessions.
For secure sessions, this is done by dynamically writing certificates to match the requested domain.
This is only proof-of-concept, and should be used cautiously, to demonstrate the effects of such an attack.
Function: Interceptor
Author: Casey Smith, Twitter: @subTee
License: BSD 3-Clause