Skip to content

Instantly share code, notes, and snippets.

@panreel
panreel / upload-blob-azure.js
Last active November 6, 2022 09:29
Upload a binary data from request body to Azure BLOB storage in Node.js [restify]
//NOTE: Do not use restify.bodyParser() - it blocks piping
//vars
var azure = require('azure-storage');
// ... BLOB connection skipped ...
//Option 1 - Piping req stream to BLOB write stream (elegant)
function (req, res, next) {
//create write stream for blob
var stream = azure.createWriteStreamToBlockBlob(
@panreel
panreel / PS-O365-AuditTest.ps1
Last active November 14, 2017 14:06
Testing PowerShell connection to O365/EXO by storing User Credentials for automatic access
# use stored credential or ask for new one
$useStoredCredsIfAvailable = $True
# credsFile location
$CredsFile = "./AuthKey"
# check if creds file exists
$FileExists = Test-Path $CredsFile
If(-not $useStoredCredsIfAvailable -or $useStoredCredsIfAvailable -and -not $FileExists){
@panreel
panreel / HackerCupQualR2.java
Last active January 11, 2017 02:08
Facebook HackerCup 2017 - Qualifications R2
import java.io.*;
import java.util.*;
public class HackerCupQualR2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int times = in.nextInt();
for(int i = 1; i <= times; i++) {
int l = in.nextInt();
@panreel
panreel / compress.js
Created March 11, 2018 16:07
NPM Img Compression Script
const dir = require('node-dir');
var jimp = require("jimp");
const args = process.argv;
dir.promiseFiles(args[2])
.then(files => {
for(let file of files) {
jimp.read(file).then(image => {
image
.quality(60)
@panreel
panreel / PPtoE3PP.ps1
Created June 12, 2018 17:04
Change ProPlus/standalone licenses to E3/ProPlus licenses
#Connect to O365 Admin
Connect-MSolService
#Get company name
$accountSkus = Get-MsolAccountSku
$companyName = $accountSkus.AccountSkuId[0].split(":")[0]
$Office365ProPlusSku = $companyName + ":OFFICESUBSCRIPTION"
$Office365E3Sku = $companyName + ":ENTERPRISEPACK"
$Office365E3SkuServicePlansWithoutProPlus = "BPOS_S_TODO_2","FORMS_PLAN_E3","STREAM_O365_E3","Deskless","FLOW_O365_P2","POWERAPPS_O365_P2","TEAMS1","PROJECTWORKMANAGEMENT","SWAY","INTUNE_O365","YAMMER_ENTERPRISE","RMS_S_ENTERPRISE","MCOSTANDARD","SHAREPOINTWAC","SHAREPOINTENTERPRISE","EXCHANGE_S_ENTERPRISE"
#Get all licensed users - You can add more filters Get-MsolUser -All <more filters, e.g. -Department "Sales" -UsageLocation "US"
$x = Get-MsolUser -All | where {$_.isLicensed -eq $true}
@panreel
panreel / changeBulkEmail.ps1
Last active October 3, 2018 12:30
Change Username to WP Accounts by using SCIM API and PowerShell
param(
[Parameter(Mandatory=$true, Position=0, HelpMessage='Path for your Workplace export file')] [string]$WPExportedUsers,
[Parameter(Mandatory=$true, Position=1, HelpMessage='Path for your Workplace access token in .json format {"accessToken" : 123xyz}')] [string]$WPAccessToken,
[switch]$Interactive
)
#Install ImportExcel Module
If(!(Get-module ImportExcel)){Install-Module ImportExcel -scope CurrentUser}
#Read JSON Access Token
@panreel
panreel / exportGroupMembers.ps1
Last active March 4, 2019 08:01
Export members from a Workplace group to a XLSX file
param(
[Parameter(Mandatory=$true, HelpMessage='The ID of the Workplace Group you would like to export')] [string]$GroupId,
[Parameter(Mandatory=$true, HelpMessage='Path for your Workplace access token in .json format {"accessToken" : 123xyz}')] [string]$WPAccessToken
)
#Install ImportExcel Module
If(!(Get-module ImportExcel)){Install-Module ImportExcel -scope CurrentUser}
#Read JSON Access Token
try {
@panreel
panreel / cleanGroupMembers.ps1
Last active October 19, 2018 17:41
Remove members from a Workplace group (based on their domain or an input XLSX file)
param(
[Parameter(Mandatory=$true, HelpMessage='The ID of the Workplace Group you would like to remove users from')] [string]$GroupId,
[Parameter(Mandatory=$false, HelpMessage='The domain of the users you would like to remove')] [string]$EmailDomain,
[Parameter(Mandatory=$false, HelpMessage='Path to your file listing users to remove from group')] [string]$WPGroupMembers,
[Parameter(Mandatory=$true, HelpMessage='Path to your Workplace access token in .json format {"accessToken" : 123xyz}')] [string]$WPAccessToken,
[Parameter(Mandatory=$false, HelpMessage='Mode you would like to run the tool in: {Test (default), Live, Live-Force}')] [string]$Mode = 'Test'
)
#Read JSON Access Token
try {
@panreel
panreel / activateInBulk.ps1
Created November 8, 2018 16:47
Activate users in bulk by using SCIM API
param(
[Parameter(Mandatory=$true, HelpMessage='Path of the user export with the list of the users you would like to activate')] [string]$WPExportedUsers,
[Parameter(Mandatory=$true, HelpMessage='Path for your Workplace access token in .json format {"accessToken" : 123xyz}')] [string]$WPAccessToken,
[switch]$Interactive
)
#Install ImportExcel Module
If(!(Get-module ImportExcel)){Install-Module ImportExcel -scope CurrentUser}
#Read JSON Access Token
@panreel
panreel / exportUsersSCIM.ps1
Last active October 22, 2020 13:04
Export Users from a Workplace instance by using SCIM API
param(
[Parameter(Mandatory=$true, HelpMessage='Path for your Workplace access token in .json format {"accessToken" : 123xyz}')] [string]$WPAccessToken,
[Parameter(Mandatory=$false, HelpMessage='Page size for SCIM requests. Defaults to 100.')] [int]$SCIMPageSize = 100
)
$defJobs = {
$origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0
function Get-Status {
If(-Not $_.active) {return "Deactivated"}