jeudi 14 mars 2013

Clear clipboard from the Windows PowerShell command line

I convert a bunch of slide decks to word processor handouts used in our trainings. Since there are over 100 decks and powerpoint ends up using Gb's of RAM once it has finished and is doing nothing anymore, I thought I would clear the clipboard.

Tangent: something uses Gb's of RAM and remains idle? Sounds like Microsoft hired some SAP developers.

Anyway, this is how I chose to solve the problem in a nice powershell script:

$a = [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$b = [Windows.Forms.Clipboard]::Clear()


To run this, you must start powershell.exe single-threaded:

powershell -sta myscript.ps1

BTW, sounds strange that powershell starts multi-threaded by default, however, it makes absolutely no sens at all that powershell cannot run this single-threaded shit in a multi-threaded instance.

I can understand that you cannot run multi-threaded shit in a single-threaded instance of powershell, makes sense, but the opposite is just plain fucked up, no ifs, buts, or maybes.


Enjoy

lundi 14 mai 2012

ps2png or pdf2png how to create high quality images from just about anything in Linux

I had this PDF I had to sign for the company I work for. It is a pain to print it out, sign it and scan it to send it out again. So I thought I would use ps2png, which works with PDF's as well, BTW, and use Gimp to insert a scan of my signature at the required position.

The problem we all come across is that ps2png sucks in terms of quality.

Linux (Unbuntu 11.10) comes with the print to svg feature, which is cool. Print the PDF, or whichever file you have, to SVG and use inkscape.

Emacs was bad, inkscape sets new records in ui complexity ... it is the first graphical editor I have come across where you just cannot select a portion of the image to copy and paste it into another. It is also the first graphical editor where you cannot use the mouse to move an inserted image around without invoking some obscure incantations, so use the arrow keys.

The bug (?) I came across was, that the page of the PDF was displayed hundreds (thousands?) of times in the SVG. When you print the resulting image to PDF, you only see it once. In inkscape, you need to edit the image on the bottom left. Click the blue arrow to insert your image, move it to the appropriate location and you can print it. You could also at this point export it to png, In the export dialog, click [Page].


EDIT: inkscape makes PDF's so crisp they make professional marketing guyz shit their pants.

lundi 7 février 2011

Oracle 10R2 on Mac OS X

I wanted to install Oracle 10.2 on Mac OS X 10.6.6 64Bit and found a couple of issues that you might encounter as well. I could not get it to link the Oracle binaries, so this is all a bit moot, for the moment. Will post as soon as I have found a solution for that - I use db2 instead, also a post on installing db2 on darwin in the works.

First of all, create the users and groups as described in the installation instructions:
1. find free id's for groups:
dscl . -list /groups gid | awk '{print $2}' | sort -n
2. find free id's for oracle user:
dscl . -list /users uid | awk '{print $2}' | sort -n
I used uid/gid's 300, 301, 301 for oracle and oinstall, dba, oper, respectively

3. create the groups

dscl . -create /groups/oinstall
dscl . -append /groups/oinstall gid 300
dscl . -append /groups/oinstall passwd "*"


dscl . -create /groups/dba
dscl . -append /groups/dba gid 301
dscl . -append /groups/dba passwd "*"
dscl . -append /groups/dba GroupMembership hans

dscl . -create /groups/oper
dscl . -append /groups/oper gid 302
dscl . -append /groups/oper passwd "*"
dscl . -append /groups/oper GroupMembership hans

4. create the oracle user

You could also use system preferences to create the user, in which case you only have to execute the last three of the dscl commands.
dscl . -create /users/oracle
dscl . -append /users/oracle uid 300
dscl . -append /users/oracle shell /bin/bash
dscl . -append /users/oracle home /Users/oracle
dscl . -append /users/oracle realname "Oracle software owner"

dscl . -append /users/oracle gid 302
dscl . -append /groups/dba GroupMembership oracle
dscl . -append /groups/dba GroupMembership hans

mkdir /Volumes/oracle
chown oracle:oinstall /Volumes/oracle
passwd oracle
5. Next, specify the kernel parameters:

I created a file named /etc/sysctl.conf with the following contents:

kern.sysv.semmsl=87381
kern.sysv.semmns=87381
kern.sysv.semmni=87381
kern.sysv.semmnu=87381
kern.sysv.semume=10
kernel.shmall=2097152
kernel.sys.shmmax=2147483648
kernel.sys.shmmni=4096
kern.maxfiles=65536
kern.maxfilesperproc=65536
net.inet.ip.portrange.first=1024
net.inet.ip.portrange.last=65000
kern.corefile=core
kern.maxproc=2068
kern.maxprocperuid=2068
6. Reboot, log on as oracle
In terminal, you want to start the 32bit Java VM:
Run:
java -version
If java -version shows it is running a 64Bit JVM, you need the 32Bit one:
./runInstaller -J-d32

I got the following error when trying to start runInstaller with the 64Bit JVM:

Install2011-02-08_07-12-16AM/oui/lib/mac_osx/liboraInstaller.dylib: no suitable image found. Did find: /private/tmp/OraInstall2011-02-08_07-12-16AM/oui/lib/mac_osx/liboraInstaller.dylib: mach-o, but wrong architecture

dimanche 23 janvier 2011

Sony Ericsson Xperia and PC Suite or Outlook

My partner had a Sony Ericesson 850i, or something similar. I made her create a backup of that phone about a year ago. Last week she lost it and got an SE Xperia 10. Since she lost her sim with her old phone, she ordered a new one, but lost all her contacts, or so she thought ...

Her phone came with "Sony Ericsson PC Suite 6.0", so that is what I used to make a backup.

I connected her 850i phone and did not mount it!!! Once I opened PC Suite, I went to "Tools > Backup n Restore" and created a backup.

When I open PC Suite now and click on "Backup n Restore" I see the backup that was made. If I click "Modify properties of the backup" (Sorry, the translation might vary, I have it in French) a properties-like dialog opens, and I can see the location of the backup, I click the browse button next to the location path and an explorer window opens with the backup.

Here comes the magic! So, opening the "dbk" file with notepad, I notice it is a pkzip file or, in other words, a simple ZIP file. I make a copy of it, for safety, named "Copie de 20100627.zip" ... excuse my French, it is a French OS.

This I can open in Windows, the first things I see is "contacts.vcf", which like its name suggests, contains all the contacts that were in the 850i. The first thing I do is, I drag this file onto the desktop, go into Outlook, Click "File > Import Export" and choose "Import a VCF file" and browse to the file.

The real pain is, for some weird reason, Outlook does not display contacts that do not have an email address .... but they are there! To make sure, just export your contacts into a CSV file - you'll notice that unlike most email clients, you cannot export your contacts into vcf file - Outlook is an evil piece of crap, don't start using it, if you can help it!!!!

This contacts.vcf you can also import into gmail, then sync you phone with gmail. In gmail, go to "Contacts", then "Import Contacts", click "Choose a file" and navigate to your VCF file, optionally choose a group name and click import.


For those upset about putting their contacts into gmail, the other option with this android, from what I have seen using it for 5 minutes, is sony ericsson's website ... don't ask me what is worse, I do not know.

vendredi 17 décembre 2010

Fixing modification dates on photos using the creation date in the photo file (set by the camera)

I have a large collection of photos, several dozens of Gb and I accidentally copied them without preserving the orginal creation dates.

Every photo you take has a date set in the file by the camera in what is called exif metadata. Some cameras can also record the exact coordinates where the photo was taken ... anyway, I needed to fix those dates. I also like to keep the files in a year/month/day folder structure.

So, here is my script:

#!/bin/sh

DATE=`exiftool "$1" | grep 'Create Date' | sed -e 's/.*: //;s/://g;s/..$//;s/ //g'`

DEST=`echo $DATE | sed 's@^\(....\)\(..\)\(..\).*@/media/shared/Pictures/\1/\2/\3/@'`
touch -t $DATE "$1"

if [ -d "$DEST" ]; then
cp -an "$1" "$DEST"
else
mkdir -p "$DEST"
cp -an "$1" "$DEST"
fi

vendredi 10 décembre 2010

Windows XP SP3 Installation fiasco

So, here I was again, creating a new vm for Windows XP. I have a Windows XP SP3 iso from work I use. This is my work computer and we have a volume license. Anyway, legal all the way.

So I insert the cd, it installs fine and the first thing I do is start Windows Update. It needs to install 85 updates totaling 107 Mb and claims it will take 51 minutes with my connection ... it took about 15 minutes including installation ... although only 82 were installed, the other three were skipped (I guess they needed a reboot).

Anyway, on the reboot, it keeps restarting as soon as it gets to the blue background. Not the BSOD background, the somewhat lighter background before the Welcome page loads.

Safe mode works without an issue, so I somehow suspect graphics driver issues, remember this is a vm - and I enabled 3d. So I try VGA mode, and there I briefly see a bsod. So I disable the automatic restart on error, and the fucker does not allow me to switch to another mode, like VGA.

So, instead of seeing the blue background I see a higher resolution black background with an hour glass. Go figure ... anyway, go back to the startup options and select "Last Known Good", which I did not feel too comfortable with, since I just installed a whack of updates and this is still the first restart after that massive install .... but I get to the desktop, youpie!!!

But the fun is not over, it wants to send an error report, which is fine by me ... and the error report is corrupt!!!!

So, I know it wants to install the other three updates and I shutdown Windows (Start -> Shutdown)... and it installs the updates. After that I get back into the same loop ... I select Last Known Good and it works ... bloody hell, how do people put up with this I do not know ... And this Last Known Good does not sound right to me ... updates have certainly changed the services and drivers ... ohh my ... I am unsure what to do now. I probably should not have installed the vm tools before the updates? Go figure.

I guess I am condemned to select Last Known Good after every software update .... fsck!

Before you ask, I need Windows XP for work ... sometimes ... and my 5 year old vm was getting issues with disk space, so I decided to install a new one from scratch.

I like the irony of "Last Known Good" ... that should uninstall Windows ....


I go back to windows update, and it wants t install another 7 updates, which I install ... after that, I get back into the looping booting fiasco ... Last Known Good ....

mardi 28 septembre 2010

chroot java on linux x86_64

I had to chroot java on linux 86_64. I have found many blogs, but all I read missed some of the steps:


export JAIL=/home/jail
#Make all dirs 
mkdir -p $JAIL/dev $JAIL/lib $JAIL/etc $JAIL/opt/ $JAIL/proc
#copy hosts file
cp /etc/hosts $JAIL/etc/hosts
#copy libs required by java (1.6.20) 
cp /lib/ld-linux-x86-64.so.2 /lib/libc.so.6 /lib/libdl.so.2 /lib/libgcc_s.so.1 /lib/libm.so.6 /lib/libnsl.so.1 /lib/libpthread.so.0 /lib/librt.so.1 $JAIL/lib/ 
#needed by my Java app
cp /usr/lib/libstdc++.so.5 $JAIL/lib/ 
#Although you link this to your "real" /lib, in your jail, it will be the lib directory in your jail.
ln -s /lib $JAIL/lib64
#Mount proc 
sudo mount -t proc /proc $JAIL/proc
#create devices 
sudo mknod -m 666 $JAIL/dev/random c 1 8 
sudo mknod -m 666 $JAIL/dev/null c 1 3 

sudo mknod -m 666 $JAIL/dev/zero c 1 5

Now just copy/install java, then start it with:
sudo chroot $JAIL /opt/java/bin/java -version
Assuming that /opt/java is where you installed java.
If java does not launch, make sure with ldd, that all so files are in the $JAIL/lib dir.
I got
chroot: failed to run command `/opt/java/bin/java': No such file or directory
Because the lib64 directory was not linked to /lib.


I see quite a few people like this blog post, please leave a comment ... thanks.