About:
This page archives most of the code snippets published on this site for easy retrieval purposes. Code snippets are in general small pieces of reusable code, not large enough to build anything worth publishing.
However, not all scripts/snippets published here are meant to be reusable (in fact some of them are nothing but very specific tailor-made solutions). It is more that I needed a place to gather all the tiny developments and maybe someone will profit from them too.
All being said, snippets are not full-blown projects and their quality of code and/or documentation can reflect it. You have been warned.
Individual snippet archives:
Individual snippets index:
[BASH] Using Reverse Remote Shell
[Perl] Adjusting date without root access
[BASH] Slowing down “find” on Linux
[VBA] Changing decimal separator setting in Excel
Code snippets:
[BASH] Using Reverse Remote Shell
First make a main connection script (something like ~/start.sh):
#!/bin/sh # Establish a new screen session killall screen screen -dmS remoteShell sleep 1 # Connect to the server via tunnel, when the session is completed - exit screen screen -S remoteShell -p 0 -X stuff "~/connect.sh && exit^M" sleep 1 # This gets executed on the remote server - request a connection to the listener screen -S remoteShell -p 0 -X stuff "~/remote.sh && exit^M" # Turn on listening on local side ~/listen.sh
You will also need a tunnel connection script (connect.sh). This can be something so trivial as:
#!/bin/sh /usr/bin/ssh -p 22 -i ~/.ssh/myIdentityFile user@example.com
The remote part (remote.sh) is something like this:
#!/bin/sh /bin/sleep 1 # Check your rrs location here, 12345 is a port of the listener # and dynamic.example.com is a dynamic hostname for the listener (client) ~/rrs --daemon --ssl --pem ~/rrs.pem --timeout 15 dynamic.example.com 12345
And the last part – listener (listen.sh):
#!/bin/sh ~/rrs --listen --ssl --pem ~/rrs.pem --port 12345
[Perl] Adjusting date without root access
#!/usr/bin/perl
use strict;
use POSIX;
# NTP server hostname
our $NTP_SERVER="ntp.icm.edu.pl";
# Local timezone shift in minutes (to UTC)
our $TZ_SHIFT=3600;
# Path where the fake timezone script is saved
our $TZ_FILE="~/.tz_shift";
# Check your rdate path here
my @date = `/usr/sbin/rdate -p -v $NTP_SERVER`;
$date[1] =~ s/.* by ([0-9]*) seconds/\1/g;
my $offset = $date[1]+$TZ_SHIFT;
print "Time offset: $offset seconds\n";
my $hours = floor($offset / 3600);
$offset -= $hours * 3600;
my $minutes = floor($offset / 60);
$offset -= $minutes * 60;
my $seconds = $offset;
print "Shifting time zone: $hours hour(s), $minutes minute(s), $seconds second(s)\n";
open(TZ, ">", $TZ_FILE);
printf TZ "#!/bin/bash\n";
printf TZ "export TZ=COR-$hours:$minutes:$seconds\n";
# This should not be needed, but for some unknown reason
# this fixed some issues when not executing the script on logon
system("export TZ=COR-$hours:$minutes:$seconds\n");
system("source $TZ_FILE");
[BASH] Slowing down “find” on Linux
DELAY=0.1
find ./ -name example -exec sleep ${DELAY} \; -print
[PHP] Fixing SimpleTags (1.5.7) and WordPress with Gengo (2.5.3) incompatiblitiy.
See the original post for instructions.
[VBA] Changing decimal separator setting in Excel
Dim currentDecimalSeparator As String Dim currentThousandsSeparator As String Dim currentUseSystemSeparators As Boolean With Application ' Store current number format settings currentDecimalSeparator = .DecimalSeparator currentThousandsSeparator = .ThousandsSeparator currentUseSystemSeparators = .UseSystemSeparators ' Set separators for the web query to match the source (website) .DecimalSeparator = "." .ThousandsSeparator = "," .UseSystemSeparators = False ' Do the processing (all queries and stuff) ' [...] ' Reset number format settings .DecimalSeparator = currentDecimalSeparator .ThousandsSeparator = currentThousandsSeparator .UseSystemSeparators = currentUseSystemSeparators End With







Recent Comments