Skip to content

Instantly share code, notes, and snippets.

View mnadjit's full-sized avatar

Mehdi Tehrani mnadjit

  • Melbourne Australia
View GitHub Profile
@mnadjit
mnadjit / install_docker.sh
Last active April 10, 2018 14:45
Debian Raspberry Pi (Raspbian) Scripts
#!/bin/bash
sudo apt-get remove docker docker-engine docker.io
curl -fsSL get.docker.com -o get-docker.sh
sudo sh get-docker.sh
echo "Please enter username to add to Docker group to run Docker as non-root user:"
read username
@mnadjit
mnadjit / python_install.sh
Last active March 5, 2018 11:49
Python - uninstall old version and install latest version
!#/bin/bash
package_name=python3.5
# Get list of all installed apps
apt list --installed | grep $package_name
# Uninstall old version of Python
apt-get remove $old_package_name
@mnadjit
mnadjit / FSL_instructions.txt
Last active April 12, 2018 02:01
Install FSL, R and R-Studio [ubuntu 16.04 LTS]
# Install Ubuntu on VM - shared folder enabled
# Install Guest Addition Disk
/media/username/VBox_GAs_5.2.6\VBoxLinuxAdditions.run
# Update packages
apt-get update
# Grant access to user to access shared folder
adduser $username vboxsf # needs reboot
@mnadjit
mnadjit / install_docker.sh
Last active July 8, 2019 03:05
Ubuntu Scripts
#!/bin/bash
sudo apt-get -y update
# Install required libraries
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
# Add Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@mnadjit
mnadjit / raspi-install.sh
Last active May 25, 2021 14:30
Install required packages and applications for Raspberry Pi dev & prod environment
#!/bin/bash
# Set personal variables
echo "Git Username: "
read GIT_USER
echo "Git email: "
read GIT_EMAIL
# Set environment as development or production
echo "Environment: [prd/dev]? "
@mnadjit
mnadjit / Unzip-Combine-HL7.bat
Last active June 28, 2021 04:52
This script combines hl7 files - this is to address the limitation in 7edit application which does not show multiple files in batch mode and requires a single batch file.
@ECHO OFF
SET UnzipperPATH="C:\Program Files\7-Zip\7z.exe"
SET HL7EditorPATH="C:\Program Files\7edit.com\7Edit 2.x\7edit.exe"
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%f IN (*.zip) DO (
CALL :Unzip %%~nf
SET /P DeleteZip="Delete Zip File? [y/n]: "
IF /I !DeleteZip!==y DEL /Q %%~nf.zip
@mnadjit
mnadjit / ubuntu-general-config.md
Last active May 13, 2022 14:16
A collection of commands to set up an ubuntu server

Hardware

`sudo lshw`
`sudo lshw -businfo`

CPU

  • CPU physcial info: sudo lshw -businfo | grep cpu
  • CPU details: cat /proc/cpuinfo
  • CPU architecture:lscpu | grep -i arch
  • CPU detailed info: cpuid

Memory

  • RAM physical info: sudo lshw -businfo | grep memory
@mnadjit
mnadjit / MoveFileToRemoteStorage.bat
Last active June 3, 2021 05:31
This batch script checks contents of a folder down to three levels with a specific structure and moves folders which DO NOT have today's timestamp as folder name to a remote storage using a UNC path.
@ECHO ON
SET SourceDir=%1
SET DestUNC=%2
:: Remove quotes around the path
SET SourceDir=%SourceDir:~1,-1%
SET DestUNC=%DestUNC:~1,-1%
SET LogPath="%SourceDir%\MoveProcesslog.txt"
SET MaxLogSize=500000
@mnadjit
mnadjit / #MoveFolders-EmailLowDiskFreeSpace.ps1
Last active June 16, 2021 06:15
This script moves folders with any date timestamp except for today, and moves it to a remote UNC path. Also checks free disk space and sends out notification email if under threshold - also checks for a file with fail*.* format that indicates another process failed to run properly.
function CreateFailureFlagFile {
$script:FailureFilePath = "$(Get-Location)\\_Failure-$(Get-Date -format yyyyMMdd).txt"
ECHO 'Issue occured during processing of MoveFolders-EmailLowDiskFreeSpace.ps1 - Please refer to log file in same directory named TransferLog.txt' | Out-File -FilePath $FailureFilePath
}
function GetConfigs {
try {
$script:LogPath = Join-Path -Path $(Get-Location).Path -ChildPath "TransferLog.txt"
MoveLogToOldLogIfLarge
@mnadjit
mnadjit / curl_basic_authorization.ps1
Last active June 16, 2021 06:31
Two methods to perform basic authorization to access a REST API which allows this
// Method 1
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ($username, $securePassword)
Invoke-RestMethod $Uri -Credential $cred
Invoke-WebRequest -Uri $Uri -Method GET -Credential $cred
// Method 2
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username,$password)))
Invoke-RestMethod $Uri -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
Invoke-WebRequest -Uri $Uri -Method GET -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}