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 / last_five.py
Created March 2, 2024 20:51
Read last 5 lines from a file of any length
"""
Solution for the challenge https://mastodon.social/@willmcgugan/112025856092773557
How to execute:
1. the very first run of the script generates the example file with
10 million lines, of random lengths
2. drop file system caches [1]
echo 3 | sudo tee /proc/sys/vm/drop_caches
3. run the script to get the time it takes to read the last five lines from
the uncached file
@SubOptimal
SubOptimal / file-timestamps.log
Created December 20, 2022 22:07
Linux file timestamps - birth, atime, mtime, ctime
birth - created - touch
birth 2022-12-20 22:56:54.558640670 +0100
access 2022-12-20 22:56:54.558640670 +0100
modify 2022-12-20 22:56:54.558640670 +0100
change 2022-12-20 22:56:54.558640670 +0100
atime - accessed - cat
birth 2022-12-20 22:56:54.558640670 +0100
access 2022-12-20 22:56:55.570654581 +0100
@SubOptimal
SubOptimal / README.md
Last active April 18, 2022 19:28
create perspective screenshot

On Twitter, Will McGuan posted a perspective screenshot.

This gist provides few basic steps, using ImageMagick, to produce some similar looking.

Following steps were processed.

  • starting with a screenshot of the Rich CLI help in a terminal

image

@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 / multicast-rcv.py
Created June 17, 2021 13:09 — forked from dksmiffs/multicast-rcv.py
Python 3 UDP multicast example, with only very minor modifications needed to this guidance: https://stackoverflow.com/a/1794373
# Multicast receiver
# Guidance: https://stackoverflow.com/a/1794373
import socket
import struct
MCAST_GRP = '224.1.1.1'
MCAST_PORT = 5007
IS_ALL_GROUPS = True
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
@SubOptimal
SubOptimal / HttpClient11.java
Last active April 2, 2019 19:49
HTTP 308 - permanent redirect and Java 11 client
/**
demo of Java 11 HttpClient
*/
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpClient.Redirect;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
@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);
}
}
}
@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 / GitHub Flavored Asciidoc (GFA).adoc
Created February 8, 2019 14:07 — forked from dcode/GitHub Flavored Asciidoc (GFA).adoc
Demo of some useful tips for using Asciidoc on GitHub

GitHub Flavored Asciidoc (GFA)