Friday, December 2, 2016

C++ function to convert int to it's binary representation in string

std::string convertInt2Binary(int pi_int)
{
    std::string s;
    int n = std::numeric_limits<int>::digits - 1;

    s.reserve(n + 1);

    do
        s.push_back(((pi_int >> n) & 1) + '0');
    while(--n > -1);

    return s;
}

Tuesday, October 25, 2016

View what grants exist on a table in Oracle

Here's a simple SQL to easily find the grants that are given to a table or view in Oracle with a little extra to grant them again (maybe in other environments or after the need to drop and recreate)

SELECT 'GRANT SELECT ON ' || TABLE_NAME || ' TO ' || GRANTEE || ';', A.*
FROM TABLE_PRIVILEGES A
WHERE TABLE_NAME IN ('PS_PERSONAL_DATA_VW','PS_JOB_VW');

:-)

Thursday, October 20, 2016

Custom resolutions in Remote Desktop

  Today I wanted to get a better use of my remote machine's resolution (I'm actually using a remote machine to connect to my client's server through the Windows remote desktop). Because I didn't want to use it in the standard seamless full screen mode - I always like to have my local taskbar visible so that I can use some of my local apps and local excel while copying and pasting stuff between the local and remote machines.
  If you set remote desktop to a fixed resolution, it only gives you a scrollbar to choose from a set of standard resolutions which may not suit all needs...
  In my case, I could either have a very limited remote desktop experience or I would have to scroll vertically. I wanted to fill all of the space on my screen, except my taskbar, which I have set to the left of the screen on my remote machine (I have it on the left for local machine, right for virtual machines (my remote machine is virtual) and the client's server has it on the standard bottom; and I like to have them all visible at the same time).
  So I had to play around a bit, but the ideal resolution for my remote desktop was: 1280x730; this very custom size is obviously not available in the remote desktop settings... so I searched the web and found this post: (http://www.kudzuworld.com/blogs/Tech/2006_07_10_A.EN.aspx).
  The problem is that it's not all so clear, so I decided to make it slightly clearer here for my own future reference:
1. Log on once in remote desktop
2. Log off! (If you don't log off, your new settings will be overwritten, because remote desktop rewrites this file when you close it...)
3. Open with notepad the file Default.rdp which is in your documents folder (it's a hidden file, so make sure to show those)
4. Set your custom resolution as below:

desktopwidth:i:1280
desktopheight:i:730

  Screenshot of mine:


  As you can see I made some backups before my changes, just in case. Notice two lines below the desktopwidth and desktopheight that my resolution is there again, in the winposstr parameter; you can ignore that, no need to set your resolution on there; when you use remote desktop after your changes, it will set that up automatically.

  There you have it!

Thursday, September 15, 2016

PeopleSoft Application Designer and Data Mover access audit SQL

  Today I created this SQL to get all OPRID's with applications designer access (and access type, write or read-only). I also added some other relevant information (account locked, last sign on, etc...).
  I have made it so it only lists one row per user, so it will show only two permission lists:
  ONE of the permission lists that gives the user this application designer access
  ONE of the permission lists that gives the user this data mover access
  If a user has permission lists that give read only and write access, this SQL will show (one of) the write access permission list (even though I think (haven't tested) that the user will have read only, since PeopleSoft tends to prioritize the display-only flag...)

WITH
APP_DESIGNER_ACCESS AS (
                        SELECT PA.CLASSID AS PERMISSION_LIST
                              ,MAX(PA.AUTHORIZEDACTIONS) MAX_ACCESS
                              ,CASE MAX(PA.AUTHORIZEDACTIONS) WHEN 0 THEN 'NO ACCESS'
                                                              WHEN 1 THEN 'READ'
                                                                     ELSE 'WRITE'
                                                              END APP_DESIGNER_ACCESS
                        FROM PSAUTHITEM PA
                        WHERE PA.MENUNAME = 'APPLICATION_DESIGNER'
                        AND   BARNAME    <> 'CHANGE_CONTROL'
                        GROUP BY CLASSID
                       )
,
DATA_MOVER_ACCESS AS (
                      SELECT PA.CLASSID AS PERMISSION_LIST
                            ,'YES'      AS DATA_MOVER_ACCESS
                      FROM PSAUTHITEM PA
                      WHERE PA.MENUNAME = 'DATA_MOVER'
                      GROUP BY CLASSID
                     )
------------------------------------------------------------------------------------------------------------------------------
SELECT OPC.OPRID
      ,OPD.OPRDEFNDESC
      ,OPD.LASTSIGNONDTTM
      ,NVL(TRUNC(SYSDATE) - TRUNC(OPD.LASTSIGNONDTTM),99999)          AS LAST_SIGNON_DAYS_AGO
      ,CASE OPD.ACCTLOCK WHEN 1 THEN 'LOCKED' ELSE 'OPRID ACTIVE' END AS ACCOUNT_STATUS
      ,NVL(OPC.APP_DESIGNER_ACCESS,'NO ACCESS')                       AS APP_DESIGNER_ACCESS
      ,NVL(OPC.DATA_MOVER_ACCESS,'NO')                                AS DATA_MOVER_ACCESS
      ,OPC.APP_DESIGNER_PERM_LIST                                     AS SAMPLE_APP_DESIGNER_PERM_LIST
      ,OPC.DATA_MOVER_PERM_LIST                                       AS SAMPLE_DATA_MOVER_PERM_LIST
FROM (
------------------------------------------------------------------------------------------------------------------------------
      SELECT OC.OPRID
            ,MAX(APPD.APP_DESIGNER_ACCESS)          as APP_DESIGNER_ACCESS
            ,MAX(DMA.DATA_MOVER_ACCESS)             as DATA_MOVER_ACCESS
            ,NVL(MAX(APPD.PERMISSION_LIST), 'NONE') as APP_DESIGNER_PERM_LIST
            ,NVL(MAX(DMA.PERMISSION_LIST) , 'NONE') as DATA_MOVER_PERM_LIST
      FROM PSOPRCLS  OC
          ,(SELECT OC.OPRID
                  ,MAX(AD.PERMISSION_LIST)     AS PERMISSION_LIST
                  ,MAX(AD.APP_DESIGNER_ACCESS) AS APP_DESIGNER_ACCESS
            FROM APP_DESIGNER_ACCESS AD
                ,PSOPRCLS            OC
            WHERE AD.PERMISSION_LIST = OC.OPRCLASS
            AND   AD.MAX_ACCESS      = (SELECT MAX(SAD.MAX_ACCESS)
                                        FROM APP_DESIGNER_ACCESS SAD
                                        WHERE SAD.PERMISSION_LIST = OC.OPRCLASS
                                       )
            GROUP BY OC.OPRID
           ) APPD
          ,(SELECT OC.OPRID
                  ,MAX(DM.PERMISSION_LIST)   AS PERMISSION_LIST
                  ,MAX(DM.DATA_MOVER_ACCESS) AS DATA_MOVER_ACCESS
            FROM DATA_MOVER_ACCESS DM
                ,PSOPRCLS OC
            WHERE DM.PERMISSION_LIST = OC.OPRCLASS
            GROUP BY OC.OPRID
           ) DMA
      WHERE APPD.OPRID           (+) = OC.OPRID
      AND   APPD.PERMISSION_LIST (+) = OC.OPRCLASS
      AND   DMA.OPRID            (+) = OC.OPRID
      AND   DMA.PERMISSION_LIST  (+) = OC.OPRCLASS
      GROUP BY OC.OPRID
------------------------------------------------------------------------------------------------------------------------------
     ) OPC --select* from dual
     , PSOPRDEFN OPD
WHERE (OPC.APP_DESIGNER_ACCESS || OPC.DATA_MOVER_ACCESS) IS NOT NULL
AND   OPD.OPRID = OPC.OPRID
------------------------------------------------------------------------------------------------------------------------------

;

Hope it helps!

Monday, September 12, 2016

Linux Processes

List all processes running that have PSAESRV and FSDMO but not FSDMO2: (including cpu and memory usage and the command that started the process): 
ps -e -o pid,%cpu,%mem,cmd | grep "PSAESRV.*FSDMO[^2]"



Update:
Use pidstat (or top) to get proper CPU usage and other details:
pidstat -p 12514 -T ALL -u -d -w -t -I

https://linux.die.net/man/1/pidstat
https://linux.die.net/man/1/ps
https://linux.die.net/man/1/top


Processes using specific ports:

You have a couple of options: 
lsof -i tcp:80  
will give you the list of processes using tcp port 80. 
Alternatively, 
sudo netstat -nlp  
will give you all open network connections.