Thursday, December 9, 2021

bound on a multidimensional array

 Function Bounds(A As Variant) As Collection

    Dim C As New Collection
    Dim v As Variant, i As Long

    On Error GoTo exit_function
    i = 1
    Do While True
        v = Array(LBound(A, i), UBound(A, i))
        C.Add v
        i = i + 1
    Loop
exit_function:
    Set Bounds = C
End Function

Used like this:

Sub test()
    Dim i As Long
    Dim A(1 To 10, 1 To 5, 4 To 10) As Integer
    Dim B(1 To 5) As Variant
    Dim C As Variant
    Dim sizes As Collection

    Set sizes = Bounds(A)
    Debug.Print "A has " & sizes.Count & " dimensions:"
    For i = 1 To sizes.Count
        Debug.Print sizes(i)(0) & " to " & sizes(i)(1)
    Next i

    Set sizes = Bounds(B)
    Debug.Print vbCrLf & "B has " & sizes.Count & " dimensions:"
    For i = 1 To sizes.Count
        Debug.Print sizes(i)(0) & " to " & sizes(i)(1)
    Next i

    Set sizes = Bounds(C)
    Debug.Print vbCrLf & "C has " & sizes.Count & " dimensions:"
    For i = 1 To sizes.Count
        Debug.Print sizes(i)(0) & " to " & sizes(i)(1)
    Next i
End Sub

Output:

A has 3 dimensions:
1 to 10
1 to 5
4 to 10

B has 1 dimensions:
1 to 5

C has 0 dimensions:

CR. https://stackoverflow.com/questions/26644231/vba-using-ubound-on-a-multidimensional-array 
John Coleman

Thursday, October 21, 2021

JAVA security for SQL SERVER 2005

 In my case i had a sql server using the 3DES_EDE_CBC algorithm, this is disabled by default on jdk 1.8 , so checking the

/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre/lib/security/java.security

And eliminating the algorithm from:

jdk.tls.disabledAlgorithms=                                                                                                                                 SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, \ EC keySize < 224, 3DES_EDE_CBC, anon, NULL

Worked for me.



Change to

jdk.tls.disabledAlgorithms=

                   SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, \ EC keySize < 224, anon, NULL


Monday, October 4, 2021

Easy free ftpserver windows for tranfer file between vm to host

#for download software

https://www.sentex.ca/~mwandel/ftpdmin/

#example for run FTP server

ftpdmin.exe c:\me

#command upload

busybox ftpput 192.168.0.86 block.txt

#command download

busybox ftpget 192.168.0.86 block.txt


Friday, September 3, 2021

VBA IsInArray find in array and return last index

 


Function IsInArray(stringToBeFound As String, arr As Variant) As Long

  Dim i As Long

  ' default return value if value not found in array

  IsInArray = -1


  For i = LBound(arr) To UBound(arr)

    If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then

      IsInArray = i

      Exit For

    End If

  Next i

End Function

Python update all component by PIP

1 c:\ pip freeze > requirements.txt

2 edit requirements.txt, and replace all ‘==’ with ‘>>’. Use the ‘Replace All’ command in the editor.

powershell -Command "(gc requirements.txt) -replace '==', '>>' | Out-File requirements.txt"

3 c:\pip install -r requirements.txt --upgrade

Netbean IDE + Glassfish

to start page

remove web.info to provent error java.luaxxxxxx

Thursday, May 6, 2021

Fix Ms outlook can't open link in mail

 Windows Registry Editor Version 5.00


[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\htmlfile\shell\open\command]

@="\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" %1"

"DelegateExecute"="{17FE9752-0B5A-4665-84CD-569794602F5C}"


Saturday, April 3, 2021

script to invert all pdf and result in folder

 @ECHO OFF

SETLOCAL EnableExtensions


SET OUTDIR=InvertedOutputs

SET GS=C:\Ghostscript\bin\gswin64c.exe


REM Make the output directory under the current one, hiding errors (e.g. directory exists)

MKDIR %OUTDIR% 1>nul: 2>>&1


REM Iterate through pdf files in current directory only.

REM Do not recurse child folders, since this would find files in the output directory

FOR %%F IN (*.pdf) DO Call :DoOne "%%F"


GOTO :Done


REM a subroutine eliminates the need for deferred expansion. All expansions are echoed to the console.

REM e.g. Call :DoOne "%%F" - processes one file

:DoOne

REM %~nx1 = the file name + extension of the argument. Since ~ strips quotes, they added back here.

REM including the commands 

REM -f %1 -- quotes are not used here, since %1 had to be quoted at the call site

ECHO ON

"%GS%" -o "%OUTDIR%\%~nx1" -sDEVICE=pdfwrite -c "{1 exch sub}{1 exch sub}{1 exch sub}{1 exch sub} setcolortransfer" -f %1

ECHO OFF

GOTO :EOF


:Done

Pause

Monday, March 8, 2021

Example(3) to user list

 #!/usr/bin/env python


import dbus

import os

from dbus.mainloop.glib import DBusGMainLoop


class CheckedObject:

    def __init__(self, obj):

        self.obj = obj


    def __getattr__(self, attr):

        return CheckedAttribute(self, attr)


class CheckedAttribute:

    def __init__(self, cobj, attr):

        self.cobj = cobj

        self.attr = attr


    def __call__(self, *args):

        result = self.cobj.obj.__getattr__(self.attr)(*args)

        if result == 0:

            raise Exception("Error: %s %s returned %s" %

                            (self.attr, args, result))

        return result


dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()

obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")

purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")

f=open('bblist.txt','w')

for a in purple.PurpleAccountsGetAllActive():

    protocolName = purple.PurpleAccountGetProtocolName(a)

    account = a

    name = purple.PurpleAccountGetUsername(account)

    # cmd="echo 1 '{}|{}' ".format(protocolName.encode('utf-8'),name.encode('utf-8'))

    #os.system(cmd)

    f.write("1 %s|%s \n" % (protocolName.encode('utf-8'),name.encode('utf-8')))

    for online in purple.PurpleFindBuddies( account, '' ):

       name_buddy=purple.PurpleBuddyGetAlias( online ).encode('utf-8')

       buddy=purple.PurpleBuddyGetName( online )

       #cmd="echo 2 '{}|{}' ".format(name_buddy,buddy.encode('utf-8'))

       #os.system(cmd)

       f.write("2 %s|%s \n" % (name_buddy,buddy.encode('utf-8')))

f.close


Friday, March 5, 2021

Example(2) to send status to discord

4 #!/usr/bin/env python




# This is a simple purple notification server.


# It shows notifications when your buddy signs on or you get an IM message.


#


# This script requires Python 2.4 and PyGTK bindings


#


# Note that all function names are resolved dynamically, no


# purple-specific library is needed.




import dbus


import dbus.glib


import dbus.decorators


import gobject


import os




def myaccount():




    for a in purple.PurpleAccountsGetAllActive():


    protocolName = purple.PurpleAccountGetProtocolName(a)


#cmd="echo '{}' ".format(protocolName)


    #os.system(cmd)


    if purple.PurpleAccountGetProtocolName(a) == 'Discord':


        #cmd="echo '{}' ".format(a)


        #os.system(cmd)


break


    return a




def mybuddy(account):

    for online in purple.PurpleFindBuddies( account, '' ):

#cmd="echo '{}' ".format(online)

        #os.system(cmd)

        name_buddy=purple.PurpleBuddyGetAlias( online ).encode('utf-8')

        if name_buddy=='prapop':

            #cmd="echo '{}' ".format(name_buddy)

            #os.system(cmd)

            break

    buddy=purple.PurpleBuddyGetName( online )

    return buddy


def sendmyim(buddy,text):

    if buddy!=0:

buddycheck=purple.PurpleBuddyGetName( buddy )

    else:

        buddycheck="12345674890"

    f = open('block.txt', 'r+')

    block_list = [line for line in f.readlines()]

    f.close()

    res = any(buddycheck.encode('utf-8') in ele for ele in block_list)

    if not res:

        buddyid = purple.PurpleBuddyGetName(buddy)

        name_buddy =purple.PurpleBuddyGetAlias(buddy).encode('utf-8')

        f=open('lastnotice.txt','w')

        f.write('{} {}' .format(name_buddy,buddyid))

        f.close

        account=myaccount()

        buddy=mybuddy(account)

        conv = purple.PurpleConversationNew(1, account,buddy.encode('utf-8'))

        im = purple.PurpleConvIm(conv)

        purple.PurpleConvImSend(im, text.encode('utf-8'))


def ensureimconversation(conversation, account, name):

    if conversation != 0:

        return conversation

    else:

        # 1 = PURPLE_CONV_IM 

        return purple.PurpleConversationNew(1, account, name)


def receivedimmsg(account, name, message, conversation, flags):

    buddy = purple.PurpleFindBuddy(account, name)

    if buddy != 0:

        alias = purple.PurpleBuddyGetAlias(buddy)

    else:

        alias = name

    if "block it" in message:

        f=open('lastnotice.txt','r')

        text=f.read()

        f.close

        w=open('block.txt','a')

        w.write("%s\n" % (text) )

        w.close

        buddy = 0

        text = "block %s" % (text)

    else:

        text = "%s says %s" % (alias, message)

        conversation = ensureimconversation(conversation, account, name)

        purple.PurpleConversationDestroy(conversation)

        #cmd="echo '{}' ".format(text.encode('utf-8'))

        #os.system(cmd)

    sendmyim(buddy,text)


def buddysignedon(buddyid):

    alias = purple.PurpleBuddyGetAlias(buddyid)

    text = "%s is online" % alias

    #cmd="echo '{}' ".format(text.encode('utf-8'))

    #os.system(cmd)

    sendmyim(buddyid,text)


def buddysignedoff(buddyid):

    alias = purple.PurpleBuddyGetAlias(buddyid)

    text = "%s is offline" % alias

    sendmyim(buddyid,text)


def buddychange(buddyid,newstatus,oldstatus):

    alias = purple.PurpleBuddyGetAlias(buddyid)

    new=purple.PurpleStatusGetName(newstatus)

    old=purple.PurpleStatusGetName(oldstatus)

    text = "%s change %s to %s" % (alias,new,old)

    if new==old:

       text="%s return from idle" % (alias)

    sendmyim(buddyid,text)


def buddyidle(buddyid,newstatus,oldstatus):

    alias = purple.PurpleBuddyGetAlias(buddyid)

    text = "%s is idle" % alias

    sendmyim(buddyid,text)


bus = dbus.SessionBus()

obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")

purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")




bus.add_signal_receiver(receivedimmsg,

                        dbus_interface = "im.pidgin.purple.PurpleInterface",

                        signal_name = "ReceivedImMsg")


bus.add_signal_receiver(buddysignedon,

                        dbus_interface = "im.pidgin.purple.PurpleInterface",

                        signal_name = "BuddySignedOn")


bus.add_signal_receiver(buddysignedoff,

                        dbus_interface = "im.pidgin.purple.PurpleInterface",

                        signal_name = "BuddySignedOff")


bus.add_signal_receiver(buddychange,

                        dbus_interface = "im.pidgin.purple.PurpleInterface",

                        signal_name = "BuddyStatusChanged")


bus.add_signal_receiver(buddyidle,

                        dbus_interface = "im.pidgin.purple.PurpleInterface",

                        signal_name = "BuddyIdleChanged")


print "This is a simple purple notification server."

print "It shows notifications when your buddy signs on or you get an IM message."


loop = gobject.MainLoop()

loop.run()


Example(1) to send status to discord

prepare python-dbus, python-gobject 


 #!/usr/bin/env python


import dbus

import os

from dbus.mainloop.glib import DBusGMainLoop


class CheckedObject:

    def __init__(self, obj):

        self.obj = obj


    def __getattr__(self, attr):

        return CheckedAttribute(self, attr)


class CheckedAttribute:

    def __init__(self, cobj, attr):

        self.cobj = cobj

        self.attr = attr


    def __call__(self, *args):

        result = self.cobj.obj.__getattr__(self.attr)(*args)

        if result == 0:

            raise Exception("Error: %s %s returned %s" %

                            (self.attr, args, result))

        return result


dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

bus = dbus.SessionBus()

obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")

purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")


for a in purple.PurpleAccountsGetAllActive():

    protocolName = purple.PurpleAccountGetProtocolName(a)

    cmd="echo '{}' ".format(protocolName)

    os.system(cmd)

    if purple.PurpleAccountGetProtocolName(a) == 'Discord':

        account = a

        cmd="echo '{}' ".format(a)

        os.system(cmd)


# account=396


name = purple.PurpleAccountGetUsername(account)

cmd="echo '{}' ".format(name)

os.system(cmd)


# for online in purple.PurpleFindBuddies( (purple.PurpleAccountsGetAllActive())[0], '' ):


for online in purple.PurpleFindBuddies( account, '' ):

    cmd="echo '{}' ".format(online)

    os.system(cmd)

    name_buddy=purple.PurpleBuddyGetAlias( online ).encode('utf-8')

    if name_buddy=='prapop':

    cmd="echo '{}' ".format(name_buddy)

os.system(cmd)

break


buddy=purple.PurpleBuddyGetName( online )

cmd="echo '{}' ".format(buddy)

os.system(cmd)

conv = purple.PurpleConversationNew(1, account,buddy)

im = purple.PurpleConvIm(conv)

msg='test'

# purple.PurpleConvImSend(im, msg)


cpurple=CheckedObject(purple)

xx=cpurple.PurpleAccountGetConnection(account)

# msginfo=purple.ServGetInfo(33043,buddy)

cmd="echo '{}' ".format(xx)

os.system(cmd)


Thursday, March 4, 2021

pidgin complie and plugin discord & skype (For wsl ubuntu)

rm -r mydir     #remove all 
 
sudo apt-get install -y make libpurple-dev libjson-glib-dev gcc

 

Plugin  DISCORD

sudo apt-get install -y imagemagick gettext
git clone git://github.com/EionRobb/purple-discord.git
cd
purple-discord make sudo make install
//////////////////////////////////////////////// 
Plugin  Skype 
sudo apt-get install libpurple-dev libjson-glib-dev cmake gcc
git clone git://github.com/EionRobb/skype4pidgin.git
cd skype4pidgin/skypeweb
mkdir build
cd build
cmake ..
cpack

To install do:

sudo dpkg -i skypeweb-1.x.x-Linux.deb
 
///////////////////////////////////////// 
Prepare for build pidgin
sudo apt-get build-dep pidgin 

E: You must put some 'deb-src' URIs in your sources.list
sudo nano /etc/apt/source.list
remove # on deb-scr

sudo apt-get update
 
//////////////////////////////////////// 
Prepare source pidgin for Mercurial
sudo apt install -y mercurial
sudo nano ~/.hgrc
[ui]
username = Prapop Puapermpoonsiri <prapopp@hotmail.com> verbose = True
merge = meld [diff] git = True

[defaults]
log = -v


hg clone https://keep.imfreedom.org/pidgin/pidgin/ pidgin
cd pidgin
hg up release-2.x.y
./autogen.sh && make && sudo make install
 

WSL for window10 and remote desktop

WSL commands: 
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
wsl --set-default-version 2

Download ubuntu wsl from microsoft store


Ubuntu commands:

sudo apt update && sudo apt -y upgrade

sudo apt-get install -y xrdp xfce4 xfce4-goodies

configure :
sudo cp /etc/xrdp/xrdp.ini /etc/xrdp/xrdp.ini.bak
sudo sed -i 's/3389/3390/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/max_bpp=32/#max_bpp=32\nmax_bpp=128/g' /etc/xrdp/xrdp.ini
sudo sed -i 's/xserverbpp=24/#xserverbpp=24\nxserverbpp=128/g' /etc/xrdp/xrdp.ini
echo xfce4-session > ~/.xsession

sudo nano /etc/xrdp/startwm.sh
comment these lines to:
#test -x /etc/X11/Xsession && exec /etc/X11/Xsession
#exec /bin/sh /etc/X11/Xsession

add these lines:
# xfce
startxfce4

sudo /etc/init.d/xrdp start

Now in Windows, use Remote Desktop Connection
localhost:3390
then login with Xorg, fill in your username and password.

Youtube easy

 ssyoutube.com --> MP4

youtubex2.com --->MP3

Saturday, February 6, 2021

zeroshell OS

 set ip to connect lan1 (192.168.137.2)  default 192.168.0.75

lan2 dhcp client (10.0.2.15)

gateway (10.0.2.2)


go to web interface

set nat lan2