Python – Test for Anagram

email me

def is_anagram(input1, input2):
input1 = input1.lower()
input2 = input2.lower()
return sorted(input1) == sorted(input2)

print("\x1b[2J")

print("iceman cinema")
print(is_anagram("iceman", "cinema"))
print "\n"

print("leaf tree")
print(is_anagram("leaf", "tree"))
print "\n"


Output

Python – Read Lines from Text File

email me

Tested on a Mac, 10.12.6.

import os.path

textFile = "/Users/Shared/TextFile.txt"
doesFileExist=os.path.isfile(textFile)
if doesFileExist == True:
file = open(textFile,"r")
lines=file.read().splitlines()
global line1
global line2
line1 = lines[0]
line2 = lines[1]
file.close()

 

 

Notes

https://docs.python.org/3/

 

Mode Description
‘r’ This is the default mode. It Opens file for reading.
‘w’ This Mode Opens file for writing.
If file does not exist, it creates a new file.
If file exists it truncates the file.
‘x’ Creates a new file. If file already exists, the operation fails.
‘a’ Open file in append mode.
If file does not exist, it creates a new file.
‘t’ This is the default mode. It opens in text mode.
‘b’ This opens in binary mode.
‘+’ This will open a file for reading and writing (updating)

Mac – Create a Daemon to Load App

email me

Step 1 – Create a plist file. Save as something like com.TheAppName.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>app.TheAppName</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/open</string>
<string>/Applications/TheAppName.app</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>LaunchOnlyOnce</key>
<false/>
<key>StartInterval</key>
<integer>3600</integer><!-- seconds -->
</dict>
</plist>

Step 2 – Copy plist to /System/Library/LaunchDaemons/

Step 3 – Load the daemon

sudo launchctl load -w /System/Library/LaunchDaemons/com.TheAppName.plist

Step 4 – Log off & Log on to test

 

Azure – Replace Package Owner with Domain User Owner

email me

* experimental

This is a script I wrote to change from the package owner, which only gives you the ability to manage the device policy in Intune, to an AD/AAD user, which gives you the ability to manage policies for both user and device. So, perform the bulk enrollment, and then run this script with your data.txt file. All devices showing Package as the owner will be updated with the specified user.

Code

Clear-Host

$ErrorActionPreference= 'silentlycontinue'

$item = $null
$line = $null

foreach($line in Get-Content C:\INTUNE\Data.txt) {
foreach ($item in $line)
{
$item = $line -split (",")
$DeviceName = $item[0]
$UserName = $item[1]

$x = Get-AzureADDevice -SearchString $DeviceName | Select Name -ExpandProperty ObjectId
$y = Get-AzureADUser -SearchString $UserName | Select Name -ExpandProperty ObjectId

Write-Host "Username: $UserName ::: $y"
Write-Host "Device: $DeviceName ::: $x"
Add-AzureADDeviceRegisteredOwner -ObjectId $x -RefObjectId $y
Get-AzureADDeviceRegisteredOwner -ObjectId $x
Add-AzureADDeviceRegisteredUser -ObjectId $x -RefObjectId $y
#Remove-AzureADDeviceRegisteredOwner -ObjectId $x -OwnerId $y
Write-Host ""

$x = ""
$y = ""
$DeviceName = ""
$UserName = ""
}
}

$item = $null
$line = $null


Data.txt file

PCName1, JohnDoe
PCName2, JaneDoe

 

Notes

Get-AzureADDevice
Get-AzureADUser
Add-AzureADDeviceRegisteredOwner
Get-AzureADDeviceRegisteredOwner
Add-AzureADDeviceRegisteredUser

 

Reg key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\CloudDomainJoin\JoinInfo
—check out UserEmail reg value
—this value can be changed, which reflects the user on the Access work or school

Pascal – Iteration and Input

email me

Tested in Free Pascal.

Code

PROGRAM LoopAndInput (input, output);

CONST
    LoopLimit = 5;

VAR
    Index, Number, Sum : integer;
    Average : real;

BEGIN
    Sum := 0;
    FOR Index := 1 TO LoopLimit DO
        BEGIN
            writeln (#13#10'Enter number ', Index, ' of ', LoopLimit);
            readln (Number);
            Sum := Sum + Number
        END;
    Average := Sum / LoopLimit;
    writeln;
    writeln ('Average:', Average:5:0);
    writeln;
    readln;
  END.

 

Output

 


Notes

Syntax Highlighter

Online Compiler

Free Pascal compiler

Bash – Hello World

email me

Recommended Reading (click for Amazon link)

 

I used an online interpreter to test the code (as well as OS X). See notes.

Code

#!/bin/bash
echo "Hello, world!"


Output


Notes

Online Interpreter

To run in OS X:

Save as helloworld.sh on the desktop  — the .sh stands for shell, as in a shell script.

— Open a terminal window

— Drag helloworld.sh to terminal window

— Press Return