Posts

Powershell

  Powershell and Task Scheduler Reference:  link $Trigger = New-ScheduledTaskTrigger -At 10 : 00 am –Daily # Specify the trigger settings $User = "NT AUTHORITY\SYSTEM" # Specify the account to run the script $Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "C:\PS\StartupScript.ps1" # Specify what program to run and with its parameters Register-ScheduledTask -TaskName "MonitorGroupMembership" -Trigger $Trigger -User $User -Action $Action -RunLevel Highest –Force # Specify the name of the task

mprof Python

  To check memory usage of a Python script, can install the   memory_profiler   library through pip  Usage: mprof run --include-children <executable> mprof plot To check performance of specific function, decorate that function with  @profile  and run the above  mprof  commands

Lexicographic comparisons in C++

Lexicographic comparisons in C++: Link to Pluralsight article

C++ move semantics

  Move Semantics The following simple class will be used to illustrate move semantics and object lifecycle.  std::move  creates rvalue reference Float.h # pragma once class Float { public : Float ( float f ) ; //constructor Float ( const Float & f ) ; //copy constructor Float ( Float && f ) noexcept ; //move constructor Float & operator = ( const Float & rhs ) ; //copy assignment operator Float & operator = ( Float && rhs ) noexcept ; //move assignment operator ~ Float ( ) ; //destructor float getValue ( ) const ; //getter void setValue ( float f ) ; //setter friend void swap ( Float & first , Float & second ) noexcept ; //copy helper function void moveFrom ( Float & src ) noexcept ; //move helper function. Note param is lvalue reference float * m_flt ; //pointer to heap based float } ; Float.cpp # include <iostream> # include <utility> # ...

C++ Uniform Initialization

  Uniform initialization These are the various types of initialization: Value initialization where object is set to default value ->  T obj{} Direct initialization ->  T obj{v} Copy initialization ->  T obj = v Copy initialization should be avoided for user defined types to prevent potentially unnecessary copies Advantages of uniform initialization Forces initialization Uniform syntax; direct initialization for array types Prevents narrowing conversions: float f { 2.0 } ; int k { f } ; //throws narrowing warning or error

Hangman Game in Go

  Hangman Game Example in Go Here is the code for a hangman game in Go: package main import ( "bufio" "fmt" "log" "math/rand" "os" "strings" "time" ) var inputReader * bufio . Reader var randSource rand . Source var randomGen * rand . Rand var hangmanPics [ 7 ] string func initPics ( ) { hangmanPics = [ 7 ] string { ` +---+ | | | ===` , ` +---+ O | | | ===` , ` +---+ O | | | | ===` , ` +---+ O | /| | | ===` , `+---+ O | /|\ | | ===` , `+---+ O | /|\ | / | ===` , `+---+ O | /|\ | / \ | ===` } } func initRandomGen ( ) { randSource = rand . NewSource ( time . Now ( ) . UnixNano ( ) ) randomGen = rand . New ( randSource ) } func readWordsFromFile ( f...

QFutureWatcher

  QFutureWatcher QFutureWatcher  is useful in keeping track of when an asynchronous task complete. Consider a scenario where a dialog pops up while some operation runs in the background. The first step is to show the dialog: msgDialog = new MessageDialog ( ) ; msgDialog -> show ( ) ; QApplication :: processEvents ( ) ; //needed to properly show the dialog Having a  QFuture m_OperationFuture  as a field, a naive approach to keeping the GUI responsive while the background operation takes place is to keep calling  QApplication::processEvents()  while the operation is still executing: m_OperationFuture = QtConcurrent :: run ( runBackgroundOperation ) ; while ( m_OperationFuture . isRunning ( ) ) { QApplication :: processEvents ( ) ; } performNextOperation ( ) ; However,  QFutureWatcher  provides a better alternative: QFutureWatcher < QString > * watcher = new QFutureWatcher < QString > ( this ) ; QObject ::...