Skip to content

Instantly share code, notes, and snippets.

@pcdv
pcdv / g-short.bash
Last active March 6, 2024 14:41
Shortened version of g.bash
function g() {
local C="$HOME/.cdirs"
case $1 in
"") nl "$C" || touch "$C";;
-e) ${EDITOR:-vi} "$C";;
.) pwd >> "$C";;
1-9]*) cd "$(sed -ne "${1}p" "$C")";;
*) cd "$(grep "$1" "$C" | head -1)";;
esac
}
@pcdv
pcdv / g.bash
Last active January 31, 2022 17:28
Directory bookmarks in Bash
# https://gist.github.com/pcdv
function g() {
local HLP="Bookmark your favorite directories:
g : list bookmarked dirs
g . : add current dir to bookmarks
g -e : edit bookmarks
g <num> : jump to n-th dir
g <regex> : jump to 1st matching dir"
local D=_; local CFG="$HOME/.cdirs"
@pcdv
pcdv / reuse-ssh-agent.bash
Created January 29, 2020 10:16
Auto connect to ssh-agent on Windows (Git Bash)
# Reuse an existing ssh-agent on login, or create a new one. Append this to your .bashrc
# I have no idea who the author of the original concept was for reusing agents. This
# version also handles the case where the agent exists but has no keys.
#
# Adapted for Git Bash on Windows
GOT_AGENT=0
for FILE in $(find /tmp/ssh-* -type s -user ${USERNAME} -name "agent.[0-9]*" 2>/dev/null)
do
@pcdv
pcdv / Args.java
Created November 8, 2018 09:20
Parse command line in Java 8 without dependencies
public class Args {
private static final String USAGE //
= String.join("\n",
"",
"tool [options] files...",
"",
"",
"Options:",
" -d PORT : filter on given port",
" -h : prints this help",
@pcdv
pcdv / gradlerun.bash
Created January 3, 2014 11:05
This experimental script uses Gradle to build a classpath from a project's dependencies then run a given java class
#!/bin/bash
# Example: gradlerun path/to/ivyrepo com.example:mylib:+ com.example.MyMainClass arg1
REPO=$1
DEP=$2
MAIN=$3
ARG=$4
shift 4
SCRIPT=/tmp/gradlescript$$
@pcdv
pcdv / jocket benchmark raspberry pi
Last active December 28, 2015 16:18
Jocket benchmark / Raspberry Pi
STANDARD SOCKET
pi@raspberrypi ~/jocket $ ./run-bench.sh -Dtcp=true
Java ServerSocket listening on 3333
Warming up : 50000 reps, pause between reps: 0ns... done in 18206ms
Running test : 300000 reps, pause between reps: 0ns... done in 100855ms
Dumping results in /tmp/Socket
1.0% ( 297000) : 309.99 (us)
10.0% ( 270000) : 312.99 (us)
50.0% ( 150000) : 317.99 (us)
@pcdv
pcdv / jocket benchmark KS 2G
Last active December 23, 2015 17:29
Kimsufi KS 2G (dual core version)
STANDARD SOCKET
$ /opt/jdk1.7.0_25/bin/java -Dtcp=true -cp jocket-0.5.0pre1.jar:jocket-bench-0.5.0pre1.jar jocket.bench.BenchClient
Warmup (50000) ... 
Running test (300000) ...
Done in 58681ms. Dumping results in Socket
1.0%          ( 297000) :   101,54 (us)
10.0%         ( 270000) :   193,04 (us)
50.0%         ( 150000) :   194,36 (us)
99.0%         (   3000) :   242,23 (us)