Installing And Using Samba Shares On Linux

To install samba capabilities on your Linx box, run the following commands:

sudo apt-get install samba samba-common-bin

This will run off an install process, note that it may ask you if you’re sure about installing this, press y to accept and continue.

Now edit the samba configuration file using:

sudo nano /etc/samba/smb.conf

Go all the way to the end of the file and add the following lines…

  • [share]
  • comment=Pi Share
  • path= DIRECTORY LOCATION e.g. /mnt/library
  • browseable = yes
  • writeable = yes
  • only guest = no
  • create mask = 0777
  • public = no
  • guest ok = no

 

At this point your may need to restart the smb service using the following command:

sudo service smbd restart

You may need to know the IP address of the Linux share in order to access it, you can do this by using “ifconfig” and looking for something along the lines of “192.168…” on the eth0 interface”

To access the share using the Windows and R key to bring up the run dialog box and type in the IP address of the Linux box or its hostname. It would now ask you for credentials, here you should use your regular Linux credentials.

You can see this below:

Credentials Prompt

Once it has accepted my credentials I get the following:

Samba Share

Hopefully, you get the same as I did, if not then leave a comment. Enjoy!

 

Rock, Paper, Scissors In PowerShell

Another game today, I’ll be adding this to my big Games Project soon. Just need to implement it into the script.

First I started off by making the PowerShell window the correct size. I did this by adding:

$pshost = get-host
$pswindow = $pshost.ui.rawui
$newsize = $pswindow.buffersize
$newsize.height = 500
$newsize.width = 500
$pswindow.buffersize = $newsize
$newsize = $pswindow.windowsize
$newsize.height = 22
$newsize.width = 85
$pswindow.windowsize = $newsize
$pswindow.WindowTitle = "Rock, Paper, Scissors"

to the start of the function.

Next I created the meat of the game, here its just a simple do statement until either the score of the user or the score of the computer has reached or exceeded 3. Best of three sort of thing. Heres that part:

do {
 $options = @("Rock","Paper","Scissors")
 $option = $options | Get-Random -Count 1
 Clear-Host
 Write-Host "Your Score - $score" -ForegroundColor Green
 Write-Host "Computer's Score - $computerscore" -ForegroundColor Red
 do {$selection = Read-Host "Selection"}while (("Rock","Paper","Scissors") -notcontains $selection)
  if ($selection -eq "rock" -and $option -eq "paper"){
   Write-Host "You lose, the computer chose $option";
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif($selection -eq "paper" -and $option -eq "scissors"){
   Write-Host "You lose, the computer chose $option"
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif($selection -eq "scissors" -and $option -eq "rock"){
   write-host "You lose, the computer chose $option"
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif ($selection -eq $option){
   Write-Host "Its a draw"
   Start-Sleep -Seconds 1
  }else{
   Write-Host "You won, the computer chose $option"
   Start-Sleep -Seconds 1
   $score = $score + 1
  }
 }until (($score -eq 3) -or ($computerscore -eq 3))
 if ($computerscore -gt $score){
  Clear-Host
  Write-Host "You lost, the computer scored $computerscore points whilst you only scored $score points" -ForegroundColor Red
 }else{
  Clear-Host
  Write-Host "You won, you got $score points. More than the computer's $computerscore" -ForegroundColor Green
 }
}

Finally, I ended the code of by showing the user who won and giving then the option to exit the game or play again. Here is the code for that:

do {$playagain = Read-Host "Do you want to play again? Y or N"} while (("Y","N") -notcontains $playagain)
if ($playagain -eq "y"){
 RPS
}elseif ($playagain -eq "n"){
 exit
}

===================================================================================================

Hopefully you can see how this all comes together. Here is the entire script for the game:

function RPS{
 $pshost = get-host
 $pswindow = $pshost.ui.rawui
 $newsize = $pswindow.buffersize
 $newsize.height = 500
 $newsize.width = 500
 $pswindow.buffersize = $newsize
 $newsize = $pswindow.windowsize
 $newsize.height = 22
 $newsize.width = 85
 $pswindow.windowsize = $newsize
 $pswindow.WindowTitle = "Rock, Paper, Scissors"

 [int]$score = 0
 [int]$computerscore = 0

 do {
  $options = @("Rock","Paper","Scissors")
  $option = $options | Get-Random -Count 1
  Clear-Host
  Write-Host "Your Score - $score" -ForegroundColor Green
  Write-Host "Computer's Score - $computerscore" -ForegroundColor Red
  do {$selection = Read-Host "Selection"}while (("Rock","Paper","Scissors") -notcontains $selection)
  if ($selection -eq "rock" -and $option -eq "paper"){
   Write-Host "You lose, the computer chose $option";
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif($selection -eq "paper" -and $option -eq "scissors"){
   Write-Host "You lose, the computer chose $option"
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif($selection -eq "scissors" -and $option -eq "rock"){
   write-host "You lose, the computer chose $option"
   Start-Sleep -Seconds 1
   $computerscore = $computerscore + 1
  }elseif ($selection -eq $option){
   Write-Host "Its a draw"
   Start-Sleep -Seconds 1
  }else{
   Write-Host "You won, the computer chose $option"
   Start-Sleep -Seconds 1
   $score = $score + 1
  }
 }until (($score -eq 3) -or ($computerscore -eq 3)) 
 if ($computerscore -gt $score){
  Clear-Host
  Write-Host "You lost, the computer scored $computerscore points whilst you only scored $score points" -ForegroundColor Red
 }else{
  Clear-Host
  Write-Host "You won, you got $score points. More than the computer's $computerscore" -ForegroundColor Green
 }

 do {$playagain = Read-Host "Do you want to play again? Y or N"} while (("Y","N") -notcontains $playagain)
 if ($playagain -eq "y"){
  RPS
 }elseif ($playagain -eq "n"){
  exit
 }
}

I was quite surprised at how short I got the script to be, I think I may try to make the Blackjake game shorter as, lets me honest. Its barbaric in its construction.