Skip to content

Instantly share code, notes, and snippets.

@swbuehler
swbuehler / dedupe.vba
Created September 9, 2016 15:48
Dedupe(): Removes duplicate emails from currently active Outlook folder by comparing the Sent Dates of emails and removing emails with duplicate sent dates.
Sub dedupe()
Dim ol As New Outlook.Application
Dim dates As Collection
Dim mbox As Outlook.Folder
Set dates = New Collection
Set mbox = ol.ActiveExplorer.CurrentFolder
For Each msg In mbox.Items
msgDate = msg.SentOn
@swbuehler
swbuehler / LocalTimeToUTC.vba
Last active September 9, 2016 15:46
Set of types and functions that use the System time to return a value of given date/time in UTC. This is the 64-bit version; to convert to 32-bit search for and remove any occurence of "PtrSafe". I found this on the Internet written by someone else (forget who) but include it here for ease of use.
Public Declare PtrSafe Function SystemTimeToFileTime Lib _
"kernel32" (lpSystemTime As SYSTEMTIME, _
lpFileTime As FILETIME) As Long
Public Declare PtrSafe Function LocalFileTimeToFileTime Lib _
"kernel32" (lpLocalFileTime As FILETIME, _
lpFileTime As FILETIME) As Long
Public Declare PtrSafe Function FileTimeToSystemTime Lib _
"kernel32" (lpFileTime As FILETIME, lpSystemTime _
@swbuehler
swbuehler / CorrectDateOnPage.vba
Last active September 9, 2016 15:42
Changes date of a OneNote page depending on information provided in "Sent" email header from Outlook or a table with "Date/Time" header (VBA). Requires a "LocalTimeToUTC()" function provided elsewhere.
Sub CorrectDateOnPage()
Dim appOneNote As New OneNote.Application
Dim pageXML As New MSXML2.DOMDocument60
Dim pageContent As String
Dim clipboard As New MSForms.DataObject
Dim tNodes As IXMLDOMNodeList
Dim tNode As IXMLDOMNode
thisPage = appOneNote.Windows.CurrentWindow.CurrentPageId
appOneNote.GetPageContent thisPage, pageContent, piAll, xs2013
pageXML.LoadXML pageContent
@swbuehler
swbuehler / RxNorm.vba
Created August 25, 2016 20:32
Get RxNorm drug name based on provided NDC (Office VBA, MSXML2)
Function RxNorm(ByVal strNDC As String)
Dim xmlhttprequest As MSXML2.XMLHTTP
Dim xmlresponse As New MSXML2.DOMDocument60
Set xmlhttprequest = New MSXML2.XMLHTTP
xmlhttprequest.Open "GET", ("https://rxnav.nlm.nih.gov/REST/rxcui?idtype=NDC&id=" & strNDC), False
xmlhttprequest.send
xmlresponse.Load xmlhttprequest.responseXML
If xmlresponse.SelectSingleNode("//rxnormId") Is Nothing Then
RxNorm = "**NDC Not Found**"
Exit Function
@swbuehler
swbuehler / Automatic Trip Log.ps1
Created August 3, 2016 17:47
Fetch trip logs from Automatic API (app registration required)
$results = @()
$headers = @{"Authorization" = "Bearer XXXXXXXXXX"}
$feed = Invoke-RestMethod -Uri "https://api.automatic.com/trip/" -Headers $headers
$next = $feed._metadata.next
while ($next -ne $null){
foreach ($result in $feed.results){
$results += $result
}
$feed = Invoke-RestMethod -Uri $next -Headers $headers
$next = $feed._metadata.next
@swbuehler
swbuehler / importfollowers.sql
Created July 30, 2016 20:06
SQL Server 2016: Stored Procedure to pull data from a JSON text file
create procedure [dbo].[InsertFollowers]
AS
BEGIN
truncate table dbo.followers
INSERT INTO dbo.followers
SELECT k.*
FROM OPENROWSET (BULK 'C:\temp\missellacronin.json', SINGLE_NCLOB) as j
CROSS APPLY OPENJSON(BulkColumn, '$')
WITH (
created_at datetimeoffset,
{
"StartTime" : "{{UpdatedAt}}",
"EndTime" : "{{UpdatedAt}}",
"Event" : "Posted to Facebook: {{Message}}",
"Location" : "",
"Description" : ""
}
function doPost(e) {
moment = Moment.load();
var cal = CalendarApp.getCalendarById('<<CALENDAR ID>>@group.calendar.google.com');
var postContent = e.postData.getDataAsString();
var json = JSON.parse(postContent);
var startTime = moment(json.StartTime,'MMMM DD, YYYY at hh:mmA').local().toDate();
var endTime = moment(json.EndTime, 'MMMM DD, YYYY at hh:mmA').local().toDate();
var event = json.Event.toString();
@swbuehler
swbuehler / gist:8407295
Created January 13, 2014 20:17
Parse filename and add keywords to PDF file (sample) using exiftool
tell application "Finder"
set theFolder to alias "Mac mini:Users:steven:SkyDrive:Receipts"
set thePDFs to every file in theFolder
repeat with eachPDF in thePDFs
try
set theFileName to the name of eachPDF
set theDate to (text 6 thru 7 of theFileName) & "/" & (text 9 thru 10 of theFileName) & "/" & (text 1 thru 4 of theFileName)
set theVendor to text 19 thru ((offset of "$" in theFileName) - 2) of theFileName
set theAmount to text (offset of "$" in theFileName) thru ((offset of ".pdf" in theFileName) - 1) of theFileName
set theKeywords to (quote & "vendor=" & theVendor & ", date=" & theDate & ", amount=\\" & theAmount & quote) as text
@swbuehler
swbuehler / Update Creation Dates.scpt
Last active December 29, 2015 13:29
Evernote: Update creation dates based on information in note title
tell application "Evernote"
set theNotes to the selection
repeat with eachNote in theNotes
set dateflag to 0
set theTitle to the title of eachNote
if theTitle begins with "DOS" and theTitle ends with "(Notes)" then -- for Medical Notes (DOS yyyy-mm-dd ... (Notes))
try
set the creation date of eachNote to date (do shell script "date -j -f '%F' " & quote & (characters 5 thru 14 of theTitle as string) & quote & " +'%A, %B %d, %Y at %r'")
set dateflag to 1
end try