Monday, August 10, 2009

LaTeX-enabled Anonymous Message Boards

I find a lot of the time that I want to ask a stupid question online but don't want my name attached to it. Solution: LaTeX-enabled, optionally anonymous online message boards! To be fair they're really better for just asking quick questions in general. If I have a weird problem on a software project, I can often just pop over to IRC and ask some basic questions, but there's not really a good analogue for math.

I built these myself so they're liable to be a little shaky. I'd appreciate any feedback, and I'll also try to answer any questions you post there, assuming I know how to answer them. To post in LaTeX, just do something like:

How do I know that $\sup \left\{ \int f d\mu : f \leq \phi, \phi \text{ simple}\right\}$ exists?

And nobody will be able to make fun of you for not understanding integration, because they won't know who you are.

Friday, August 07, 2009

Microsoft Access VBA code to Convert Table Records to SQL

This isn't math per se, but today I found it useful to be able to convert some tables in Access to SQL statements that would insert said records into another database. This isn't densely commented and likely isn't bulletproof, but it gets the job done for me and I thought someone might want such a thing, so here it is:
Function SerializeRecords(table As String, criteria As String, filename As String)
Dim rs As DAO.Recordset

On Error Resume Next
Open filename For Append As 1
If Err.Number > 0 Then
MsgBox "Can't write to file " & filename & ".", vbCritical, "Output Error"
Exit Function
End If
qs = "SELECT * FROM " & table & " WHERE " & criteria

On Error Resume Next
Set rs = CurrentDb.OpenRecordset(qs)
If Err.Number > 0 Then
Close #1
MsgBox "Error executing query " & qs, vbCritical, "Output error"
Exit Function
End If

qds = "DELETE FROM " & table & " WHERE " & criteria & ";"
Print #1, qds

Do While Not rs.EOF
qis = "INSERT INTO " & table & "("
For Each f In rs.Fields
qis = qis & "[" & f.Name & "],"
Next f
qis = Mid(qis, 1, Len(qis) - 1) & ") VALUES("
For Each f In rs.Fields
If IsNull(f.Value) Then
qis = qis & "Null,"
ElseIf f.type = dbChar Or f.type = dbText Or f.type = dbMemo Then
qis = qis & EscapeString(f.Value) & ","
ElseIf f.type = dbDate Then
qis = qis & "'" & f.Value & "',"
Else
qis = qis & f.Value & ","
End If
Next f
qis = Mid(qis, 1, Len(qis) - 1) & ");"
Print #1, qis
rs.MoveNext
Loop

Close #1
rs.Close
End Function

Function EscapeString(s As String)
t = Replace(s, "'", "''")
t = Replace(t, Chr(13) & Chr(10), "' & chr(13) & chr(10) & '")
t = "'" & t & "'"
EscapeString = t
End Function

I'm currently working on a medium-scale software project *and* studying for quals, but I'll try to put up some more legit math content here soon.