Interesting pieces of code

Post

Posted
Rating:
#1 (In Topic #95)
Regular
monteiro is in the usergroup ‘Regular’
Ok, I know some of you have some piece of code or ideas that is/was really a problem solver. Let's see some!
CREATING EDITABLE DOCUMENTS FOR AN OFFICE
Problem: The office produces some huge reports using LibreOffice. To much text to type!
Solution: These reports are water sample analysis.
  1) The lab feeds the results into a postgresql database.
  2) When finished the work on the water sample by the lab, an office software alerts its user.
  3) This software has a odt report template, which is copied to another directory for edition and uncompressed there.
  4) All the data is in the content.xml file. So, we could use a script to edit some placeholders we have in our template. Here is an example:

Code

#!/bin/bash
cd "$1"
sed -i "s~$2~$3~" content.xml
 5) After editing, we can compress the files again, rename it as ".odt" e save it to a FTP server. Here is an example of the FTP transaction:

Code

#!/bin/bash
ftp -n <<EOF
open ftp://IP
user name password
put $1
EOF

Once in the FTP server, the file is available to the customer.

Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
Well I was pleased with this: -

Code

Public Sub Form_Open()
Dim sTemp As String = "This              is     a          very                  badly                         spaced                                         string"
Dim sCheck As String

Repeat
  sCheck = sTemp
  Print sTemp
  sTemp = Replace(sTemp, "  ", " ")
Until sCheck = sTemp

sTemp = Replace(sTemp, " is", " WAS")
Print "\n" & sTemp

End
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
This is another piece of code I liked. I had a database stored in a .csv file but I wanted to display the contents in a particular order. This code is not exactly as used but simplified to show the principle.

Code

Public Sub Form_Open()
Dim sInputString As String[] = ["One ", "Three ", "Zero ", "Five", "Four ", "Two "]
Dim sOrder As Short[] = [2, 0, 5, 1, 4, 3]
Dim siCount As Short

For sicount = 0 To 5
  Print sInputString[sOrder[siCount]];
Next

End
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
monteiro is in the usergroup ‘Regular’
 This one is useful to export html or php page directly to pdf from firefox command line:
1 - Install cmdlnprint complement for firefox
From your code:
2 -  Shell "firefox -print " & URL & "  -print-mode pdf -print-file " & /file_path/file_name.pdf

A software I wrote creates a bank slip using php. The document is saved as pdf in order to be sent to the customer by email.

Online now: No Back to the top
1 guest and 0 members have just viewed this.