Skip to content

Instantly share code, notes, and snippets.

@greenido
Last active November 18, 2024 18:27
Show Gist options
  • Save greenido/c725d654b2d4acbf90c46c1bda96a950 to your computer and use it in GitHub Desktop.
Save greenido/c725d654b2d4acbf90c46c1bda96a950 to your computer and use it in GitHub Desktop.
Cross-Platform Installation Application Assignment (Max 2 hours)

Objective

Create a basic cross-platform command execution application that can be installed on Windows and macOS, capable of executing simple system commands and returning their results.

Core Requirements (2 hours)

1. Installation Package (~30 minutes)

  • Create a simple installer for either Windows (.exe) or macOS (.pkg) [choose one]
  • Implement basic start-on-boot functionality

2. Command Execution (~45 minutes)

Implement support for two command types:

  • Network ping
  • Get system info (hostname, IP address)
type Commander interface {
    Ping(host string) (PingResult, error)
    GetSystemInfo() (SystemInfo, error)
}

type PingResult struct {
    Successful bool
    Time       time.Duration
}

type SystemInfo struct {
    Hostname  string
    IPAddress string
}

3. Communication (~45 minutes)

  • Implement a basic HTTP server to receive commands
  • Return results as JSON

Example endpoint structure:

// POST /execute
type CommandRequest struct {
    Type    string `json:"type"`    // "ping" or "sysinfo"
    Payload string `json:"payload"` // For ping, this is the host
}

type CommandResponse struct {
    Success bool        `json:"success"`
    Data    interface{} `json:"data"`
    Error   string      `json:"error,omitempty"`
}

Implementation Requirements

  1. Main Application Structure
func main() {
    commander := NewCommander()
    server := &http.Server{
        Addr:    ":8080",
        Handler: handleRequests(commander),
    }
    log.Fatal(server.ListenAndServe())
}

func handleRequests(cmdr Commander) http.Handler {
    mux := http.NewServeMux()
    mux.HandleFunc("/execute", handleCommand(cmdr))
    return mux
}

func handleCommand(cmdr Commander) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        // Parse request and execute command
    }
}
  1. Platform-Specific Implementation
type commander struct{}

func NewCommander() Commander {
    return &commander{}
}

func (c *commander) GetSystemInfo() (SystemInfo, error) {
    hostname, err := os.Hostname()
    if err != nil {
        return SystemInfo{}, err
    }
    
    // Get IP address (implement this)
    
    return SystemInfo{
        Hostname:  hostname,
        IPAddress: "implement me",
    }, nil
}

Deliverables

  1. Create a GitHub repository with your solution.

  2. Source code with:

    • Command execution implementation
    • HTTP server implementation
    • Basic installer script
  3. README.md with:

    • Build instructions
    • API documentation
    • Installation guide
    • Testing
    • A short clip that shows the "app in action"

Example Test Case

func TestGetSystemInfo(t *testing.T) {
    cmdr := NewCommander()
    info, err := cmdr.GetSystemInfo()
    
    if err != nil {
        t.Fatalf("Expected no error, got %v", err)
    }
    
    if info.Hostname == "" {
        t.Error("Expected hostname to be non-empty")
    }
    
    if info.IPAddress == "" {
        t.Error("Expected IP address to be non-empty")
    }
}

Time Breakdown

  • Setup project and installer script: 30 minutes max
  • Implement command execution: 45 minutes max
  • Create HTTP server and endpoints: 45 minutes max

Evaluation Criteria

  1. Code Quality
    • Clean, idiomatic Go code
    • Basic error handling
  2. Functionality
    • Successfully executes required commands
    • Correctly returns results via HTTP
  3. Completeness
    • All core requirements implemented
    • Basic documentation provided

Notes for Candidates

  • Focus on core functionality first
  • Clean code is important, but perfect is the enemy of done
  • Document any assumptions or limitations

Interview Follow-up

Be prepared to discuss:

  • Your architectural decisions
  • How you would scale this for a large organization
  • Security considerations
  • Performance optimizations
  • How you'd handle offline functionality

Good luck - We're excited to see your solution!

@ryanfaerman
Copy link

I've completed this and my code is available here: https://github.com/ryanfaerman/agent-smith

@ORESoftware
Copy link

will complete this soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment