Community discussions

MikroTik App
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

✂ Rextended Fragments of Snippets

Thu Aug 12, 2021 3:44 pm

Over the years I have published dozens of scripts,
most need to be updated and are hard to find with standard search.
And they also need to be checked if they are still valid for the new stable v7 version.

I'm slowly re-reading all of my 10000 posts
and I'll add here all the useful Snippets I found,
with a description and the link to the topic where they are present.

In the future, when I'm done, I'll index everything for better search.
Last edited by rextended on Sun Apr 09, 2023 12:31 am, edited 3 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Sep 15, 2021 10:29 am

wireless on off with mode button
viewtopic.php?f=7&t=115078&p=857648#p857648

create directory and subdirectory
viewtopic.php?f=9&t=151644&p=878316#p878368

mac ping results saved on variable
viewtopic.php?f=2&t=69773&p=876970#p876970

Put snmp-get value on variable
viewtopic.php?f=9&t=136809&p=876969#p876969

Convert character to uppercase or lowercase
viewtopic.php?f=9&t=75555&p=876693#p876693

UNIX time Epoch, day of the week, ISO:8601 date
viewtopic.php?f=9&t=75555#p876568

Import IP or IP prefix from file
viewtopic.php?f=9&t=166293#p872049

How to download only one piece of file at a time with /tool fetch and put it inside a variable
viewtopic.php?f=9&t=177530

Decode USSD hexstr2chrstr hexadecimal string to char string
viewtopic.php?f=9&t=129693&p=871742#p871742

hex2chr hexadecimal to char
viewtopic.php?f=9&t=108127&p=871741#p871741

definitive ip or ip-prefix posix regex
viewtopic.php?f=9&t=152632&p=871284#p871284

auto add (starlink) classless route
viewtopic.php?f=2&t=175272&p=871239#p871239

int2hex num2hex integer number to hexadecimal convert function
viewtopic.php?f=2&t=57665&p=868898#p868898

check host status
viewtopic.php?f=9&t=177005&p=868482#p868482

dual wan A-B-C failover
viewtopic.php?f=2&t=176574&p=865665#p865665

dual dhcp wan failover
viewtopic.php?f=13&t=176956&p=868082#p868082

How to ***really*** block invalid ICMP, TCP, UDP packets and others (ver. 2021)
viewtopic.php?f=9&t=83387&p=867386

comma separated value of interface list
viewtopic.php?f=9&t=176428&p=865545#p865545

num2month mon2MON mon2num number month
viewtopic.php?f=9&t=176408&p=864690#p864688

short address list ip address aggregator (to do)
viewtopic.php?f=23&t=148187&p=864415#p864415

send whatsapp notification
viewtopic.php?f=9&t=124157&p=862628#p860703

asynchronous script execution
viewtopic.php?f=9&t=87589&p=861988#p861988

enable x64 mode on RouterOS x86 installed on x64 (virtual or not) machine
viewtopic.php?f=2&t=116621&p=861102#p861102

random number generator (without OTP frills)
viewtopic.php?f=9&t=175453&p=858629

default firewall rules
viewtopic.php?f=13&t=175129&p=856824#p856824

convert string to ip-prefix
viewtopic.php?f=9&t=127039&p=854216#p854216

dynamic variables
viewtopic.php?f=9&t=178435&p=879152#p879152

manage fetch errors
viewtopic.php?f=2&t=178355&p=878643#p878643

sort array, sort file by date, date2ymd
viewtopic.php?f=9&t=178532#p879931
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Sep 17, 2021 2:42 am

 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Sep 17, 2021 11:50 am

DHCPv6 option 39 fqdn2encdns FQDN to DNS encoding DNS encoder

viewtopic.php?f=1&t=178607&p=880429#p880424
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Oct 02, 2021 1:53 pm

Save and Restore global variables on reboot

viewtopic.php?f=9&t=170591&p=883422#p883422
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Feb 26, 2022 11:25 am

Save RouterBOARD full backup of everything [configuration, certificates, host key, router users (no passwords), licence, user-manager, dude, other files]
viewtopic.php?f=1&t=175360&p=858564#p858564
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon May 02, 2022 5:23 am

Online function to obtain the start date and time of the RouterBOARD.
It takes into account the time zone set in the RouterBOARD.
viewtopic.php?t=185616#p930465
Last edited by rextended on Fri Jan 13, 2023 3:42 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu May 19, 2022 7:17 pm

Convert float to Celsius for TG-BT5-OUT
viewtopic.php?p=934123#p934123
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon May 23, 2022 2:39 pm

Convert the date string (May|may)/23/2022 to number 20220523
(the "date" type on RouterOS do not exist)
viewtopic.php?p=934798#p934798
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue May 24, 2022 5:12 pm

Fomr 2014: I forgot that on print and on find is possible to do some operations insde search string...
like (just an example)
/ip address print where (network + 1) = 192.168.88.1

viewtopic.php?p=411411#p411411
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue May 24, 2022 5:23 pm

 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue May 24, 2022 7:09 pm

Code: Select all

# TAG # lastcheck (25 Mar 2014, 13:34)
viewtopic.php?p=417214#p417214


TAG: ###RCHCK###
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jun 03, 2022 7:31 pm

Check if the URL is valid and read server response and redirects:
viewtopic.php?p=937034#p937124
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Aug 09, 2022 2:54 pm

Create a log file and dynamically split the file every 4095 Bytes or less
viewtopic.php?p=950767#p950761
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Aug 26, 2022 3:30 pm

Obtain some info from one IP, convert subnet mask to prefix, convert prefix to subnet mask, convert IP to num, convert num to IP, convert IP to HEX, convert HEX to IP etc.

If the IP have (do not have) subnet mask different from /32 (255.255.255.255)
other useful info can be obtained from this information.
(MikroTik actually do not support directly /31 addresses)

For example if you have this 10.31.42.56/16
{
:local source    10.31.42.56/16

:local ip        [:toip [:pick $source 0 [:find $source "/"]]]
:local prefix    [:tonum [:pick $source ([:find $source "/"] + 1) [:len $source]]]
:local submask   (255.255.255.255<<(32 - $prefix))
:local addrspace (~$submask)
:local totip     ([:tonum $addrspace] + 1)
:local network   ($ip & $submask)
:local broadcast ($ip | $addrspace)
:local first     (($network     + 1) - ($prefix / 31))
:local last      (($broadcast   - 1) + ($prefix / 31))
:local usable    (($last - $network) + ($prefix / 31))
:put "       Source: $source"
:put "           IP: $ip"
:put "Subnet Prefix: $prefix"
:put "  Subnet Mask: $submask"
:put "Address Space: $addrspace"
:put "    Total IPs: $totip"
:put "  Network* IP: $network"
:put "Broadcast* IP: $broadcast"
:put "    First* IP: $first"
:put "     Last* IP: $last"
:put "  Usable* IPs: $usable"
}
* = Network / Broadcast / First IP and Last IP are valid only when the IP are distribuited on local LAN,
instead for routing only, all IP can be used.
.0 and .255 are perfectly valid IP if are not the network ip or the broadcast address,
but for compatibility with some end devices that have problems with .0 and .255 outside a /24, is better remove all .0 and all .255 from the IP pools assigned from DHCP Server.

For example if you have this IP 10.31.42.56 and subnet 255.255.0.0
{
:local sourceip    10.31.42.56
:local sourcesub   255.255.0.0

:local ip        [:toip $sourceip]
:local submask   [:toip $sourcesub]
:local addrspace (~$submask)
:local tempsub   [:tonum $addrspace]
:local prefix    32
:while ($tempsub > 0) do={:set tempsub ($tempsub / 2); :set prefix ($prefix - 1)}
:local totip     ([:tonum $addrspace] + 1)
:local network   ($ip & $submask)
:local broadcast ($ip | $addrspace)
:local first     (($network     + 1) - ($prefix / 31))
:local last      (($broadcast   - 1) + ($prefix / 31))
:local usable    (($last - $network) + ($prefix / 31))
:put "    Source IP: $ip"
:put "  Source Mask: $submask"
:put "Subnet Prefix: $prefix"
:put "Address Space: $addrspace"
:put "    Total IPs: $totip"
:put "  Network* IP: $network"
:put "Broadcast* IP: $broadcast"
:put "    First* IP: $first"
:put "     Last* IP: $last"
:put "  Usable* IPs: $usable"
}

Convert IP to decimal number: (127.0.0.1 = 2130706433)
:put [:tonum 127.0.0.1]

Convert decimal number to IP: (2130706433 = 127.0.0.1)
:put (0.0.0.0 + 2130706433)

Convert IP to hexadecimal number
Using this:
viewtopic.php?f=2&t=57665&p=868898#p868898
The IP can be converted first to decimal, then to hexadecimal.
:put [$num2hex [:tonum 127.0.0.1]]

Convert hexadecimal number to IP
:put (0.0.0.0 + 0x7F000001)
Last edited by rextended on Fri Mar 03, 2023 1:14 pm, edited 10 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Oct 31, 2022 12:31 pm

Script for convert codepage or replace characters inside a string
viewtopic.php?p=965180#p965180
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Oct 31, 2022 2:55 pm

decimal 2 binary (only 1 BYTE)
:global dec2bin do={
    :local number [:tonum $1]
    :local b8 0 ; :if ($number & 128) do={:set b8 1}
    :local b7 0 ; :if ($number &  64) do={:set b7 1}
    :local b6 0 ; :if ($number &  32) do={:set b6 1}
    :local b5 0 ; :if ($number &  16) do={:set b5 1}
    :local b4 0 ; :if ($number &   8) do={:set b4 1}
    :local b3 0 ; :if ($number &   4) do={:set b3 1}
    :local b2 0 ; :if ($number &   2) do={:set b2 1}
    :local b1 0 ; :if ($number &   1) do={:set b1 1}
    :return "$b8$b7$b6$b5$b4$b3$b2$b1"
}
see here for version from 0 to 9.223.372.036.854.775.807 auto BYTE / WORD / DWORD / QWORD version:
viewtopic.php?t=177551#p967775



hexadecimal 2 binary (only 1 byte) expected as 0x00 ... 0xFF or 00... FF value:
:global hex2bin do={
    :local conv $1
    :if (!($conv~"(^0x|^)[0-9a-fA-F]{2}\$")) do={:return "00000000"}
    :if ([:typeof [:find $conv "0x" -1]] = "nil") do={:set conv "0x$conv"}
    :local number [:tonum $conv]
    :local b8 0 ; :if ($number & 128) do={:set b8 1}
    :local b7 0 ; :if ($number &  64) do={:set b7 1}
    :local b6 0 ; :if ($number &  32) do={:set b6 1}
    :local b5 0 ; :if ($number &  16) do={:set b5 1}
    :local b4 0 ; :if ($number &   8) do={:set b4 1}
    :local b3 0 ; :if ($number &   4) do={:set b3 1}
    :local b2 0 ; :if ($number &   2) do={:set b2 1}
    :local b1 0 ; :if ($number &   1) do={:set b1 1}
    :return "$b8$b7$b6$b5$b4$b3$b2$b1"
}
see here for version from 0 to 9.223.372.036.854.775.807 auto BYTE / WORD / DWORD / QWORD version:
viewtopic.php?t=177551#p967775
Last edited by rextended on Fri Jun 09, 2023 1:15 am, edited 5 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Oct 31, 2022 3:32 pm

binary to decimal (only 8 bit / 1 byte) from 00000000 to 11111111
:global bin2dec do={
    :local bin $1
    :local dec  0
    :local mol  1
    :if (!($bin~"^[0-1]{8}\$")) do={:return 0}
    :for pos from=1 to=8 do={
        :local temp [:tonum [:pick $bin (8 - $pos) (8 - $pos + 1)]]
        :set dec ($dec + ($temp * $mol))
        :set mol ($mol * 2)
    }
    :return $dec
}

binary to hexadecimal (only 8 bit / 1 byte) from 00000000 to 11111111
the output is on 0x00 ... 0xFF format, for remove the 0x simplu remove 0x on last ":return"
:global bin2hex do={
    :local bin $1
    :local dec  0
    :local mol  1
    :if (!($bin~"^[0-1]{8}\$")) do={:return "0x00"}
    :for pos from=1 to=8 do={
        :local temp [:tonum [:pick $bin (8 - $pos) (8 - $pos + 1)]]
        :set dec ($dec + ($temp * $mol))
        :set mol ($mol * 2)
    }
    :local hexadec   "0"
    :local remainder 0
    :local hexChars  "0123456789ABCDEF"
    :if ($dec > 0) do={:set hexadec ""}
    :while ( $dec > 0 ) do={
          :set remainder ($dec % 16)
          :set dec       (($dec-$remainder) / 16)
          :set hexadec   ([:pick $hexChars $remainder].$hexadec)
    } 
    :if ([:len $hexadec] = 1) do={:set hexadec "0$hexadec"}
    :return "0x$hexadec"
}

this is the version of binary to decimal that support binary signed QWORD (64 bit) and is the max supported from RouterOS
:global binQW2dec do={
    :local bin $1
    :local dec  0
    :local mol  1
    :local lgt [:len $bin]
    :if (!($bin~"^[0-1]{$lgt}\$")) do={:return 0}
    :for pos from=1 to=$lgt do={
        :local temp [:tonum [:pick $bin ($lgt - $pos) ($lgt - $pos + 1)]]
        :set dec ($dec + ($temp * $mol))
        :set mol ($mol * 2)
    }
    :return $dec
}

this is the version of binary to hexadecimal that support binary signed QWORD (64 bit) and is the max supported from RouterOS
:global binQW2hex do={
    :local bin $1
    :local dec  0
    :local mol  1
    :local lgt [:len $bin]
    :if (!($bin~"^[0-1]{$lgt}\$")) do={:return "0x00"}
    :for pos from=1 to=$lgt do={
        :local temp [:tonum [:pick $bin ($lgt - $pos) ($lgt - $pos + 1)]]
        :set dec ($dec + ($temp * $mol))
        :set mol ($mol * 2)
    }
    :local firstchar ""
    :if ($dec < 0) do={
        :local chk (($dec & 0x7000000000000000) >> 60)
        :set firstchar [:pick "89ABCDEF" $chk ($chk + 1)]
        :set dec ($dec & 0x0FFFFFFFFFFFFFFF)
    }
    :local hexadec   "0"
    :local remainder 0
    :local hexChars  "0123456789ABCDEF"
    :if ($dec > 0) do={:set hexadec ""}
    :while ( $dec > 0 ) do={
          :set remainder ($dec % 16)
          :set dec       (($dec-$remainder) / 16)
          :set hexadec   ([:pick $hexChars $remainder].$hexadec)
    } 
    :if ($firstchar != "") do={
        :set hexadec "00000000000000$hexadec"
        :set hexadec "$firstchar$[:pick $hexadec ([:len $hexadec] - 15) [:len $hexadec]]"
    }
    :return "0x$hexadec"
}
Last edited by rextended on Mon Oct 31, 2022 6:33 pm, edited 4 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Oct 31, 2022 3:41 pm

for convert decimal to hexadecimal (not only one byte) can be used:
viewtopic.php?p=868898#p868898

for convert hexadecimal to decimal, on RouterOS already exist this two methods (0x must be present):
:put 0xFF85

:put [:tonum "0xFF85"]

but this can be used (not only one byte):
:global hex2dec do={
    :local conv $1
    :if (!($conv~"^[0-9a-fA-F]+\$")) do={:return 0}
    :if ([:typeof [:find $conv "0x" -1]] = "nil") do={:set conv "0x$conv"}
    :return [:tonum $conv]
}
WARNING: RouterOS have a bug that do not recognize negative hex values, on future I mod the previous script to support QWORD hex conversion
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Nov 14, 2022 6:15 pm

Convert string from ASCII 8-bit CP1252 to UNICODE entry points
:global ASCIItoCP1252toUNICODE do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1252toUNICODE {"0000";"0001";"0002";"0003";"0004";"0005";"0006";"0007";"0008";"0009";"000A";"000B";"000C";"000D";"000E";"000F";
                         "0010";"0011";"0012";"0013";"0014";"0015";"0016";"0017";"0018";"0019";"001A";"001B";"001C";"001D";"001E";"001F";
                         "0020";"0021";"0022";"0023";"0024";"0025";"0026";"0027";"0028";"0029";"002A";"002B";"002C";"002D";"002E";"002F";
                         "0030";"0031";"0032";"0033";"0034";"0035";"0036";"0037";"0038";"0039";"003A";"003B";"003C";"003D";"003E";"003F";
                         "0040";"0041";"0042";"0043";"0044";"0045";"0046";"0047";"0048";"0049";"004A";"004B";"004C";"004D";"004E";"004F";
                         "0050";"0051";"0052";"0053";"0054";"0055";"0056";"0057";"0058";"0059";"005A";"005B";"005C";"005D";"005E";"005F";
                         "0060";"0061";"0062";"0063";"0064";"0065";"0066";"0067";"0068";"0069";"006A";"006B";"006C";"006D";"006E";"006F";
                         "0070";"0071";"0072";"0073";"0074";"0075";"0076";"0077";"0078";"0079";"007A";"007B";"007C";"007D";"007E";"007F";
                         "20AC";"FFFD";"201A";"0192";"201E";"2026";"2020";"2021";"02C6";"2030";"0160";"2039";"0152";"FFFD";"017D";"FFFD";
                         "FFFD";"2018";"2019";"201C";"201D";"2022";"2013";"2014";"02DC";"2122";"0161";"203A";"0153";"FFFD";"017E";"0178";
                         "00A0";"00A1";"00A2";"00A3";"00A4";"00A5";"00A6";"00A7";"00A8";"00A9";"00AA";"00AB";"00AC";"00AD";"00AE";"00AF";
                         "00B0";"00B1";"00B2";"00B3";"00B4";"00B5";"00B6";"00B7";"00B8";"00B9";"00BA";"00BB";"00BC";"00BD";"00BE";"00BF";
                         "00C0";"00C1";"00C2";"00C3";"00C4";"00C5";"00C6";"00C7";"00C8";"00C9";"00CA";"00CB";"00CC";"00CD";"00CE";"00CF";
                         "00D0";"00D1";"00D2";"00D3";"00D4";"00D5";"00D6";"00D7";"00D8";"00D9";"00DA";"00DB";"00DC";"00DD";"00DE";"00DF";
                         "00E0";"00E1";"00E2";"00E3";"00E4";"00E5";"00E6";"00E7";"00E8";"00E9";"00EA";"00EB";"00EC";"00ED";"00EE";"00EF";
                         "00F0";"00F1";"00F2";"00F3";"00F4";"00F5";"00F6";"00F7";"00F8";"00F9";"00FA";"00FB";"00FC";"00FD";"00FE";"00FF"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local unicode "0x$($CP1252toUNICODE->[:find $ascii [:pick $string $pos ($pos + 1)] -1])"
        :set constr "$constr$unicode"
    }
    :return $constr
}

:put [$ASCIItoCP1252toUNICODE "test"]
0x81, 0x8F, 0x8D, 0x90, 0x9D (not assigned on CP1252) => 0xFFFD REPLACEMENT CHARACTER �




Convert string from ASCII 8-bit CP1252 to UTF-8 string with each byte escaped with %
:global ASCIItoCP1252toUTF8 do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1252toUTF8 {"00";"01";"02";"03";"04";"05";"06";"07";"08";"09";"0A";"0B";"0C";"0D";"0E";"0F";
                         "10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"1A";"1B";"1C";"1D";"1E";"1F";
                         "20";"21";"22";"23";"24";"25";"26";"27";"28";"29";"2A";"2B";"2C";"2D";"2E";"2F";
                         "30";"31";"32";"33";"34";"35";"36";"37";"38";"39";"3A";"3B";"3C";"3D";"3E";"3F";
                         "40";"41";"42";"43";"44";"45";"46";"47";"48";"49";"4A";"4B";"4C";"4D";"4E";"4F";
                         "50";"51";"52";"53";"54";"55";"56";"57";"58";"59";"5A";"5B";"5C";"5D";"5E";"5F";
                         "60";"61";"62";"63";"64";"65";"66";"67";"68";"69";"6A";"6B";"6C";"6D";"6E";"6F";
                         "70";"71";"72";"73";"74";"75";"76";"77";"78";"79";"7A";"7B";"7C";"7D";"7E";"7F";
      "E282AC";"EFBFBD";"E2809A";"C692";"E2809E";"E280A6";"E280A0";"E280A1";"CB86";"E280B0";"C5A0";"E280B9";"C592";"EFBFBD";"C5BD";"EFBFBD";
      "EFBFBD";"E28098";"E28099";"E2809C";"E2809D";"E280A2";"E28093";"E28094";"CB9C";"E284A2";"C5A1";"E280BA";"C593";"EFBFBD";"C5BE";"C5B8";
                         "C2A0";"C2A1";"C2A2";"C2A3";"C2A4";"C2A5";"C2A6";"C2A7";"C2A8";"C2A9";"C2AA";"C2AB";"C2AC";"C2AD";"C2AE";"C2AF";
                         "C2B0";"C2B1";"C2B2";"C2B3";"C2B4";"C2B5";"C2B6";"C2B7";"C2B8";"C2B9";"C2BA";"C2BB";"C2BC";"C2BD";"C2BE";"C2BF";
                         "C380";"C381";"C382";"C383";"C384";"C385";"C386";"C387";"C388";"C389";"C38A";"C38B";"C38C";"C38D";"C38E";"C38F";
                         "C390";"C391";"C392";"C393";"C394";"C395";"C396";"C397";"C398";"C399";"C39A";"C39B";"C39C";"C39D";"C39E";"C39F";
                         "C3A0";"C3A1";"C3A2";"C3A3";"C3A4";"C3A5";"C3A6";"C3A7";"C3A8";"C3A9";"C3AA";"C3AB";"C3AC";"C3AD";"C3AE";"C3AF";
                         "C3B0";"C3B1";"C3B2";"C3B3";"C3B4";"C3B5";"C3B6";"C3B7";"C3B8";"C3B9";"C3BA";"C3BB";"C3BC";"C3BD";"C3BE";"C3BF"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local utf ($CP1252toUTF8->[:find $ascii [:pick $string $pos ($pos + 1)] -1])
        :local sym ""
        :if ([:len $utf] = 2) do={:set sym "%$[:pick $utf 0 2]" }
        :if ([:len $utf] = 4) do={:set sym "%$[:pick $utf 0 2]%$[:pick $utf 2 4]" }
        :if ([:len $utf] = 6) do={:set sym "%$[:pick $utf 0 2]%$[:pick $utf 2 4]%$[:pick $utf 4 6]" }
        :set constr "$constr$sym"
    }
    :return $constr
}

:put [$ASCIItoCP1252toUTF8 "test"]
0x81, 0x8F, 0x8D, 0x90, 0x9D (not assigned on CP1252) => %EF%BF%BD REPLACEMENT CHARACTER �

The BOM, Byte Order Mark for UTF-8 is "%EF%BB%BF"
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Nov 16, 2022 11:24 am

This convert decimal from 0 to 9.223.372.036.854.775.807 to binary value, do not support negative values:
:global dec2bin do={
    :local number [:tonum $1]
    :local ret    ""
    :local rshift 7
    :if ($number >       0xFF) do={:set rshift 15}
    :if ($number >     0xFFFF) do={:set rshift 31}
    :if ($number > 0xFFFFFFFF) do={:set rshift 63}
    :for i from=0 to=$rshift step=1 do={
        :set ret "$(($number >> $i) & 1)$ret"
    }
    :return $ret
}

this is the same for hexadecimal (NOT NEGATIVE VALUES from 0xFF[...] to 0x80[...]) expected as 0x0 ... 0x7FFFFFFFFFFFFFFF with or without 0x
:global hex2bin do={
    :local conv $1
    :if (!($conv~"(^0x|^)[0-9a-fA-F]+\$")) do={:return "00000000"}
    :if ([:typeof [:find $conv "0x" -1]] = "nil") do={:set conv "0x$conv"}
    :local number [:tonum $conv]
    :local ret    ""
    :local rshift 7
    :if ($number >       0xFF) do={:set rshift 15}
    :if ($number >     0xFFFF) do={:set rshift 31}
    :if ($number > 0xFFFFFFFF) do={:set rshift 63}
    :for i from=0 to=$rshift step=1 do={
        :set ret "$(($number >> $i) & 1)$ret"
    }
    :return $ret
}
Last edited by rextended on Tue Jan 16, 2024 10:10 am, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Nov 18, 2022 1:55 pm

Current date and time as string (Also week day name, if the year is bissextile, and Unix Epoch time)
viewtopic.php?p=960070#p960070
Last edited by rextended on Fri Jan 13, 2023 3:41 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Dec 09, 2022 5:50 pm

Case INsensitive search (on example on comment field)
viewtopic.php?t=191504#p971246
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 18961
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: ✂ Rextended Fragments of Snippets

Sun Dec 11, 2022 8:38 pm

Kudos and thanks for all this work. I would send you a bottle of wine but you already the best wine....... (I hear the french wining pun intended)......
I was going to send you some coffee, but you already have the best coffee.
I was going to send chocolate but heck you are so close to Switzerland it probably falls from the sky ( hoelveten better not see this post )

So my heartfelt thanks and wonderment will have to do!
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Dec 12, 2022 1:56 am

Thanks @anav!!!
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Dec 12, 2022 7:49 pm

char to integer, chr2int
char to hex, chr2hex
string of chars to hex string, str2hex
string of chars to array of integers, str2intarr
ipv6 raw hex to IPv6 formatted address, ipv6raw2format (this is incomplete, just for start)
viewtopic.php?t=191609#p971663
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Dec 21, 2022 9:24 pm

various things for array:
create complex array,
browse and replace inside array
and other
viewtopic.php?t=191832#p973295
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Dec 22, 2022 11:52 am

 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Jan 11, 2023 5:00 pm

remove duplicates on array

viewtopic.php?p=976670#p976670
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jan 13, 2023 3:42 am

convert Unix Epoch to datetime

viewtopic.php?p=977170#p977170
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jan 13, 2023 4:10 am

convert time format (like 45w10d14:32:45.37513571) to seconds
(for example, for uptime, for :timestamp on v7, etc.)

viewtopic.php?p=977174#p977174
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Jan 24, 2023 6:06 pm

Search and replace function, with self-loop prevention.

viewtopic.php?t=192932#p979819
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Jan 25, 2023 6:29 pm

Function for escape the script like on "export":

viewtopic.php?p=980088#p980088
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Jan 25, 2023 10:47 pm

Function to URL encode the strings for the GET fields for "/tool fetch"
(a submitted GET form can be simulated with http-header-field="Content-Type:application/x-www-form-urlencoded")

or POST with datatype application/x-www-form-urlencoded
(http-header-field="Content-Type:application/x-www-form-urlencoded" http-data="<DATA encoded with ASCIItoCP1252toURLencode>")

Only 4 characters - . _ ~ must not be escaped, and space must be replaced with +
:global ASCIItoCP1252toURLencode do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1252toURLe {"00";"01";"02";"03";"04";"05";"06";"07";"08";"09";"0A";"0B";"0C";"0D";"0E";"0F";
                         "10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"1A";"1B";"1C";"1D";"1E";"1F";
                         "+";"21";"22";"23";"24";"25";"26";"27";"28";"29";"2A";"2B";"2C";"-";".";"2F";
                         "0";"1";"2";"3";"4";"5";"6";"7";"8";"9";"3A";"3B";"3C";"3D";"3E";"3F";
                         "40";"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";
                         "P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"5B";"5C";"5D";"5E";"_";
                         "60";"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";
                         "p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";"7B";"7C";"7D";"~";"7F";
      "E282AC";"EFBFBD";"E2809A";"C692";"E2809E";"E280A6";"E280A0";"E280A1";"CB86";"E280B0";"C5A0";"E280B9";"C592";"EFBFBD";"C5BD";"EFBFBD";
      "EFBFBD";"E28098";"E28099";"E2809C";"E2809D";"E280A2";"E28093";"E28094";"CB9C";"E284A2";"C5A1";"E280BA";"C593";"EFBFBD";"C5BE";"C5B8";
                         "C2A0";"C2A1";"C2A2";"C2A3";"C2A4";"C2A5";"C2A6";"C2A7";"C2A8";"C2A9";"C2AA";"C2AB";"C2AC";"C2AD";"C2AE";"C2AF";
                         "C2B0";"C2B1";"C2B2";"C2B3";"C2B4";"C2B5";"C2B6";"C2B7";"C2B8";"C2B9";"C2BA";"C2BB";"C2BC";"C2BD";"C2BE";"C2BF";
                         "C380";"C381";"C382";"C383";"C384";"C385";"C386";"C387";"C388";"C389";"C38A";"C38B";"C38C";"C38D";"C38E";"C38F";
                         "C390";"C391";"C392";"C393";"C394";"C395";"C396";"C397";"C398";"C399";"C39A";"C39B";"C39C";"C39D";"C39E";"C39F";
                         "C3A0";"C3A1";"C3A2";"C3A3";"C3A4";"C3A5";"C3A6";"C3A7";"C3A8";"C3A9";"C3AA";"C3AB";"C3AC";"C3AD";"C3AE";"C3AF";
                         "C3B0";"C3B1";"C3B2";"C3B3";"C3B4";"C3B5";"C3B6";"C3B7";"C3B8";"C3B9";"C3BA";"C3BB";"C3BC";"C3BD";"C3BE";"C3BF"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local urle ($CP1252toURLe->[:find $ascii [:pick $string $pos ($pos + 1)] -1])
        :local sym $urle
        :if ([:len $urle] = 2) do={:set sym "%$[:pick $urle 0 2]" }
        :if ([:len $urle] = 4) do={:set sym "%$[:pick $urle 0 2]%$[:pick $urle 2 4]" }
        :if ([:len $urle] = 6) do={:set sym "%$[:pick $urle 0 2]%$[:pick $urle 2 4]%$[:pick $urle 4 6]" }
        :set constr "$constr$sym"
    }
    :return $constr
}

example code

:put [$ASCIItoCP1252toURLencode ("The Euro symbol is \80 (on CP1252)")]


If the text is already on UTF-8, like readed from a file or fetched "data", must be used this:
:global UTF8toURLencode do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local UTF8toURLe {"00";"01";"02";"03";"04";"05";"06";"07";"08";"09";"0A";"0B";"0C";"0D";"0E";"0F";
                       "10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"1A";"1B";"1C";"1D";"1E";"1F";
                       "+";"21";"22";"23";"24";"25";"26";"27";"28";"29";"2A";"2B";"2C";"-";".";"2F";
                       "0";"1";"2";"3";"4";"5";"6";"7";"8";"9";"3A";"3B";"3C";"3D";"3E";"3F";
                       "40";"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";
                       "P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"5B";"5C";"5D";"5E";"_";
                       "60";"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";
                       "p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";"7B";"7C";"7D";"~";"7F";
                       "80";"81";"82";"83";"84";"85";"86";"87";"88";"89";"8A";"8B";"8C";"8D";"8E";"8F";
                       "90";"91";"92";"93";"94";"95";"96";"97";"98";"99";"9A";"9B";"9C";"9D";"9E";"9F";
                       "A0";"A1";"A2";"A3";"A4";"A5";"A6";"A7";"A8";"A9";"AA";"AB";"AC";"AD";"AE";"AF";
                       "B0";"B1";"B2";"B3";"B4";"B5";"B6";"B7";"B8";"B9";"BA";"BB";"BC";"BD";"BE";"BF";
                       "C0";"C1";"C2";"C3";"C4";"C5";"C6";"C7";"C8";"C9";"CA";"CB";"CC";"CD";"CE";"CF";
                       "D0";"D1";"D2";"D3";"D4";"D5";"D6";"D7";"D8";"D9";"DA";"DB";"DC";"DD";"DE";"DF";
                       "E0";"E1";"E2";"E3";"E4";"E5";"E6";"E7";"E8";"E9";"EA";"EB";"EC";"ED";"EE";"EF";
                       "F0";"F1";"F2";"F3";"F4";"F5";"F6";"F7";"F8";"F9";"FA";"FB";"FC";"FD";"FE";"FF"
                      }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local urle ($UTF8toURLe->[:find $ascii [:pick $string $pos ($pos + 1)] -1])
        :local sym $urle
        :if ([:len $urle] = 2) do={:set sym "%$[:pick $urle 0 2]" }
        :set constr "$constr$sym"
    }
    :return $constr
}

example code

:put [$UTF8toURLencode ("The Euro symbol is \E2\82\AC (on UTF-8)")]
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sun Feb 12, 2023 7:24 am

Function to convert UCS-2 to UTF-8
can also be used to convert UNICODE entry point from U+0000 to U+FFFF
and is ready to be converted, if needed, for UNICODE entry point from U+100000 to U+10FFFF (bigger are not valid on UNICODE)
viewtopic.php?p=983695#p983695
Last edited by rextended on Fri Feb 17, 2023 8:32 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Feb 17, 2023 8:32 pm

Function to convert UTF-8 to UCS-2
is ready to be converted, if needed, for all UNICODE entry point from U+000000 to U+10FFFF (bigger are not valid on UNICODE)
viewtopic.php?p=985041#p985041
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Feb 17, 2023 9:43 pm

Added also the function to convert UTF-8 to UCS-2 string for create the mesage part on SMS PDU encoded with UCS-2.
viewtopic.php?p=985041#p985041
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Feb 20, 2023 10:17 am

Clear the scren on terminal. Thanks to @Amm0!!!
viewtopic.php?p=985469#p985469
Last edited by rextended on Fri Mar 24, 2023 2:41 pm, edited 1 time in total.
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Mon Feb 27, 2023 2:24 pm

The list of these works shows a high level of professionalism and a wide range of interests of our esteemed Rex`a. At the same time, it is obvious that he is interested in solving complex, mostly algorithmically interesting problems of applied programming in the Router OS scripting language. I would like to wish the author further success and would ask him not to submit this as a general list sorted by the date of creation, but also to separately arrange his masterpieces in a library of scripts, united in semantic sections. For example, sorting functions, transcoding functions, time management functions, etc... so that users can quickly find the required script or group of scripts.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Mar 07, 2023 6:09 pm

Thank you very much, but tidying up also takes a lot of time ;)
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Mar 08, 2023 2:06 pm

Function to convert a string (or a Byte stream) to Base64 based on RFC 4648
Optional "url" parameter use URL and filename-safe standard encoding.
Optional "nopad" parameter do not put the padding "=" character (is optional on RFC 4648).

viewtopic.php?p=988931#p988931
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Mar 09, 2023 1:29 pm

Function for decode a Base64 string based on RFC 4648

Optional "url" parameter use URL and filename-safe encoding instead ot the standard encoding.

Optional "mustpad" parameter, if is present, consider invalid Base64 input when do not have the required padding (is optional on RFC 4648).

Optional "ignoreotherchr" parameter: if is present one non-ecoding character, continue the decoding sequence skipping that.
For RFC 4648 instead is a blocking error.

viewtopic.php?p=989112#p989112
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 10, 2023 2:21 pm

Function to convert a string (or a Byte stream) to Base16

Optional "lowercase" use lowercase a-f in place of the correct A-F

viewtopic.php?p=989286#p989286
Last edited by rextended on Fri Mar 10, 2023 3:08 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 10, 2023 2:40 pm

Function to convert Base16 to string (or a Byte stream)

Option "ignoreodd" ignore if the decoded string have odd value (must be have only character pairs).

viewtopic.php?p=989289#p989289
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 10, 2023 7:41 pm

Function to convert a string (or a Byte stream) to Base32 based on RFC 4648
Optional "nopad" parameter do not put the padding "=" character (is optional on RFC 4648).
Optional "hex" parameter use RFC 4648 base32 Extended Hex Alphabet encoding instead ot the standard encoding.

viewtopic.php?p=989344#p989344
Last edited by rextended on Fri Mar 10, 2023 9:49 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 10, 2023 9:38 pm

Function for decode a Base32 string based on RFC 4648

Optional "mustpad" parameter, if is present, consider invalid Base32 input when do not have the required padding (is optional on RFC 4648).
Optional "hex" parameter use RFC 4648 base32 Extended Hex Alphabet encoding instead ot the standard encoding.

viewtopic.php?p=989358#p989358
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Mar 15, 2023 12:19 pm

Functions to convert a string to lowercase, uppercase or proper case (only the first letter up, the other low)
Any other non A-Z a-z character passed remain unchanged.

Optional parameter:
1) no parameter convert the first letter uppercase, all the others lowercase.
2) "U" convert to upper case
3) "L" convert to lower case
4) "P" convert to proper case: only the first letter on each word are uppercase, the remaining lower.

viewtopic.php?p=990121#p990121
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Mar 28, 2023 3:17 am

This is relevant for working with PDU, not for directly read/write SMS on GSM7 format, on second time is maded one converter.

Function to convert one CP1252 (or simply ASCII-7-bit) string to one Hex GSM7 string for create the PDU.
:global CP1252toHexGSM7 do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"

    :local gsm7b {"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"0A";"20";"1B0D";"0D";"20";"20";
                  "20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";
                  "20";"21";"22";"23";"02";"25";"26";"27";"28";"29";"2A";"2B";"2C";"2D";"2E";"2F";
                  "30";"31";"32";"33";"34";"35";"36";"37";"38";"39";"3A";"3B";"3C";"3D";"3E";"3F";
                  "00";"41";"42";"43";"44";"45";"46";"47";"48";"49";"4A";"4B";"4C";"4D";"4E";"4F";
                  "50";"51";"52";"53";"54";"55";"56";"57";"58";"59";"5A";"1B3C";"1B2F";"1B3E";"1B14";"11";
                  "27";"61";"62";"63";"64";"65";"66";"67";"68";"69";"6A";"6B";"6C";"6D";"6E";"6F";
                  "70";"71";"72";"73";"74";"75";"76";"77";"78";"79";"7A";"1B28";"1B40";"1B29";"1B3D";"20";
                  "1B65";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";
                  "20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";
                  "20";"40";"20";"01";"24";"03";"20";"5F";"20";"20";"20";"20";"20";"20";"20";"20";
                  "20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"20";"60";
                  "20";"20";"20";"20";"5B";"0E";"1C";"09";"20";"1F";"20";"20";"20";"20";"20";"20";
                  "20";"5D";"20";"20";"20";"20";"5C";"20";"0B";"20";"20";"20";"5E";"20";"20";"1E";
                  "7F";"20";"20";"20";"7B";"0F";"1D";"20";"04";"05";"20";"20";"07";"20";"20";"20";
                  "20";"7D";"08";"20";"20";"20";"7C";"20";"0C";"06";"20";"20";"7E";"20";"20";"20";
                 }
# CP1253 Greek do not support any 0x7F-0xFF except:
# Euro  0x80=1B65
# Pound 0xA3=01, Currency 0xA4=24, Yen   0xA5=03, Section 0xA7=5F
# Gamma 0xC3=13, Delta    0xC4=10, Theta 0xC8=19, Lambda  0xCB=14, Xi      0xCE=1A
# Pi    0xD0=16, Sigma    0xD3=18, Phi   0xD6=12, Psi     0xD8=17, Omega   0xD9=15

    :local input $1
    :if (([:typeof $input] != "str") or ($input = "")) do={:return ""}
    :local inputlen [:len $input]
    :local convstr ""
    :for pos from=0 to=($inputlen - 1) do={
        :local gsmchr "$($gsm7b->[:find $ascii [:pick $input $pos ($pos + 1)] -1])"
        :set convstr "$convstr$gsmchr"
    }
    :return $convstr
}

example code

[] > :put [$CP1252toHexGSM7 ("Hi to All! [@~)]")]
486920746F20416C6C21201B3C001B3D291B3E

# calculate characters needed, max single GSM7 SMS is 160 characters
[] > :put ([:len [$CP1252toHexGSM7 ("Hi to All! [@~)]")]] / 2)
19
Last edited by rextended on Tue Mar 28, 2023 5:07 pm, edited 7 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Mar 28, 2023 3:59 pm

Function to convert Hex GSM7 to CP1252 string

Option "ignoreodd" ignore if the decoded string have odd value (must be have only character pairs).

This is for decode the GSM7 string after extracting that for PDU.

For extract the GSM7 string from PDU must be used another function.
:global HexGSM7toCP1252 do={
    :local cp1252 {"\40";"\A3";"\24";"\A5";"\E8";"\E9";"\F9";"\EC";"\F2";"\C7";"\0A";"\D8";"\F8";"\0D";"\C5";"\E5";
                   "\20";"\5F";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\1B";"\C6";"\E6";"\DF";"\C9";
                   "\20";"\21";"\22";"\23";"\A4";"\25";"\26";"\27";"\28";"\29";"\2A";"\2B";"\2C";"\2D";"\2E";"\2F";
                   "\30";"\31";"\32";"\33";"\34";"\35";"\36";"\37";"\38";"\39";"\3A";"\3B";"\3C";"\3D";"\3E";"\3F";
                   "\A1";"\41";"\42";"\43";"\44";"\45";"\46";"\47";"\48";"\49";"\4A";"\4B";"\4C";"\4D";"\4E";"\4F";
                   "\50";"\51";"\52";"\53";"\54";"\55";"\56";"\57";"\58";"\59";"\5A";"\C4";"\D6";"\D1";"\DC";"\A7";
                   "\BF";"\61";"\62";"\63";"\64";"\65";"\66";"\67";"\68";"\69";"\6A";"\6B";"\6C";"\6D";"\6E";"\6F";
                   "\70";"\71";"\72";"\73";"\74";"\75";"\76";"\77";"\78";"\79";"\7A";"\E4";"\F6";"\F1";"\FC";"\E0";
                   "\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\0C";"\20";"\20";"\0D";"\20";"\20";
                   "\20";"\20";"\20";"\20";"\5E";"\20";"\20";"\20";"\20";"\20";"\20";"\1B";"\20";"\20";"\20";"\20";
                   "\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\7B";"\7D";"\20";"\20";"\20";"\20";"\20";"\5C";
                   "\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\5B";"\7E";"\5D";"\20";
                   "\7C";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";
                   "\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";
                   "\20";"\20";"\20";"\20";"\20";"\80";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";
                   "\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20";"\20"
                  }

    :local input   [:tostr "$1"]
    :local options [:tostr "$2"]

    :local lowerarray {"a"="A";"b"="B";"c"="C";"d"="D";"e"="E";"f"="F"}

    :if (!($input~"^[0-9A-Fa-f]*\$")) do={
        :error "invalid characters: only 0-9, A-F and a-f are valid HexGSM7 values"
    }

    :if (!($options~"ignoreodd")) do={
        :if (([:len $input] % 2) != 0) do={:error "Invalid length, is odd."}
    }

    :local position 0
    :local output   "" ; :local work "" ; :local worknum 0 ; :local chk1 "" ; :local chk2 ""
    :while ($position < [:len $input]) do={
        :set chk1 [:pick $input $position       ($position + 1)]
        :set chk2 [:pick $input ($position + 1) ($position + 2)]
        :if ($chk1~"[a-f]") do={:set chk1 ($lowerarray->$chk1)}
        :if ($chk2~"[a-f]") do={:set chk2 ($lowerarray->$chk2)}
        :set work "$chk1$chk2"
        :if ([:len $work] = 2) do={
            :set worknum [:tonum "0x$work"]
            :if ($worknum > 0x7F) do={:error "Invalid 7-bit value ($worknum)"}
            :if ($work = "1B") do={
                :set chk1 [:pick $input ($position + 2) ($position + 3)]
                :set chk2 [:pick $input ($position + 3) ($position + 4)]
                :if ($chk1~"[a-f]") do={:set chk1 ($lowerarray->$chk1)}
                :if ($chk2~"[a-f]") do={:set chk2 ($lowerarray->$chk2)}
                :set work "$chk1$chk2"
                :if ([:len $work] = 2) do={
                    :set worknum [:tonum "0x$work"]
                    :if ($worknum > 0x7F) do={:error "Invalid 7-bit value after Escape (1B$worknum)"}
                    :if ($work = "1B") do={:error "Invalid Double Escape value"}
                    :set work ($cp1252->($worknum | 0x80))
                } else={:set work ""}
                :set position ($position + 2)
            } else={
                :set work ($cp1252->$worknum)
            }
        } else={:set work ""}
        :set output   "$output$work"
        :set position ($position + 2)
    }
    :return $output
}

example code

[] > :put [$HexGSM7toCP1252 ("486920746F20416C6C21201B3C001B3D291B3E")]
Hi to All! [@~)]
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 10:43 am

Rex, sorry for asking, are you a professional programmer? What programming languages ​​do you have experience with? Is Mikrotik your hobby or your main job? What is your main profession?
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1025
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 11:08 am

Okay, didn't you know Rextended is actually a ChatGPT bot? ; -)
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 11:30 am

Come on... You are a joker !
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 12:28 pm

Do not offtopic this tread, is only for snippets.

But I'll answer the same for those who wonder.

Currently I'm a WISP in Italy with MikroTik, Ceragon, Ubiquiti and Cambium equipment (in order of importance).
In school (when I was 11) we were taught Turbo Pascal, from there the programming has always fascinated me.
They gave me an old computer, a CPM/86 with DOS 3 I learned to tinker with debugging and assembler...
On free time I have studied source code of Quake and Quake 2 (written on "C"), rewriting the game as I and my friends wanted, then we'd play games together...
Not to mention playing Doom with serial ports.... :lol:
Then in high school I did Electronics and Telecommunications as a specialization, but it was I who taught the professors and comrades in the computer lab...
I didn't want to go to university, I was bored enough, so I started working on my own as a programmer
(JScript, VBScript, Visual Basic, ASP, "handmade" HTML..., SQL DB and Oracle DB, I sure forgot something....),
but then when in 2003, in Italy, they "liberalized" the 5GHz I also started experimenting with data transport,
until on 2007 (choosing the MikroTik devices) I opened a WISP with other partners.

Now if I program something I do it for me, since by now the WISP has become the main job.
In my life I've learned to get what I need based on what I know and what I have available,
so the versatility of scripting with MikroTik also lets me do things not related to data transport, such as controlling solar cells and groups generators.

That's all, if you have more questions, please open a separate topic.
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 12:50 pm

Rex, thanks for your reply. I can add that in our school years we had a lot in common (I was fond of system programming on the Apple II and its Russian analogue PC AGAT), but then you became a programmer, and I was a doctor. Sorry for cluttering up this thread. You can delete these posts from here. I would like to write something to you personally, but I don't know how to do it through the forum.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Mar 30, 2023 12:54 pm

You just did ;)
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 31, 2023 12:58 pm

function to convert GSM7 string to Hex PDU.

On future all function regarding PDU and GSM7 are armonized for work with PDU.

Optional parameter:
1) no parameter do not add the unencoded string lenght at the start
2) "addlen" add the unencoded string lenght at the start (required on PDU)

:global gsm7topdu do={
    :local input   [:tostr "$1"]
    :local options "$2"

    :local numbyte2hex do={
        :local input [:tonum $1]
        :local hexchars "0123456789ABCDEF"
        :local convert [:pick $hexchars (($input >> 4) & 0xF)]
        :set convert ($convert.[:pick $hexchars ($input & 0xF)])
        :return $convert
    }

    :local charsString ""
    :for x from=0 to=15 step=1 do={ :for y from=0 to=15 step=1 do={
        :local tmpHex "$[:pick "0123456789ABCDEF" $x ($x+1)]$[:pick "0123456789ABCDEF" $y ($y+1)]"
        :set $charsString "$charsString$[[:parse "(\"\\$tmpHex\")"]]"
    } }

    :local chr2int do={:if (($1="") or ([:len $1] > 1) or ([:typeof $1] = "nothing")) do={:return -1}; :return [:find $2 $1 -1]}

    :local position 0
    :local output "" ; :local work ""
    :local v1 0 ; :local v2 0 ; :local v3 0 ; :local v4 0 ; :local v5 0 ; :local v6 0 ; :local v7 0 ; :local v8 0
    :local ch1 "" ; :local ch2 "" ; :local ch3 "" ; :local ch4 "" ; :local ch5 "" ; :local ch6 "" ; :local ch7 ""

    :while ($position < [:len $input]) do={
        :set work [:pick $input $position ($position + 8)]
        :set v1 [$chr2int [:pick $work 0 1] $charsString]
        :set v2 [$chr2int [:pick $work 1 2] $charsString]
        :set v3 [$chr2int [:pick $work 2 3] $charsString]
        :set v4 [$chr2int [:pick $work 3 4] $charsString]
        :set v5 [$chr2int [:pick $work 4 5] $charsString]
        :set v6 [$chr2int [:pick $work 5 6] $charsString]
        :set v7 [$chr2int [:pick $work 6 7] $charsString]
        :set v8 [$chr2int [:pick $work 7 8] $charsString]

        :if (($v1 > 0x7F) or ($v2 > 0x7F) or ($v3 > 0x7F) or ($v4 > 0x7F) or \
             ($v5 > 0x7F) or ($v6 > 0x7F) or ($v7 > 0x7F) or ($v8 > 0x7F)) do={
            :error "Unexpected 8-bit character value"
        }

        :set ch1 [$numbyte2hex ((($v2 & 0x01) << 7) +  $v1      ) ]
        :set ch2 [$numbyte2hex ((($v3 & 0x03) << 6) + ($v2 >> 1)) ]
        :set ch3 [$numbyte2hex ((($v4 & 0x07) << 5) + ($v3 >> 2)) ]
        :set ch4 [$numbyte2hex ((($v5 & 0x0F) << 4) + ($v4 >> 3)) ]
        :set ch5 [$numbyte2hex ((($v6 & 0x1F) << 3) + ($v5 >> 4)) ]
        :set ch6 [$numbyte2hex ((($v7 & 0x3F) << 2) + ($v6 >> 5)) ]
        :set ch7 [$numbyte2hex ((($v8 & 0x7F) << 1) + ($v7 >> 6)) ]

                 :if ([:len $work] = 8) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6$ch7"
        } else={ :if ([:len $work] = 7) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6$[$numbyte2hex ($v7 >> 6)]"
        } else={ :if ([:len $work] = 6) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6"
        } else={ :if ([:len $work] = 5) do={:set work "$ch1$ch2$ch3$ch4$ch5"
        } else={ :if ([:len $work] = 4) do={:set work "$ch1$ch2$ch3$ch4"
        } else={ :if ([:len $work] = 3) do={:set work "$ch1$ch2$ch3"
        } else={ :if ([:len $work] = 2) do={:set work "$ch1$ch2"
        } else={ :if ([:len $work] = 1) do={:set work "$ch1"
        }}}}}}}}

        :set output "$output$work"
        :set position ($position + 8)
    }

    :if ($options~"addlen") do={:set output "$[$numbyte2hex [:len $input]]$output"}

    :return $output
}

example code

[] > :put [$gsm7topdu ("Hi to All!!!")]
C83488FE0605D9EC502804

[] > :put [$gsm7topdu ("Hi to All!!!") "addlen"]
0CC83488FE0605D9EC502804
Last edited by rextended on Fri Mar 31, 2023 2:25 pm, edited 3 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Mar 31, 2023 1:58 pm

function to convert PDU (already on GSM7 alphabet) to Hex GSM7 string

On future all function regarding PDU and GSM7 are armonized for work with PDU.

Optional parameter:
1) "skiplen" skip the string lenght at the start (present on PDU)
2) "ignoreinvalid" ignore invalid PDU sequence if the last value suppose another character to decode.
:global pdutogsm7 do={
    :local input   [:tostr "$1"]
    :local options "$2$3"

    :if ($options~"skiplen") do={:set input [:pick $input 1 [:len $input]]}

    :local numbyte2hex do={
        :local input [:tonum $1]
        :local hexchars "0123456789ABCDEF"
        :local convert [:pick $hexchars (($input >> 4) & 0xF)]
        :set convert ($convert.[:pick $hexchars ($input & 0xF)])
        :return $convert
    }

    :local charsString ""
    :for x from=0 to=15 step=1 do={ :for y from=0 to=15 step=1 do={
        :local tmpHex "$[:pick "0123456789ABCDEF" $x ($x+1)]$[:pick "0123456789ABCDEF" $y ($y+1)]"
        :set $charsString "$charsString$[[:parse "(\"\\$tmpHex\")"]]"
    } }

    :local chr2int do={:if (($1="") or ([:len $1] > 1) or ([:typeof $1] = "nothing")) do={:return -1}; :return [:find $2 $1 -1]}

    :local position 0
    :local output "" ; :local work ""
    :local v1 0 ; :local v2 0 ; :local v3 0 ; :local v4 0 ; :local v5 0 ; :local v6 0 ; :local v7 0
    :local ch1 "" ; :local ch2 "" ; :local ch3 "" ; :local ch4 "" ; :local ch5 "" ; :local ch6 "" ; :local ch7 "" ; :local ch8 ""
    :local errorinvalid "Invalid PDU data, expected value not provided."

    :while ($position < [:len $input]) do={
        :set work [:pick $input $position ($position + 7)]
        :set v1 [$chr2int [:pick $work 0 1] $charsString]
        :set v2 [$chr2int [:pick $work 1 2] $charsString]
        :set v3 [$chr2int [:pick $work 2 3] $charsString]
        :set v4 [$chr2int [:pick $work 3 4] $charsString]
        :set v5 [$chr2int [:pick $work 4 5] $charsString]
        :set v6 [$chr2int [:pick $work 5 6] $charsString]
        :set v7 [$chr2int [:pick $work 6 7] $charsString]

        :if (!($options~"ignoreinvalid")) do={
            :if (([:len $work] = 1) and (($v1 >> 7) != 0)) do={:error $errorinvalid}
            :if (([:len $work] = 2) and (($v2 >> 6) != 0)) do={:error $errorinvalid}
            :if (([:len $work] = 3) and (($v3 >> 5) != 0)) do={:error $errorinvalid}
            :if (([:len $work] = 4) and (($v4 >> 4) != 0)) do={:error $errorinvalid}
            :if (([:len $work] = 5) and (($v5 >> 3) != 0)) do={:error $errorinvalid}
            :if (([:len $work] = 6) and (($v6 >> 2) != 0)) do={:error $errorinvalid}
        }

        :set ch1 [$numbyte2hex (  $v1                     & 0x7F) ]
        :set ch2 [$numbyte2hex ((($v2 << 1) + ($v1 >> 7)) & 0x7F) ]
        :set ch3 [$numbyte2hex ((($v3 << 2) + ($v2 >> 6)) & 0x7F) ]
        :set ch4 [$numbyte2hex ((($v4 << 3) + ($v3 >> 5)) & 0x7F) ]
        :set ch5 [$numbyte2hex ((($v5 << 4) + ($v4 >> 4)) & 0x7F) ]
        :set ch6 [$numbyte2hex ((($v6 << 5) + ($v5 >> 3)) & 0x7F) ]
        :set ch7 [$numbyte2hex ((($v7 << 6) + ($v6 >> 2)) & 0x7F) ]
        :set ch8 [$numbyte2hex ((              $v7 >> 1)  & 0x7F) ]

                 :if (([:len $work] = 7) and ($ch8 != "00")) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6$ch7$ch8"
        } else={ :if ( [:len $work] = 7                    ) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6$ch7"
        } else={ :if ( [:len $work] = 6                    ) do={:set work "$ch1$ch2$ch3$ch4$ch5$ch6"
        } else={ :if ( [:len $work] = 5                    ) do={:set work "$ch1$ch2$ch3$ch4$ch5"
        } else={ :if ( [:len $work] = 4                    ) do={:set work "$ch1$ch2$ch3$ch4"
        } else={ :if ( [:len $work] = 3                    ) do={:set work "$ch1$ch2$ch3"
        } else={ :if ( [:len $work] = 2                    ) do={:set work "$ch1$ch2"
        } else={ :if ( [:len $work] = 1                    ) do={:set work "$ch1"
        }}}}}}}}

        :set output "$output$work"
        :set position ($position + 7)
    }

    :return $output
}



example code

[] > :put [$pdutogsm7 ("\C8\34\88\FE\06\05\D9\EC\50\28\04")]
486920746F20416C6C212121

:put [$HexGSM7toCP1252  [$pdutogsm7 ("\C8\34\88\FE\06\05\D9\EC\50\28\04")]]
Hi to All!!!

:put [$HexGSM7toCP1252  "486920746F20416C6C212121"]
Hi to All!!!

[] > :put [$pdutogsm7 ("\C8\34\88\FE\06\05\D9\EC\50\28")]
Invalid PDU data, expected value not provided.

[] > :put [$pdutogsm7 ("\C8\34\88\FE\06\05\D9\EC\50\28") "ignoreinvalid"]
486920746F20416C6C212121

:put [$HexGSM7toCP1252  "486920746F20416C6C2121"]
Hi to All!!
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Apr 01, 2023 11:23 am

I just noticed that the function gsm7topdu on this post
viewtopic.php?t=177551#p993428

Can be used also to convert (and the pdutogsm7 to read it back) the numbers used on USSD code...

example code

[] > :put [$gsm7topdu ("*101#")]
AA182C3602

/int lte at-chat lte1 input="AT+CUSD=1,\"$[$gsm7topdu ("*101#")]\",15" wait=yes
NOTE: Some deice support directly the use of USSD code without coding it:
/int lte at-chat lte1 input="AT+CUSD=1,\"*101#\",15" wait=yes
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Apr 04, 2023 12:25 am

Convert DWORD FLOAT as IEEE754 to number

viewtopic.php?t=186070#p994119
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Apr 10, 2023 5:33 pm

Convert datetime date or time to epoch

Accept imput as "mmm/dd/yyyy hh:mm:ss" or "mmm/dd hh:mm:ss" or only "hh:mm:ss". The last two for read the date also from next-run on scheduler or from the logs, etc.
The month can be on lowercase, 1st case or uppercase like apr, Apr or APR

viewtopic.php?p=994849#p994849

added:
accept also imput as "yyyy-MM-dd hh:mm:ss" or "MM-dd hh:mm:ss"
Last edited by rextended on Thu May 11, 2023 1:35 am, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu May 11, 2023 1:32 am

Added RouterOS v7.10+ compatibility to all scripts in links, when they concern dates in 2023-05-11 or 05-11 format
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1275
Joined: Tue Jun 23, 2015 2:35 pm

Re: ✂ Rextended Fragments of Snippets

Thu May 11, 2023 1:24 pm

well done
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu May 11, 2023 2:12 pm

well done
Thanks ;)
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sun May 28, 2023 1:44 pm

Send the only wanted Logs by Telegram messages:

one telegram message for each new log entry code
viewtopic.php?p=1004552#p1004546

one unique telegram message with all new log entry code
viewtopic.php?p=1004552#p1004552
Last edited by rextended on Tue Jan 16, 2024 10:11 am, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue May 30, 2023 8:24 pm

Send the only wanted Logs by Telegram messages:
[…]
Added the possibility to remove unwanted topics, like ipsec phase1 negotiation failed
Last edited by rextended on Tue Jan 16, 2024 10:11 am, edited 4 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Jun 17, 2023 11:17 pm

Send the only wated Logs by Telegram messages:
[…]
Added the possibility to trim the length of the messages
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jun 23, 2023 11:52 pm

Prevent the script running, inside the script, if the script already is running.

viewtopic.php?t=197314#p1009493
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Jul 06, 2023 5:29 pm

"Can a script be created if a wrong login name is used":
viewtopic.php?p=929454#p929373
derived from:
viewtopic.php?p=917307#p917428
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Jul 12, 2023 10:18 am

 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jul 14, 2023 10:12 am

CP1251 Cyrillic variant

Convert string from ASCII 8-bit CP1251 to UNICODE entry points
:global ASCIItoCP1251toUNICODE do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1251toUNICODE {"0000";"0001";"0002";"0003";"0004";"0005";"0006";"0007";"0008";"0009";"000A";"000B";"000C";"000D";"000E";"000F";
                         "0010";"0011";"0012";"0013";"0014";"0015";"0016";"0017";"0018";"0019";"001A";"001B";"001C";"001D";"001E";"001F";
                         "0020";"0021";"0022";"0023";"0024";"0025";"0026";"0027";"0028";"0029";"002A";"002B";"002C";"002D";"002E";"002F";
                         "0030";"0031";"0032";"0033";"0034";"0035";"0036";"0037";"0038";"0039";"003A";"003B";"003C";"003D";"003E";"003F";
                         "0040";"0041";"0042";"0043";"0044";"0045";"0046";"0047";"0048";"0049";"004A";"004B";"004C";"004D";"004E";"004F";
                         "0050";"0051";"0052";"0053";"0054";"0055";"0056";"0057";"0058";"0059";"005A";"005B";"005C";"005D";"005E";"005F";
                         "0060";"0061";"0062";"0063";"0064";"0065";"0066";"0067";"0068";"0069";"006A";"006B";"006C";"006D";"006E";"006F";
                         "0070";"0071";"0072";"0073";"0074";"0075";"0076";"0077";"0078";"0079";"007A";"007B";"007C";"007D";"007E";"007F";
                         "0402";"0403";"201A";"0453";"201E";"2026";"2020";"2021";"20AC";"2030";"0409";"2039";"040A";"040C";"040B";"040F";
                         "0452";"2018";"2019";"201C";"201D";"2022";"2013";"2014";"FFFD";"2122";"0459";"203A";"045A";"045C";"045B";"045F";
                         "00A0";"040E";"045E";"0408";"00A4";"0490";"00A6";"00A7";"0401";"00A9";"0404";"00AB";"00AC";"00AD";"00AE";"0407";
                         "00B0";"00B1";"0406";"0456";"0491";"00B5";"00B6";"00B7";"0451";"2116";"0454";"00BB";"0458";"0405";"0455";"0457";
                         "0410";"0411";"0412";"0413";"0414";"0415";"0416";"0417";"0418";"0419";"041A";"041B";"041C";"041D";"041E";"041F";
                         "0420";"0421";"0422";"0423";"0424";"0425";"0426";"0427";"0428";"0429";"042A";"042B";"042C";"042D";"042E";"042F";
                         "0430";"0431";"0432";"0433";"0434";"0435";"0436";"0437";"0438";"0439";"043A";"043B";"043C";"043D";"043E";"043F";
                         "0440";"0441";"0442";"0443";"0444";"0445";"0446";"0447";"0448";"0449";"044A";"044B";"044C";"044D";"044E";"044F"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local unicode "0x$($CP1251toUNICODE->[:find $ascii [:pick $string $pos ($pos + 1)] -1]) "
        :set constr "$constr$unicode"
    }
    :return $constr
}

:put [$ASCIItoCP1251toUNICODE ("\F2\E5\F1\F2")]
тест = \F2\E5\F1\F2 = 0x0442 0x0435 0x0441 0x0442

0x98 (not assigned on CP1251) => 0xFFFD REPLACEMENT CHARACTER �



Convert string from ASCII 8-bit CP1251 to UTF-8 string with each byte escaped with %
:global ASCIItoCP1251toUTF8 do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1251toUTF8 {"00";"01";"02";"03";"04";"05";"06";"07";"08";"09";"0A";"0B";"0C";"0D";"0E";"0F";
                         "10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"1A";"1B";"1C";"1D";"1E";"1F";
                         "20";"21";"22";"23";"24";"25";"26";"27";"28";"29";"2A";"2B";"2C";"2D";"2E";"2F";
                         "30";"31";"32";"33";"34";"35";"36";"37";"38";"39";"3A";"3B";"3C";"3D";"3E";"3F";
                         "40";"41";"42";"43";"44";"45";"46";"47";"48";"49";"4A";"4B";"4C";"4D";"4E";"4F";
                         "50";"51";"52";"53";"54";"55";"56";"57";"58";"59";"5A";"5B";"5C";"5D";"5E";"5F";
                         "60";"61";"62";"63";"64";"65";"66";"67";"68";"69";"6A";"6B";"6C";"6D";"6E";"6F";
                         "70";"71";"72";"73";"74";"75";"76";"77";"78";"79";"7A";"7B";"7C";"7D";"7E";"7F";
      "D082";"D083";"E2809A";"D193";"E2809E";"E280A6";"E280A0";"E280A1";"E282AC";"E280B0";"D089";"E280B9";"D08A";"D08C";"D08B";"D08F";
      "D192";"E28098";"E28099";"E2809C";"E2809D";"E280A2";"E28093";"E28094";"EFBFBD";"E284A2";"D199";"E280BA";"D19A";"D19C";"D19B";"D19F";
                         "C2A0";"D08E";"D19E";"D088";"C2A4";"D290";"C2A6";"C2A7";"D081";"C2A9";"D084";"C2AB";"C2AC";"C2AD";"C2AE";"D087";
                         "C2B0";"C2B1";"D086";"D196";"D291";"C2B5";"C2B6";"C2B7";"D191";"E28496";"D194";"C2BB";"D198";"D085";"D195";"D197";
                         "D090";"D091";"D092";"D093";"D094";"D095";"D096";"D097";"D098";"D099";"D09A";"D09B";"D09C";"D09D";"D09E";"D09F";
                         "D0A0";"D0A1";"D0A2";"D0A3";"D0A4";"D0A5";"D0A6";"D0A7";"D0A8";"D0A9";"D0AA";"D0AB";"D0AC";"D0AD";"D0AE";"D0AF";
                         "D0B0";"D0B1";"D0B2";"D0B3";"D0B4";"D0B5";"D0B6";"D0B7";"D0B8";"D0B9";"D0BA";"D0BB";"D0BC";"D0BD";"D0BE";"D0BF";
                         "D180";"D181";"D182";"D183";"D184";"D185";"D186";"D187";"D188";"D189";"D18A";"D18B";"D18C";"D18D";"D18E";"D18F"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local utf ($CP1251toUTF8->[:find $ascii [:pick $string $pos ($pos + 1)] -1])
        :local sym ""
        :if ([:len $utf] = 2) do={:set sym "%$[:pick $utf 0 2]" }
        :if ([:len $utf] = 4) do={:set sym "%$[:pick $utf 0 2]%$[:pick $utf 2 4]" }
        :if ([:len $utf] = 6) do={:set sym "%$[:pick $utf 0 2]%$[:pick $utf 2 4]%$[:pick $utf 4 6]" }
        :set constr "$constr$sym"
    }
    :return $constr
}

:put [$ASCIItoCP1251toUTF8 ("\F2\E5\F1\F2")]
0x98 (not assigned on CP1251) => %EF%BF%BD REPLACEMENT CHARACTER �

тест = \F2\E5\F1\F2 = %D1%82%D0%B5%D1%81%D1%82

The BOM, Byte Order Mark for UTF-8 is "%EF%BB%BF"
Last edited by rextended on Mon Jul 17, 2023 5:45 pm, edited 2 times in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Jul 15, 2023 3:05 am

CP1251 Cyrillic variant: Function to URL encode the strings for the GET fields for "/tool fetch"
(a submitted GET form can be simulated with http-header-field="Content-Type:application/x-www-form-urlencoded")

or POST with datatype application/x-www-form-urlencoded
(http-header-field="Content-Type:application/x-www-form-urlencoded" http-data="<DATA encoded with ASCIItoCP1251toURLencode>")

Only 4 characters - . _ ~ must not be escaped, and space must be replaced with +
:global ASCIItoCP1251toURLencode do={
    :local ascii "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                  \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                  \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                  \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                  \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                  \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                  \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                  \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                  \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                  \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                  \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                  \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                  \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                  \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                  \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                  \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local CP1251toURLe {"00";"01";"02";"03";"04";"05";"06";"07";"08";"09";"0A";"0B";"0C";"0D";"0E";"0F";
                         "10";"11";"12";"13";"14";"15";"16";"17";"18";"19";"1A";"1B";"1C";"1D";"1E";"1F";
                         "+";"21";"22";"23";"24";"25";"26";"27";"28";"29";"2A";"2B";"2C";"-";".";"2F";
                         "0";"1";"2";"3";"4";"5";"6";"7";"8";"9";"3A";"3B";"3C";"3D";"3E";"3F";
                         "40";"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";
                         "P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"5B";"5C";"5D";"5E";"_";
                         "60";"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";
                         "p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";"7B";"7C";"7D";"~";"7F";
      "D082";"D083";"E2809A";"D193";"E2809E";"E280A6";"E280A0";"E280A1";"E282AC";"E280B0";"D089";"E280B9";"D08A";"D08C";"D08B";"D08F";
      "D192";"E28098";"E28099";"E2809C";"E2809D";"E280A2";"E28093";"E28094";"EFBFBD";"E284A2";"D199";"E280BA";"D19A";"D19C";"D19B";"D19F";
                         "C2A0";"D08E";"D19E";"D088";"C2A4";"D290";"C2A6";"C2A7";"D081";"C2A9";"D084";"C2AB";"C2AC";"C2AD";"C2AE";"D087";
                         "C2B0";"C2B1";"D086";"D196";"D291";"C2B5";"C2B6";"C2B7";"D191";"E28496";"D194";"C2BB";"D198";"D085";"D195";"D197";
                         "D090";"D091";"D092";"D093";"D094";"D095";"D096";"D097";"D098";"D099";"D09A";"D09B";"D09C";"D09D";"D09E";"D09F";
                         "D0A0";"D0A1";"D0A2";"D0A3";"D0A4";"D0A5";"D0A6";"D0A7";"D0A8";"D0A9";"D0AA";"D0AB";"D0AC";"D0AD";"D0AE";"D0AF";
                         "D0B0";"D0B1";"D0B2";"D0B3";"D0B4";"D0B5";"D0B6";"D0B7";"D0B8";"D0B9";"D0BA";"D0BB";"D0BC";"D0BD";"D0BE";"D0BF";
                         "D180";"D181";"D182";"D183";"D184";"D185";"D186";"D187";"D188";"D189";"D18A";"D18B";"D18C";"D18D";"D18E";"D18F"
                        }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :local urle ($CP1251toURLe->[:find $ascii [:pick $string $pos ($pos + 1)] -1])
        :local sym $urle
        :if ([:len $urle] = 2) do={:set sym "%$[:pick $urle 0 2]" }
        :if ([:len $urle] = 4) do={:set sym "%$[:pick $urle 0 2]%$[:pick $urle 2 4]" }
        :if ([:len $urle] = 6) do={:set sym "%$[:pick $urle 0 2]%$[:pick $urle 2 4]%$[:pick $urle 4 6]" }
        :set constr "$constr$sym"
    }
    :return $constr
}

example code

:put [$ASCIItoCP1251toURLencode ("test on Cyrillic is \F2\E5\F1\F2 (on CP1251)")]
\F2\E5\F1\F2 = тест

result:
test+on+Cyrillic+is+%D1%82%D0%B5%D1%81%D1%82+%28on+CP1251%29

If the text is already on UTF-8, like readed from a file or fetched "data", must be used this:
viewtopic.php?p=1013152#p980163
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Sat Jul 15, 2023 3:18 am

Now it's time to create CP1251toHexGSM7, but... GSM-7 doesn't support Cyrillic characters at all,
so it is impossible to write a function to convert something written with CP1251 and convert it into an SMS written on GSM-7 (unless you just use a-z, etc).

At this point it is more accurate to write a function based on GOST 7.79-2000 that transliterates symbols from Cyrillic to the Latin characters on ASCII-7 bit.
Of course this is only if you really can't send the message in UCS-2 format, since UCS-2 supports (maybe) all languages...

So...

Process to convert one CP1251 string to one transliterated ASCII-7 bit only string for create the PDU.

First:
Convert the string from CP1251 to transliterated ASCII-7 bit only using GOST 7.79-2000 as guide.
:global CP1251to7BITbyGHOST do={
    :local CP1251 "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\
                   \10\11\12\13\14\15\16\17\18\19\1A\1B\1C\1D\1E\1F\
                   \20\21\22\23\24\25\26\27\28\29\2A\2B\2C\2D\2E\2F\
                   \30\31\32\33\34\35\36\37\38\39\3A\3B\3C\3D\3E\3F\
                   \40\41\42\43\44\45\46\47\48\49\4A\4B\4C\4D\4E\4F\
                   \50\51\52\53\54\55\56\57\58\59\5A\5B\5C\5D\5E\5F\
                   \60\61\62\63\64\65\66\67\68\69\6A\6B\6C\6D\6E\6F\
                   \70\71\72\73\74\75\76\77\78\79\7A\7B\7C\7D\7E\7F\
                   \80\81\82\83\84\85\86\87\88\89\8A\8B\8C\8D\8E\8F\
                   \90\91\92\93\94\95\96\97\98\99\9A\9B\9C\9D\9E\9F\
                   \A0\A1\A2\A3\A4\A5\A6\A7\A8\A9\AA\AB\AC\AD\AE\AF\
                   \B0\B1\B2\B3\B4\B5\B6\B7\B8\B9\BA\BB\BC\BD\BE\BF\
                   \C0\C1\C2\C3\C4\C5\C6\C7\C8\C9\CA\CB\CC\CD\CE\CF\
                   \D0\D1\D2\D3\D4\D5\D6\D7\D8\D9\DA\DB\DC\DD\DE\DF\
                   \E0\E1\E2\E3\E4\E5\E6\E7\E8\E9\EA\EB\EC\ED\EE\EF\
                   \F0\F1\F2\F3\F4\F5\F6\F7\F8\F9\FA\FB\FC\FD\FE\FF"
    :local GHOST {"\00";"\01";"\02";"\03";"\04";"\05";"\06";"\07";"\08";"\09";"\0A";"\0B";"\0C";"\0D";"\0E";"\0F";
                  "\10";"\11";"\12";"\13";"\14";"\15";"\16";"\17";"\18";"\19";"\1A";"\1B";"\1C";"\1D";"\1E";"\1F";
                  "\20";"\21";"\22";"\23";"\24";"\25";"\26";"\27";"\28";"\29";"\2A";"\2B";"\2C";"\2D";"\2E";"\2F";
                  "\30";"\31";"\32";"\33";"\34";"\35";"\36";"\37";"\38";"\39";"\3A";"\3B";"\3C";"\3D";"\3E";"\3F";
                  "\40";"\41";"\42";"\43";"\44";"\45";"\46";"\47";"\48";"\49";"\4A";"\4B";"\4C";"\4D";"\4E";"\4F";
                  "\50";"\51";"\52";"\53";"\54";"\55";"\56";"\57";"\58";"\59";"\5A";"\5B";"\5C";"\5D";"\5E";"\5F";
                  "\60";"\61";"\62";"\63";"\64";"\65";"\66";"\67";"\68";"\69";"\6A";"\6B";"\6C";"\6D";"\6E";"\6F";
                  "\70";"\71";"\72";"\73";"\74";"\75";"\76";"\77";"\78";"\79";"\7A";"\7B";"\7C";"\7D";"\7E";"\7F";
                  "DJ";"GJ";"\82";"gj";"\84";"\85";"\86";"\87";"\80";"\89";"LJ";"\8B";"NJ";"KJ";"CJ";"DJ";
                  "dj";"\91";"\92";"\93";"\94";"\95";"\96";"\97";"\90";"\99";"lj";"\9B";"nj";"kj";"cj";"dj";
                  "\A0";"W";"w";"J";"\A4";"G";"\A6";"\A7";"YO";"\A9";"YE";"\AB";"\AC";"\AD";"\AE";"YI";
                  "\B0";"\B1";"I";"i";"g";"\B5";"\B6";"\B7";"yo";"#";"ye";"\BB";"j";"DZ";"dz";"yi";
                  "A";"B";"V";"G";"D";"E";"ZH";"Z";"I";"J";"K";"L";"M";"N";"O";"P";
                  "R";"S";"T";"U";"F";"X";"CZ";"CH";"SH";"SHH";"\"";"Y'";"'";"E'";"YU";"YA";
                  "a";"b";"v";"g";"d";"e";"zh";"z";"i";"j";"k";"l";"m";"n";"o";"p";
                  "r";"s";"t";"u";"f";"x";"cz";"ch";"sh";"shh";"\"";"y'";"'";"e'";"yu";"ya"
                }
    :local string $1
    :if (([:typeof $string] != "str") or ($string = "")) do={ :return "" }
    :local lenstr [:len $string]
    :local constr ""
    :for pos from=0 to=($lenstr - 1) do={
        :set constr "$constr$($GHOST->[:find $CP1251 [:pick $string $pos ($pos + 1)] -1])"
    }
    :return $constr
}

Example (\F2\E5\F1\F2 = тест)
:put [$CP1251to7BITbyGHOST ("\F2\E5\F1\F2")]
result:
test

Then:
Use CP1252toHexGSM7 here:
viewtopic.php?p=1013154#p992677


I apologize in advance for any mistakes, I don't know Cyrillic.
Thanks for understanding.

Conversion table used:

conversion code

АБВГДЕ Ж  ЗИЙКЛМНОПРСТУФХ Ц  Ч  Ш  Щ   Ъ Ы  Ь Э  Ю  Я  абвгде ж  зийклмнопрстуфх ц  ч  ш  щ   ъ ы  ь э  ю  я
ABVGDE ZH ZIJKLMNOPRSTUFX CZ CH SH SHH " Y' ' E' YU YA abvgde zh zijklmnoprstufx cz ch sh shh " y' ' e' yu ya

Ґ Ѓ  Ђ  Ё  Є  Ѕ  І Ї  Ј Љ  Њ  Ќ  Ћ  Ў Џ  ґ ѓ  ђ  ё  є  ѕ  і ї  ј љ  њ  ќ  ћ  ў џ
G GJ DJ YO YE DZ I YI J LJ NJ KJ CJ W DJ g gj dj yo ye dz i yi j lj nj kj cj w dj
Thanks @Ca6ko for the suggestion of GOST 7.79-2000

If someone want help, please go here:
viewtopic.php?t=197828
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Oct 20, 2023 10:05 am

Check if Script is already running:
viewtopic.php?p=1009493#p1009493
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Wed Oct 25, 2023 12:27 pm

Rex has written almost every script you can think of.
What should we do now?
It's time to hack the Router OS (scientifically speaking, reverse engineer it).
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Oct 25, 2023 1:00 pm

It's time to hack the Router OS (scientifically speaking, reverse engineer it).
There's no talking about it...
For having spoiled 6 new devices,
and having logically opened a post for each of them, as any intelligent person would have done, given that it was a topic for each device,
as is done everywhere on this and other forums,
I was banned for a few days, without the possibility of reply...
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Wed Oct 25, 2023 1:58 pm

Have you damaged 6 Mikrotik devices? It's hard to believe. What devices are these and how did this happen?
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Oct 25, 2023 6:24 pm

Have you damaged 6 Mikrotik devices? It's hard to believe. What devices are these and how did this happen?
No... language misunderstand...
spoiler = in this case used as "reveal in advance", not to break something...
 
liuyao
just joined
Posts: 9
Joined: Wed Sep 04, 2019 9:14 am
Location: China

Re: ✂ Rextended Fragments of Snippets

Tue Jan 16, 2024 4:50 am

Hello, I'm from China. I'm currently confused as to whether I can convert Chinese characters into URLencode encoding, such as "朋友你好". I've tried all the global variables you provided above, but it doesn't work. Very much looking forward to and thank you for your reply

Translation from Google
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Tue Jan 16, 2024 10:08 am

Open a separate topic.
 
liuyao
just joined
Posts: 9
Joined: Wed Sep 04, 2019 9:14 am
Location: China

Re: ✂ Rextended Fragments of Snippets

Wed Jan 17, 2024 4:57 am

 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Thu Jan 25, 2024 3:28 pm

Given the continued ingratitude of the forum's administrative staff, I will stop.

Did it cost so much to admit that, even if in good faith, the moderator had been wrong?

Someone will finally celebrate this event and be happy (is not one allusion for the administrative staff).
I feel sorry for the others, but they will no longer be able to count on my help.

Small note: unlike others who have already left in recent days, I will not delete any of my contributions on the forum.
As already written in another post, in another now deleted topic, I am too "fond" of the scripts I create to destroy them unnecessarily.
Surely there is someone who can get inspiration from it, or come in handy to someone.
 
User avatar
diamuxin
Member
Member
Posts: 319
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: ✂ Rextended Fragments of Snippets

Thu Jan 25, 2024 10:41 pm

Bad news :(

We will miss your very good scripts (especially your functions) thanks to them I have been able to learn a little more every day.
Thanks for your contribution to the Mikrotik universe.

Best regards.
 
joshhboss
Member Candidate
Member Candidate
Posts: 270
Joined: Thu Aug 01, 2019 2:13 pm

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 12:08 am

Given the continued ingratitude of the forum's administrative staff, I will stop.

Did it cost so much to admit that, even if in good faith, the moderator had been wrong?

Someone will finally celebrate this event and be happy (is not one allusion for the administrative staff).
I feel sorry for the others, but they will no longer be able to count on my help.

Small note: unlike others who have already left in recent days, I will not delete any of my contributions on the forum.
As already written in another post, in another now deleted topic, I am too "fond" of the scripts I create to destroy them unnecessarily.
Surely there is someone who can get inspiration from it, or come in handy to someone.
This truly is horrible. Between Anav and now Rex. This is a death blow basically to the forums for me. I can’t count how many times searches on google land me 8 times out of 10 to a solution or insight that swiftly lands me to a solution that came from either one of these two.

Anav specifically with me was patient and has helped me learn and have confidence to just dive deeper into the networking space.

70% of my scripts I use on a weekly basis can be linked back to Rex as well.

Sad
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26294
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 8:32 am

Very sad, that such basic ask like "can you please not use swear words" is taken as "ingratitude"
 
User avatar
BartoszP
Forum Guru
Forum Guru
Posts: 2855
Joined: Mon Jun 16, 2014 1:13 pm
Location: Poland

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 9:00 am

Given the continued ingratitude of the forum's administrative staff, I will stop.
Did it cost so much to admit that, even if in good faith, the moderator had been wrong?

Someone will finally celebrate this event and be happy (is not one allusion for the administrative staff).I feel sorry for the others, but they will no longer be able to count on my help.
...
Bad, bad news that so much knowledge is wasted and all these "feeling insulted" lost possibility to draw fully from the free sources of technical wisdom.
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 10:17 am

Very sad, that such basic ask like "can you please not use swear words" is taken as "ingratitude"
What you write is not true, and by deleting the posts, as you have already done, you erase the evidence.
You deleted my reply post, it was the first:
viewtopic.php?t=203686
I hope at least someone else has read it and remembers it.
It said that I agreed, as long as mistakes made in the past were not again held against me.

Then I get a warning from a moderator for this post:
viewtopic.php?t=196072#p1039561
The answer is from 2023-12-02 and as everyone can clearly see it is a "bump" not an edit, so the content already existed last year.
(The bump is for the topic, not for the post, obviously)
I understand that the moderator may have been confused with the dates,
but I have advised several times that normal users cannot read the warnings, or even know which post they refer to.
So it was the case, before issuing the warning, to advise the user that that post was not good, and why.

Then anyone can judge whether there are swear words in this advice.
Instead of blindly copying and pasting, try to understand what that command is for and why it was used that way.
viewtopic.php?t=196072#p1039561
A warning for this, written previous year anyway, seems more than excessive to me.
 
User avatar
woland
Member Candidate
Member Candidate
Posts: 258
Joined: Mon Aug 16, 2021 4:49 pm

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 11:18 am

Sorry, off topic, but in support of @Rextended and @Anav: they have invested incredible amounts of time and energy into this forum. Yes their tone is sometimes harsh, but the value they have created for MT should be very much appreciated by MT!
The reason why I havent given up on MT devices is these treasure troves of articles they (and of course also others) have created.
I am a home user, can´t afford consultants and I don´t have the time and budget to take courses in Latvia. The MT docs are somewhat improving, but learning from them is no easy task!
So their posts fill in a gap, a big one.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26294
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 11:20 am

This is because rextended, you never learn. What is happening here again? You start anotherr offtopic with all the complaining.
And I have to delete this post too, since it is off topic.
 
jaclaz
Long time Member
Long time Member
Posts: 557
Joined: Tue Oct 03, 2023 4:21 pm

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 11:37 am

@rextended
UNcalled for comment:
once said that your leaving the forum will deprive it from an exceptionally good source of knowledge about scripting (and not only) and that users (particularly new members like myself) will miss you, maybe you could reconsider your decision, if it is based only on this single warning.

You of course may have all the reasons in the world to take this decision, but this one - at least seen from the outside - seems not serious enough as a reason, it is not like you have been suspended/banned, it is only a warning.

I can understand how you feel that it is not appropriate/justified, or that it was delivered improperly, but it is not (should not be) the end of the world, it is like (it happened to me quite a few times) when at school the teacher gives you a vote that you find too low for the amount of work/study you did, it's not that you abandon the school or later, on a job, a manager gives you a scolding for some trifling matters and you resign just for that.

Only my two cents ...
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 11:49 am

@jaclaz and the others:
I can't continue to comment this in my topic, this on this topic is off-topic in... my topic.
So I'm not answering this anymore.

You will only see me as a normal user who reports bugs and reads the forum.
I will still continue to fix my scripts if there is an error.
I will not delete any of my contributions on the forum.
I am too "fond" of the scripts I create to destroy them unnecessarily.
I'm just happy that there are a lot of users who appreciated my work.


Thank you all.
 
Kanta
just joined
Posts: 17
Joined: Tue May 15, 2018 7:54 pm

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 1:21 pm

This is because rextended, you never learn. What is happening here again? You start anotherr offtopic with all the complaining.
And I have to delete this post too, since it is off topic.
Keep supporting the help vampires.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7038
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: ✂ Rextended Fragments of Snippets

Fri Jan 26, 2024 3:16 pm

I can't continue to comment this in my topic, this on this topic is off-topic in... my topic.
Well, this is indeed off-topic, it has nothing to do with script snippets.
 
User avatar
Sertik
Member
Member
Posts: 425
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: ✂ Rextended Fragments of Snippets

Tue Feb 13, 2024 10:55 am

I haven’t visited the forum for a long time... I recently read this off-topic...
This is what I would like to say:

Dear Rex! We don’t know the true reasons for your decision to stop writing scripts... If it’s really some kind of resentment, the offended pride of a talented person or something like that - spit on it all and come back! If anyone cares about my opinion, I think that you are a true talent.
And you have proven this many times, although it is not easy for most of us to even follow your thought expressed in script code...
I also think that all your students on this forum think so, and perhaps not only here... No matter what happens in the world, no matter what happens and in what era, the true value of a master is not even in creating masterpieces, but in creating followers who will follow you... But you can still do a lot for “living” people (while GPT is far from you!) and we all need you and love you with all your advantages and disadvantages (we are all people). And you should not have any regard for the opinion of the forum administration.

Believe me, I am writing this not because I need something from you, but because I respect you and was really happy to have the opportunity to communicate with you not only as a programmer, but also as a very smart person...

I hope that the automatic translator did not distort the meaning of what I wanted to say...

If the reasons for your decision are different, and in any case, we all respect you and will accept your decision, no matter how sad it may be for everyone. But I would really like to hope that someday you will return!
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 680
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: ✂ Rextended Fragments of Snippets

Sun Mar 10, 2024 3:20 pm

@rextended
Will you share your contact info?
 
User avatar
rextended
Forum Guru
Forum Guru
Topic Author
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: ✂ Rextended Fragments of Snippets

Mon Mar 11, 2024 10:43 am

Sorry, not... Ask on forum (on a separate/proper topic).
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 680
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Mar 13, 2024 7:11 pm

sad-cat.jpeg
You do not have the required permissions to view the files attached to this post.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 18961
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: ✂ Rextended Fragments of Snippets

Wed Mar 13, 2024 7:35 pm

Sertik, most of the angst caused is a cumulative thing. When like rextended, one has answered, day in day out, post after post that has zero quality control its very hard to remain patient and one justs gets to the point directly!! ( you have heard of RSI (injury)). Over the years, having been involved in requirements and validation of problems, its clear that a first post process would be an easy and effective solution to help ensure the best experience for a new poster ( who would get answers and support more quickly ) and provide those supporting, day in and day out, useful posts with which to apply limited time and energy.
It is ironic that MT staff simply wish us to have some consideration for first time posters, WHILE I am suggesting
a. provide first time posters a positive experience ( we have the same goals ultimately )
b. show some consideration to those providing support. ( often the same people that are beta testing your products gratis )

Since a, b, would take some effort, its seemingly not on the RADAR........... No progress or forward thinking or effort or seeming lack of common sense, leads some to say what is the point........... When few on the footy team are doing all the running around and the owner of the team says nope we dont need a goalie, just play better defense.......... I'm just saying we need a goalie!

Also ironic, is that you can bet your bottom dollar that MT has processes for all the work they do in-house, for budgeting, product forecasting, analytics, software coding, software testing, HR and hiring and firing etc..................... Its how the world operates.............

Who is online

Users browsing this forum: No registered users and 20 guests