Getting around protected read-only MS Word/LibreOffice odt documents
Posted by Kelvin on 13 Jun 2012 | Tagged as: Ubuntu
I recently received an agreement in MS Word format which I wanted to fill out, but couldn't because it was protected/read-only. Opening the document in LibreOffice writer didn't significantly improve the situation.. whole sections of the document was still marked read-only.
Here's what I did to get around it:
1. Open .doc in LibreOffice Writer, save as .odt
2. Open .odt in AbiWord, make changes, save back to .odt
3. (optional) Open .odt in LibreOffice Writer and do whatever else you need to do
At this point, you're probably wondering: why not open the .doc in AbiWord in the first place? Well, AbiWord didn't import the .doc very well, with lots of formatting issues, missing characters etc. Using LibreOffice Writer to convert the .doc to .odt bypasses this.
Split wav/flac/ape files with cue
Posted by Kelvin on 07 May 2012 | Tagged as: Ubuntu
If you ever need to split a disc image which has been burned as a single wav/flac/ape file with a corresponding cue file, this will help you out.
Split2flac does all the tedium of splitting, renaming (according to a renaming pattern of your choosing), converting to FLAC/M4A/MP3/OGG_VORBIS/WAV, as well as adding ID3 tags.
sudo wget https://raw.github.com/ftrvxmtrx/split2flac/fe1f5a2c62dad5c514b118fbb90f7974ae28f712/split2flac
sudo chmod +x split2flac
Now type "split2flac -h" for usage instructions.
Batch convert svg to png in Ubuntu
Posted by Kelvin on 19 Oct 2011 | Tagged as: Ubuntu
for i in *; do rsvg-convert -a $i -o `echo $i | sed -e 's/svg$/png/'`; done
to rasterize the svg at 300dpi, shrinking dimensions by 50%:
Mount a .dmg file in Ubuntu
Posted by Kelvin on 11 Oct 2011 | Tagged as: Ubuntu
dmg2img /path/to/image.dmg
sudo modprobe hfsplus
sudo mount -t hfsplus -o loop image.img /mnt
The .dmg archive is now mounted at /mnt. You can browse it either via command-line or via Nautilus.
Courtesy of http://iremedy.net/blog/2010/11/how-to-mount-a-dmg-file-in-ubuntu-linux/
Delete directories older than x days
Posted by Kelvin on 04 Aug 2011 | Tagged as: Ubuntu
Great for cleaning up log directories.
Change 14 to the required age in days.
Determine if a server supports Gzip compression
Posted by Kelvin on 06 Jun 2011 | Tagged as: Ubuntu
curl http://www.supermind.org --silent --write-out "size_download=%{size_download}\n" --output /dev/null
echo "Size WITH accepting gzip"
curl http://www.supermind.org --silent -H "Accept-Encoding: gzip,deflate" --write-out "size_download=%{size_download}\n" --output /dev/null
You can of course substitute the URL with a different one.
On my site, this is what I get:
$size_download=10560
$curl http://www.supermind.org --silent -H "Accept-Encoding: gzip,deflate" --write-out "size_download=%{size_download}\n" --output /dev/null
$size_download=4345
HOWTO: Add gzip support to Squid 3.1 in Ubuntu
Posted by Kelvin on 06 Jun 2011 | Tagged as: Ubuntu
The squid3 deb that's available in the apt repos don't come configured with ecap support, which is required to support serving of gzip-compressed pages to clients.
In a network environment where the majority of traffic is wireless (like where I live), reducing the payload of internal network requests will have a positive impact on performance.
Follow instructions precisely at http://code.google.com/p/squid-ecap-gzip/wiki/Installation.
You should use Squid 3.1.11 and ecap 0.03 even though more recent versions are available. I tried compiling with 3.1.12.2 and ran into a bunch of make errors, where 3.1.11 compiled just fine.
The one step where I deviated from the instructions, was when configuring Squid. I used, instead, configure options which were closer to the original Ubuntu release. Here it is:
The last switch adds support for ecap.
Using sed to delete lines from a file
Posted by Kelvin on 21 May 2011 | Tagged as: Ubuntu
Delete line containing foo
Delete last line
Recursively find the n latest modified files in a directory
Posted by Kelvin on 18 May 2011 | Tagged as: programming, Ubuntu
Here's how to find the latest modified files in a directory. Particularly useful when you've made some changes and can't remember what!
Replace tail -1 with tail -20 to list the 20 most recent files for example.
Courtesy of StackOverflow: http://stackoverflow.com/questions/4561895/how-to-recursively-find-the-latest-modified-file-in-a-directory
Convert fixed-width file to CSV
Posted by Kelvin on 12 May 2011 | Tagged as: programming, Ubuntu
After trying various sed/awk recipes to convert from fixed-width to CSV, I found a Python script that works well.
Here it is, from http://code.activestate.com/recipes/452503-convert-db-fixed-width-output-to-csv-format/
## {{{ http://code.activestate.com/recipes/452503/ (r1)
# Ian Maurer
# http://itmaurer.com/
# Convert a Fixed Width file to a CSV with Headers
#
# Requires following format:
#
# header1 header2 header3
# ------------ ------- ----------------
# data_a1 data_a2 data_a3
def writerow(ofile, row):
for i in range(len(row)):
row[i] = '"' + row[i].replace('"', '') + '"'
data = ",".join(row)
ofile.write(data)
ofile.write("\n")
def convert(ifile, ofile):
header = ifile.readline().strip()
while not header:
header = ifile.readline().strip()
hticks = ifile.readline().strip()
csizes = [len(cticks) for cticks in hticks.split()]
line = header
while line:
start, row = 0, []
for csize in csizes:
column = line[start:start+csize].strip()
row.append(column)
start = start + csize + 1
writerow(ofile, row)
line = ifile.readline().strip()
if __name__ == "__main__":
import sys
if len(sys.argv) == 3:
ifile = open(sys.argv[1], "r")
ofile = open(sys.argv[2], "w+")
convert(ifile, ofile)
else:
print "Usage: python convert.py <input> <output>"
## end of http://code.activestate.com/recipes/452503/ }}}
