Skip to content

Instantly share code, notes, and snippets.

@ricdeez
ricdeez / gist:4167823
Created November 29, 2012 09:34
Ruby: Turn pipe delimited data into array of arrays.
new_data = new_data.split(/\n/).collect {|v| v.split(/\|/)}
@ricdeez
ricdeez / gist:4167831
Created November 29, 2012 09:36
Ruby: Manipulate MSWord Docs
%w(pp win32ole).each {|dep| require dep}
begin
$app = WIN32OLE.connect('Word.Application')
rescue Exception => e
$app = WIN32OLE.new('Word.Application')
end
$app.Visible = true
class WordConst
@ricdeez
ricdeez / gist:4167844
Created November 29, 2012 09:42
Ruby: Instantiate Word Object
$wd = WIN32OLE.new('Word.Application')
$wd.Visible = true
doc = $wd.Documents.Open(doc_file)
@ricdeez
ricdeez / msproject_filter_by_taskname_and_sort.rb
Created December 13, 2012 22:59
MS Project: List of tasks matching a pattern, sorted by one parameter
#!/usr/bin/ruby
%w( win32ole pp date ).each { |dep| require dep }
doc = 'C:\Users\rdapaz\Dropbox\Karara\Schedule\K2 Master Schedule - Delayed FAT Scenario.mpp'
mpp = WIN32OLE.new('MSProject.Application')
mpp.Visible = true
mpp.FileOpen(doc)
tasks = []
mpp.ActiveProject.Tasks.each do |tsk|
@ricdeez
ricdeez / gist:4436412
Created January 2, 2013 17:43
ImageMagick label picture
convert sm_giga-01.jpg -gravity south \
-stroke '#000C' -strokewidth 2 -annotate 0 'g33ky_b1ts' \
-stroke none -fill white -annotate 0 'g33ky_b1ts' \
polsm_giga-01.jpg
@ricdeez
ricdeez / JoinCells.vb
Created January 17, 2013 07:08
VBA: Join Cells on a Spreadsheet
Public Sub JoinCells()
Dim xls As Excel.Worksheet
Dim cell As Excel.Range
Dim destn_rge As Excel.Range
Dim combined As String
Dim i As Long
i = 0
Set destn_rge = Nothing
@ricdeez
ricdeez / databaseimport.rb
Created January 18, 2013 09:25
Ruby Import data to Access from Excel
%w(pp win32ole).each { |dep| require dep }
db = 'C:\Users\rdapaz\Documents\Statement of Compliance.accdb'
cs = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=#{db};"
rs = WIN32OLE.new('ADODB.Recordset')
conn = WIN32OLE.new('ADODB.Connection')
conn.Open(cs)
rs.Open("[SoC]", conn, 1, 3)
conn.Execute("DELETE * FROM SoC")
@ricdeez
ricdeez / list_in_words.rb
Created January 29, 2013 06:58
Ruby: List in Words
print "#{doc}: "
print "#{data.size > 1 ? data[0..-2].join(", ") : ""}#{data.size > 1 ? " and " : "" }#{data[-1].join("")}" if data.size > 0
print "None" if data.size == 0
@ricdeez
ricdeez / TimesheetDBEOWUpdater.rb
Created February 5, 2014 06:02
Update Access database date/time field to show date at the end of the week
%w(win32ole date time).each { |dep| require dep }
def week_ending(tm)
# The <?Date> object passed in to week_ending is actually an instance of the Time class
new_tm = tm
offset = case new_tm.strftime('%a')
when "Mon"
6
when "Tue"
5
@ricdeez
ricdeez / excel_cell_joiner.vb
Created February 19, 2014 09:33
Excel Join Cells
# encoding: UTF-8
%w(pp date).each { |dep| require dep }
def weird_date_todate(weird_date)
Date.new(weird_date.split(/\./)[2],weird_date.split(/\./)[1],weird_date.split(/\./)[0])
end
puts weird_date_todate('14.10.2013')
# data = DATA