Powershell Marries C#

######################################
# Use Powershell as a Wrapper for C# #
######################################
(Start-Job { 

# process powershell command line arguments
param($stufffromcommandline) 
$stufffromcommandline = @{$true="run spot run";$false=$stufffromcommandline}[[string]::IsNullOrEmpty($stufffromcommandline)]
  
    
# ignore next line
$csharpcode = @”
// ##############################################################################


using System;
using System.Linq;
using System.Diagnostics;
using System.Threading;

namespace c
{
    public static class spot 
    {
        public static string run(string message)
        {
            try {
                Log(message);
                var x = "This is a test.";
                Log(x);
                Log(x);
                Log(x);
                Log(x);
                Log(x);
                string y = null;
                Log(y.ToString() );
                
                Console.WriteLine("You won't see this. Really.");
                Debug.WriteLine("Or this."); 
                Console.Out.WriteLine("Or that.");
                
            } catch (Exception e) {
                Log(e);
            }
            return APPLICATION_OUTPUT;
        }
        
        private static string APPLICATION_OUTPUT = "";
        private static void Log(object toLog)
        {
            if (toLog != null)
                APPLICATION_OUTPUT += toLog.ToString() + Environment.NewLine;
        }
    }
}





// ##############################################################################
“@   
Add-Type -TypeDefinition $csharpcode -Language csharpversion3 
[c.spot]::run($stufffromcommandline)



} -ArgumentList $args) | wait-job | receive-job ; Remove-Job *

FFMpeg: Convert Videos for streaming

@echo off
echo.
echo Bitte in dieses Fenster die zu konvertierende Datei "reinziehen" 
set /p file=UND mit [ENTER] bestaetigen:

FOR /f "eol=; delims=?" %%i IN ("%file%") DO (
set filedrive=%%~di
set filename=%%~ni
set filepath=%%~pi
echo %%i
)


echo Film: %file%
echo Ausgabedatei: "%filedrive%%filepath%%filename%_konvertiert.mp4"

start "" "bin\ffmpeg" -i %file% -crf 15 -maxrate 2000k -bufsize 2000k "%filedrive%%filepath%%filename%_1_high.mp4"
start "" "bin\ffmpeg" -i %file% -crf 15 -maxrate 1000k -bufsize 1000k "%filedrive%%filepath%%filename%_2_medium.mp4"
start "" "bin\ffmpeg" -i %file% -crf 15 -maxrate  750k -bufsize  750k "%filedrive%%filepath%%filename%_3_low.mp4"
start "" "bin\ffmpeg" -i %file% -crf 15 -maxrate  500k -bufsize  500k "%filedrive%%filepath%%filename%_4_lower.mp4"

Javascript to dynamically insert CSS

<script type="text/javascript">
var css='b table tbody tr td img { transition: all 1s ease-in-out 0s; } b table tbody tr td img:hover{ transform:rotate(720deg) scale(2);}';
style=document.createElement('style');
if (style.styleSheet) style.styleSheet.cssText=css;
else style.appendChild(document.createTextNode(css));
document.getElementsByTagName('head')[0].appendChild(style);
</script>   // 

VBScript Example: Convert a Word document to PDF / Replace a string in a file using regular expressions

' Transforms a doc to a pdf (props to Rafael Winterhalter)
Function DocToPdf( docInputFile, pdfOutputFile )
	Dim fileSystemObject
	Dim wordApplication
	Dim wordDocument
	Dim wordDocuments
	Dim baseFolder

	Set fileSystemObject = CreateObject("Scripting.FileSystemObject")
	Set wordApplication = CreateObject("Word.Application")
	Set wordDocuments = wordApplication.Documents

	docInputFile = fileSystemObject.GetAbsolutePathName(docInputFile)
	baseFolder = fileSystemObject.GetParentFolderName(docInputFile)

	If Len(pdfOutputFile) = 0 Then
	pdfOutputFile = fileSystemObject.GetBaseName(docInputFile) + ".pdf"
	End If

	If Len(fileSystemObject.GetParentFolderName(pdfOutputFile)) = 0 Then
	pdfOutputFile = baseFolder + "\" + pdfOutputFile
	End If

	' Disable any potential macros of the word document.
	wordApplication.WordBasic.DisableAutoMacros

	On Error Resume Next
	' Open readonly
	Set wordDocument = wordDocuments.Open(docInputFile,,True)
	' See http://msdn2.microsoft.com/en-us/library/bb221597.aspx
	wordDocument.SaveAs pdfOutputFile, wdFormatPDF
	wordDocument.Close WdDoNotSaveChanges
	wordApplication.Quit WdDoNotSaveChanges
	Set wordApplication = Nothing
	Set fileSystemObject = Nothing
End Function
 
' Fill with leading zeros
Function LPad (str, pad, length)
    LPad = String(length - Len(str), pad) & str
End Function
 
' Get date string in the form 2000-03-31
Function getIsoDateString()
    getIsoDateString = Year(Now) & "-" & LPad(Month(Now), "0", 2)  & "-" & LPad(Day(Now), "0", 2)
End Function
 
Function replacePatternInFile(file, pattern, replacement)
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.OpenTextFile(file, ForReading)

	source = objFile.ReadAll
	objFile.Close

	Set objRegEx = CreateObject("VBScript.RegExp")
	objRegEx.Global = True   
	objRegEx.IgnoreCase = True
	objRegEx.Pattern = pattern
	source = objRegEx.Replace(source, replacement)

	Set objFile = objFSO.OpenTextFile(file, ForWriting)
	objFile.Write source
	objFile.Close
End Function
 
 
 
 ' See http://msdn2.microsoft.com/en-us/library/bb238158.aspx
Const wdFormatPDF = 17  ' PDF format.
Const wdFormatXPS = 18  ' XPS format.
Const WdDoNotSaveChanges = 0
Const ForReading = 1
Const ForWriting = 2 
  

' Execute script
Call DocToPdf( "c:\mydocument.docx", "\\strangenetworkpath\" & getIsoDateString & " document.pdf" )
If Err.Number = 0 Then
	Call replacePatternInFile("\\strangenetworkpath\content.html", "/.{0,11} document.pdf", "/" & getIsoDateString & " document.pdf" )
	WScript.Echo "Success!"
End If