Use Koans to learn a new programming language

A Koan is a Buddhist idea. A Koan presents a situation, dialog, statement, story or question that must be thought about. Many of these questions cannot be answered outright, having multiple interpretations.
The goal of a Koan is not the answer, but thinking about the question.
Now, regarding to learning a new programming language.
Koans premise is that there are set of broken tests and it is your mission to repair them. Along the way, the tests are fixed by utilizing the language, syntax and culture of Test Driven Development (TDD). Learning the culture is one of the coolest parts of the Koans.
The goal is to learn the language, syntax, structure, and some common functions and libraries. The goal is not to speed through or skip around, but take your time and add more tests, break and fix again. You have to fill in that missing piece in order to move on to the next Koan. These Koans are thinking exercises, you have to understand how the language feature works before you can move on.
I like a lot the idea around Koans, because i think the real learn happens by DOING and no other way.
I think Koans are a great way to learn a new language, they won’t teach you the intricate in’s and out of the language, neither will they teach you the pro’s and con’ nor the real life use of the language, but, i think is a good way to get you confident up and running, your knowledge of the syntax differences and the general feel of a language.
With That said, I can only add a list of available Koans repositories for different languages.

The original

See also

Front-end languages




Other technical tools

If you need more, search the word “Koan” in https://github.com/ orhttps://bitbucket.org/


Killing Windows process with VBScript and WMI

For some info about VBScript and WMI chek the previous post.
So lets kill some specific windows process filtering their params.
In this case i want to kill the Domain2 thats running on Glassfish.

So i will run it like this:

KillProcess "java.exe", "domain2"
Why i want to do this? Well there is a time when i really want to stop glassfish services but they ignore me xD and raise some timeout :(

Here is the KillProcess snippet:

Sub KillProcess(Process,CommandLine)
    strComputer = "."
    Set objWMIService = GetObject("winmgmts://./root/cimv2")

    Set colProcessbyName = objWMIService.ExecQuery("Select * from Win32_Process Where Name like '%" & Process & "%' and CommandLine LIKE '%"& CommandLine &"%'")

    If (NOT IsNull(colProcessbyName)) AND ( getCount(colProcessbyName) > 0) Then
      For Each objProcess in colProcessbyName
          strProcessID = objProcess.ProcessId
          Wscript.Echo "Process ID: " & strProcessID
    End If

    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process where ProcessId =" & strProcessID)
    If (NOT IsNull(colProcessList)) AND (getCount(colProcessList) > 0) Then
      For Each objProcess in colProcessList
    End If

End Sub
That's all folks

Restarting Windows services with VBScript and WMI

For those who don't know, VBScript (Visual Basic Scripting Edition) is an Active Scripting language developed by Microsoft that is modeled on Visual Basic.

It is designed as a "lightweight" language with a fast interpreter for use in a wide variety of Microsoft environments. VBScript uses the Component Object Model to access elements of the environment within which it is running.

Also i will be using WMI (Windows Management Instrumentation). WMI is the infrastructure for management data and operations on Windows-based operating systems. You can write WMI scripts or applications to automate administrative tasks on remote computers but WMI also supplies management data to other parts of the operating system and products, for example System Center Operations Manager, formerly Microsoft Operations Manager (MOM), or Windows Remote Management (WinRM).

Situation: I need to stop services and start it again when the process finished.
Problem: Services starts/stops in and asyncronous way and i dont want to use sc or net stop/start because i need to check the current status of the service in a programatically way.

Here is my snippet:

Sub WaitUntil(Query)
   Set wmi = GetObject("winmgmts://./root/cimv2")
   Do Until wmi.ExecQuery(Query).Count > 0
      WScript.Sleep 100
End Sub

Sub StartOrStopService(Action, ServiceName)
  Set wmi = GetObject("winmgmts://./root/cimv2")

  Wscript.Echo "Trying to "+ Action +" service: " & ServiceName

  qry = "SELECT * FROM Win32_Service WHERE Name='" & ServiceName & "'"
  For Each s In wmi.ExecQuery(qry)
    Select Case Action
      Case "start": If s.State = "Stopped" Then 
                                Wscript.Echo "Wating for service to "& Action &": " & ServiceName
                                WaitUntil qry & " AND State='Running'"
                    End If

      Case "stop" : If s.State = "Running" Then 
                                Wscript.Echo "Wating for service to "& Action &": " & ServiceName
                                WaitUntil qry & " AND State='Stopped'"
                    End If

      Case "restart" : 
            StartOrStopService "stop", ServiceName
            StartOrStopService "start", ServiceName
      Case Else   : WScript.Echo "Invalid action: " & action
    End Select
End Sub
And i use it in this way:

    StartOrStopService "restart", "AppServer9PE-2"
Of course StartOrStopService is the main function, but there is a trick.
The WaitUntil is just a delay to avoid problemas when starting or stoping, becasue they run asyncronouslly.
yes i'm playing with a glassfish service
For more info about VBScript go to: http://msdn.microsoft.com/en-us/library/t0aew7h6(v=vs.84).aspx
and for WMI go to: http://msdn.microsoft.com/en-us/library/aa394582(v=vs.85).aspx
And that's all folks

Creative Commons License This page is powered by Blogger. Isn't yours?