Skip to content

Instantly share code, notes, and snippets.

@hyperqube
hyperqube / add2fossil.sh
Created May 23, 2012 13:59
Add non-binary files to fossil
find -type f -regex '[^~]*' -exec dos2unix -b -v -U {} 2>&1 \;\
| grep Unix \
| sed -e "s/..Unix .*//" | cut -b 16-300 | xargs fossil add
require 'pp'
require 'win32ole'
require 'yaml'
require 'set'
@access = WIN32OLE.new('Access.Application')
@filename = 'D:\dev\dashboard.accdb'
@access.OpenCurrentDatabase @filename
@prefix = "D:\\dev\\dump\\"
@db = @access.CurrentDb()
@hyperqube
hyperqube / gist:2838183
Created May 30, 2012 18:38
Convert to Access 2007
require 'win32ole'
def convert_to_access2007(srcdir)
Dir.chdir(srcdir)
access = WIN32OLE.new('Access.Application')
Dir.glob('*.mdb').map do |mdb|
src = File.expand_path(mdb).gsub /\//, "\\"
dst = src.sub /.mdb$/i , '.accdb'
print "Converting ",src,"to", dst
# 12 for access 2007
access.ConvertAccessProject src , dst , 12
def get_all_sql(srcdir)
Dir.chdir(srcdir)
fullname = File.expand_path('query.sql', srcdir)
access = WIN32OLE.new('Access.Application')
File.open(fullname,'w' ) do |o|
Dir.glob('*.accdb').each do |f|
access.OpenCurrentDatabase(File.expand_path(f))
db = access.CurrentDb()
if !db.nil? then
db.QueryDefs.each{ |q|
@hyperqube
hyperqube / get_all_sql.rb
Created May 31, 2012 15:04
Extract all Access query in SQL to a text file
require 'win32ole'
def get_all_sql(srcdir)
Dir.chdir(srcdir)
access = WIN32OLE.new('Access.Application')
Dir.glob('*.accdb').each do |f|
src = File.expand_path(f).gsub /\//, "\\"
access.OpenCurrentDatabase src
if db = access.CurrentDb then
puts "processing #{src}"
sql_buffer = " -- #{src}"
require 'pp'
require 'win32ole'
require 'yaml'
require 'set'
class String ; def is_valid?; self.strip != "" ; end ; end
class Integer; def is_valid?; self > 0 ; end ; end
class FalseClass; def is_valid?; self ; end; end
require 'pp'
require 'win32ole'
require 'yaml'
require 'set'
class String ; def is_valid?; self.strip != "" ; end ; end
class Integer; def is_valid?; self > 0 ; end ; end
class FalseClass; def is_valid?; self ; end; end
require 'pp'
require 'win32ole'
path = 'D:/dev/access/tmp/*.sql'
tablist =[]
Dir.glob(path).map do |f|
File.open(f,"r:CP863") do |i|
tablist << i.read.scan(/\W[Rr]_\w{5,9}/)
end
end
@hyperqube
hyperqube / get_partition.rb
Created June 6, 2012 16:54
Distribute objects in n partitions with approximately equal size
class Partition
def initialize
@sum = 0
@names = []
end
attr_reader :sum,:names
def add(name,size)
@names << name
@sum=@sum+size
end
@hyperqube
hyperqube / get_partition.ps1
Created June 7, 2012 16:49
Split files into roughly equal partitions
function Add-Prop([string]$name,$value){
$input |add-member -memberType Noteproperty -name $name -value $value -passThru
}
function Get-Partitions($no_partitions=4){
$sums = @()
$indexes = (0..($no_partitions-1))
$indexes |% { $sums+= 0 }
$sortedBySize = $input | Sort Length -Descending
foreach($file in $sortedBySize){