Recording code

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #5465

    by lasty12 at 2013-01-23 11:28:09

    Hi All,

    Just wondered what "best practice" each of you follow for annotating and storing scripts.
    At the moment I am using Onenote to detail new code that I am learning for reference but wondered if anyone has a more "script" orientated method – e.g. one that is more syntax friendly rather than needing screen snips or plain text?

    Cheers

    by sunnyc7 at 2013-01-23 12:27:48

    Hi.

    I follow these methods.
    a) I try to write in-line comments for Cmdlets, .Net Functions I am not familiar with.
    I would also include MSDN links, or my search results for a similar or a different treatment.
    I google like this:
    [System.Net.Dns]:: filetype:ps1

    b) I also investigate alternate logic steps, try changing parameters etc.
    c) I also investigate if i can extend the script.

    I summarize my notes at the end of the script in a comment block, like this.
    # This is my annotation for an excellent port-scanner script written by Boe Prox.
    Original script by Boe here:
    http://gallery.technet.microsoft.com/sc ... d823867131

    <
    #Sunny
    #Date: 12/28/2012
    ANALYSIS:
    a) Simple Port Scanner. Picks an IP Connects. Doesnt do anything else.
    The core logic of assigning IP's to the script (Subnet, Single-IP,Multiple-IP) has to sit outside the Test-Port.
    b) Error checking can be improved.
    c) Code is primarily a wrapper around .net Class
    d) There is a Test-Connection code in UDP, but none for TCP ?

    IMPROVEMENT:
    a) Test if you can ping the box, before you connect.
    b) Put Ping in a try/catch block.
    c) How about autodiscover options, where you can ping the subnet 192.168.1.x – 255
    d) To Extend it to ping to a 10.10.X.Y – you need to build an array of IP's from 10.10.0.0 – 10.10.0.255
    Using .Net System.Net classes to ping each individually, might make the code slow.
    e) One alternative is to use Multi-Threaded port scanner, pretty standard in all port scanners.
    Something like this:
    http://www.orcsweb.com/blog/jeff/multit ... t-scanner/

    f) Output can be piped to OGV Test-port -From 192.168.1.1 -To 192.168.1.255 | ogv
    g) Mechanism should be provided for commonly used ports in a LAN 25,80,443,139,6001-6004
    h) IPV6 options ?
    #>

    d) End of the day, I save my annotations for myself. It will be nice to have scripts repo, in a wiki format so that others can use / extend the annotations.
    e) I usually do not act on my annotations right away (time/job/other factors).
    But, if I have to work on the script, I look at my annotations and try to write the script that I want. The analysis part is already done, with links and comments. It boils down to just coding it.

    I started on the Powershell script annotations path, after looking at Chess annotations.
    Example here:
    http://gameknot.com/annotation.pl/tourn ... rov?gm=216

    Hope this helps.
    Thanks
    Sunny

    by nohandle at 2013-01-23 12:32:11

    I use just bunch of folders to store things I am working on or exploring. But I think about moving to some source control because of the easier sharing among computers. Other great way of not losing anything is posting on forums, blog etc. with explanations.

    Generally I use multiline < # comments #> and auto help comments to put notes and explanations to code. It can be placed exactly where you need it and you don't have to switch between two documents.

    by lasty12 at 2013-01-23 12:46:56

    @nohandle – Agree regarding posting to forums, however a large proportion of the syntax is confidential so I would need to make changes before posting, which would take too long.

    Just wondered if there is a magical way of storing and annotating code within a program designed specifically for!

    by sunnyc7 at 2013-01-23 12:51:58

    Hi.

    I follow these methods.
    a) I try to write in-line comments for Cmdlets, .Net Functions I am not familiar with.
    I would also include MSDN links, or my search results for a similar or a different treatment.
    I google like this:
    [System.Net.Dns]:: filetype:ps1

    b) I also investigate alternate logic steps, try changing parameters etc.
    c) I also investigate if i can extend the script.

    I summarize my notes at the end of the script in a comment block, like this.
    # This is my annotation for an excellent port-scanner script written by Boe Prox.
    Original script by Boe here:
    http://gallery.technet.microsoft.com/sc ... d823867131

    <
    #Sunny
    #Date: 12/28/2012
    ANALYSIS:
    a) Simple Port Scanner. Picks an IP Connects. Doesnt do anything else.
    The core logic of assigning IP's to the script (Subnet, Single-IP,Multiple-IP) has to sit outside the Test-Port.
    b) Error checking can be improved.
    c) Code is primarily a wrapper around .net Class
    d) There is a Test-Connection code in UDP, but none for TCP ?

    IMPROVEMENT:
    a) Test if you can ping the box, before you connect.
    b) Put Ping in a try/catch block.
    c) How about autodiscover options, where you can ping the subnet 192.168.1.x – 255
    d) To Extend it to ping to a 10.10.X.Y – you need to build an array of IP's from 10.10.0.0 – 10.10.0.255
    Using .Net System.Net classes to ping each individually, might make the code slow.
    e) One alternative is to use Multi-Threaded port scanner, pretty standard in all port scanners.
    Something like this:
    http://www.orcsweb.com/blog/jeff/multit ... t-scanner/

    f) Output can be piped to OGV Test-port -From 192.168.1.1 -To 192.168.1.255 | ogv
    g) Mechanism should be provided for commonly used ports in a LAN 25,80,443,139,6001-6004
    h) IPV6 options ?
    #>

    d) End of the day, I save my annotations for myself. It will be nice to have scripts repo, in a wiki format so that others can use / extend the annotations.

    I started on the Powershell script annotations path, after looking at Chess annotations.
    Example here:
    http://gameknot.com/annotation.pl/tourn ... rov?gm=216

    Hope this helps.
    Thanks
    Sunny

You must be logged in to reply to this topic.