Thursday, September 24, 2015

Splitting Word document into separate files

#Author: Matt Bungard / bungard at g-mail d com
#
#Pull bits from various sources, if you've been exluded let me know and I'll cite accordingly
#http://stackoverflow.com/questions/26737239/powershell-add-a-new-document-to-exisitng-word-file-with-page-number-of-2
## -- Settings --
#$fileNamePattern = "ID #:\s+(\d+)"
$fileNamePattern = "Student ID #:\s+# (\d+)"
$pageLength = 1
$inputFile = "inputDoc.docx"
$outputPath = "outputDir\" #End the path with a slash
## -- End Settings
[ref]$SaveFormat = "microsoft.office.interop.word.WdSaveFormat" -as [type]
$word = New-Object -ComObject word.application
$word.Visible = $true
$doc = $word.Documents.Open($inputFile)
$pages = $doc.ComputeStatistics([Microsoft.Office.Interop.Word.WdStatistic]::wdStatisticPages)
$rngPage = $doc.Range()
for($i=1;$i -le $pages; $i+=$pageLength)
{
[Void]$word.Selection.GoTo([Microsoft.Office.Interop.Word.WdGoToItem]::wdGoToPage,
[Microsoft.Office.Interop.Word.WdGoToDirection]::wdGoToAbsolute,
$i #Starting Page
)
$rngPage.Start = $word.Selection.Start
[Void]$word.Selection.GoTo([Microsoft.Office.Interop.Word.WdGoToItem]::wdGoToPage,
[Microsoft.Office.Interop.Word.WdGoToDirection]::wdGoToAbsolute,
$i+$pageLength #Next page Number
)
$rngPage.End = $word.Selection.Start
$marginTop = $word.Selection.PageSetup.TopMargin
$marginBottom = $word.Selection.PageSetup.BottomMargin
$marginLeft = $word.Selection.PageSetup.LeftMargin
$marginRight = $word.Selection.PageSetup.RightMargin
$rngPage.Copy()
$newDoc = $word.Documents.Add()
$word.Selection.PageSetup.TopMargin = $marginTop
$word.Selection.PageSetup.BottomMargin = $marginBottom
$word.Selection.PageSetup.LeftMargin = $marginLeft
$word.Selection.PageSetup.RightMargin = $marginRight
$word.Selection.Paste() # Now we have our new page on a new doc
$word.Selection.EndKey(6,0) #Move to the end of the file
$word.Selection.TypeBackspace() #Seems to grab an extra section/page break
$word.Selection.Delete() #Now we have our doc down to size
#Get Name
$regex = [Regex]::Match($rngPage.Text, $fileNamePattern)
if($regex.Success)
{
$id = $regex.Groups[1].Value
}
else
{
$id = "patternNotFound_" + $i
}
$path = $outputPath + $id + ".docx"
$newDoc.saveas([ref] $path, [ref]$SaveFormat::wdFormatDocumentDefault)
$newDoc.close()
Remove-Variable(regex)
Remove-Variable(id)
}
[gc]::collect()
[gc]::WaitForPendingFinalizers()

Tuesday, September 22, 2015

Rails - Apache - "Web Application could not be started"

When deploying a new rails application to a local Apache install, i seem to run into this error:
Web application could not be started It looks like Bundler could not find a gem. Maybe you didn't install all the gems that this application needs. To install your gems, please run: bundle install If that didn't work, then the problem is probably caused by your application being run under a different environment than it's supposed to. Please check the following:
A quick fix, appears to be:

Run: bundle install --path vendor/bundle

Source: http://stackoverflow.com/a/5589346/3084542

Friday, May 29, 2015

Shell command to remove a .bak extension

find . -name "*.bak" -exec sh -c 'mv {} "`dirname {}`/`basename {} .bak`"' \;

Monday, May 7, 2012

C# Escaping Generic Objects for SQL Server

In response to a need to escape various fields within any given class object, I worked up this guy. Essentially, iterates through all members of a given object and replaces single quotes with doubles on any String object. private static void SQLServerEscapeObject(object obj) { foreach (System.Reflection.PropertyInfo property in obj.GetType().GetProperties()) { try { if (property.PropertyType.FullName == "System.String" && property.GetValue(obj, null) != null) { property.SetValue(obj, property.GetValue(obj, null).ToString().Replace("'", "''"), null); } } catch (Exception e) { Logger.Log("Issue clensing SQL query: " + e.Message, Logger.Loglevel.Warning); } } return; }

Wednesday, August 3, 2011

Exchange web-services

Actual code to come later one.
in short, thanking
http://felixmondelo.blogspot.com/2008/08/exchange-2007-web-services-iii-update.html
and
http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/b8f91d59-9c1f-4a61-8e5d-3e33ca28fd9e/

for assistance in making Calendar update requests.

Wednesday, January 12, 2011

Project Server 2010 PSI - CustomFields

Here is a method that will add a CustomFieldRow to a ProjectDataSet for use in ProjectServer 2010 through the PSI.




Here are the support calls to get the necessary GUID's.


Credits:
http://blogs.msdn.com/b/brismith/archive/2010/08/25/project-server-adding-custom-fields-to-projects-and-tasks-using-the-psi.aspx

http://blogs.msdn.com/b/project_programmability/archive/2008/02/28/custom-field-and-lookup-table-webcast.aspx

Sunday, October 24, 2010

Rails routes, respond_to and more

As pulled from:
http://info.michael-simons.eu/2007/08/06/rails-respond_to-method/

I've used respond_to previously...but it slipped my mind..so i figured I'd repost it here.

Here is the snippit that replaced a separate (and now useless method) for each major entry view page.

respond_to do |format|
format.html
format.js { render :partial => 'list.html.erb' }
end

Tuesday, February 23, 2010

Flot - jQuery Graphing

http://code.google.com/p/flot/

Here is one use of Flot in an app I'm working on:

JS:



Some ruby to fill in the data/ticks variables:



and that's about it. Some tweaking to clean things up, but I now have a nice weight over time graph with appropriate BMI ranges coloring the background.