Tuesday, October 14, 2008

Remove Pesky Dos / Soft Line breaks in VI (VIM)

I hate it when you are trying to import a text file and the importer doesn’t like it cause there are ^M + \n line breaks in the middle of fields….

 

In vi, use:

 

 :%s/\r\n/ /g

 

To turn them into spaces..

Saturday, October 4, 2008

Open a directory of text files and display them in a text box

It is always handy to be able to view a bunch of output files one after
another without having to open them all in a tabbed editor or open a
bunch of notepads. On a form named MainForm, add buttons Named:
LoadOutputFiles, NextFile and PreviousFile; add a label named
OutputPosition; Copy and paste the code below...

Dim OutputFiles as String()
Dim LoadedID as Integer
Dim TotalNumberOfFilesLoaded as Integer

Public Class MainForm

Private Sub LoadOutputFiles_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles LoadOutputFiles.Click
If Not FolderBrowserDialog.SelectedPath.Length > 1 Then
If Not FolderBrowserDialog.ShowDialog =
Windows.Forms.DialogResult.OK Then
Exit Sub
End If
End If
OutputFiles =
System.IO.Directory.GetFiles(FolderBrowserDialog.SelectedPath) 'Add a
filter to the 'GetFiles' function for *.txt etc...
TotalNumberOfFilesLoaded = OutputFiles.Length
Array.Sort(OutputFiles) 'Sort the Files
LoadedID = 0
ReadNextFile(LoadedID)
End Sub

Sub ReadNextFile(ByVal ID As Integer)
If OutputFiles Is Nothing Then
Exit Sub
End If
If ID = TotalNumberOfFilesLoaded Or ID >
TotalNumberOfFilesLoaded Then
ID = 0
LoadedID = 0
End If
If ID = -1 Then
ID = TotalNumberOfFilesLoaded - 1
LoadedID = TotalNumberOfFilesLoaded - 1
End If
Dim fs As IO.StreamReader = Nothing
Try
fs = New System.IO.StreamReader(OutputFiles(ID))
OutputText.Text = fs.ReadToEnd
fs.Close()
Catch ex As Exception
If Not fs Is Nothing Then
fs.Close()
End If
End Try
OutputPosition.Text = String.Format("{0} of {1}", LoadedID + 1,
TotalNumberOfFilesLoaded)
End Sub


Private Sub NextFile_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles NextFile.Click
LoadedID -= 1
ReadNextFile(LoadedID)
End Sub

Private Sub PreviousFile_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles PreviousFile.Click
LoadedID += 1
ReadNextFile(LoadedID)
End Sub

End Class

Active Directory Data / Time Converter; pwdLastSet, accountExpires, lastLogonTimestamp, lastLogon, badPasswordTime

Found a cool tool to convert AD’s really strange date/time format to real readable format. Very useful if you don’t have time to write your own and look at the ldap side of AD a lot…

 

http://www.chrisnowell.com/information_security_tools/date_converter/Windows_active_directory_date_converter.asp

 

Wednesday, October 1, 2008

Insert Key on a iMAC running Parallels

To toggle the insert key…  (cause when it is on and you hot space it overwrites your text)

Hold ‘FN’ and hit the Zero key on your keypad (the set of numbers under your right hand)

Table Counts on a field accross the entire Database

Ever need to look for a value in a field across the entire DB? Have 10k+ Table that have your particular field? Here is a plsql package that I create to help in tracking where a person’s ID (emplid) shows up in the DB. Takes about 3 minutes to process 1 emplid.

 

Usage: select * from table(tablecounts_pkg.mbi_tablecounts('<<EMPLID>>') ) ;

 

 

CREATE OR REPLACE PACKAGE SYSADM.tablecounts_pkg

IS

     -- Looks for all PS tables (Joins on User_tables to make sure it is a table) and does a count on that table based on EMPLID.

   TYPE outrec_typ IS RECORD (

      var_table      VARCHAR2 (30),

      var_rowcount   NUMBER

   );

 

   TYPE outrecset IS TABLE OF outrec_typ;

 --Usage select * from table(tablecounts_pkg.tablecounts('1978614') ) ;

   FUNCTION tablecounts (emplid VARCHAR)

      RETURN outrecset PIPELINED;

    

END tablecounts_pkg;

/

 

CREATE OR REPLACE PACKAGE BODY SYSADM.tablecounts_pkg

IS

   FUNCTION tablecounts (emplid VARCHAR)

      RETURN outrecset PIPELINED

   IS

      out_rec           outrec_typ;

 

      CURSOR tablenames

      IS

         SELECT a.table_name

           FROM SYS.user_tab_cols a, user_tables b

          WHERE column_name = 'EMPLID' AND a.table_name LIKE 'PS%' AND a.table_name = b.table_name;

 

      table_row_count   NUMBER;

      stmt              VARCHAR (200);

   BEGIN

      FOR x IN tablenames

      LOOP

         stmt := 'select count(*) from ' || x.table_name || ' where emplid = ''' || emplid || '''';

 

         --DBMS_OUTPUT.put_line (stmt);

         EXECUTE IMMEDIATE stmt

                      INTO table_row_count;

 

         IF table_row_count > 0

         THEN

            out_rec.var_table := x.table_name;

            out_rec.var_rowcount := table_row_count;

            PIPE ROW (out_rec);

         END IF;

      END LOOP;

 

      RETURN;

   END;

END tablecounts_pkg;

/

Add to Google