How to create a csv file in javascript and get the “save as”-dialog

June 17, 2010

Long headline! Anyway, this is a problem I’ve encountered more than once. When exporting data from a webpage to a .csv file I usaually create it on the server side using a servlet.

However, If the data is already stored in the browser, you don’t want an extra server request (especially if you’ve manipulated the data on the client).

The first lead came from this post. It explains how to open a separate window with csv content. But how to get the “Save As” dialog? After some searching I found tips about using “data URL” and finally found the solution.

The essentials of my test code:

function loadLinkButton(){
  var btn = document.getElementById("linkButton");
  var axx = document.getElementById("ax");
  // I used this online encoder to create the data url.
  // axx.href = 'data:text/csv;base64,MTsyOzQ=';  // This was my first test, not having the encoder. 
  axx.href = 'data:text/csv;base64,'+Base64.encode("3;2;1");} // I used the javascript encoder from this page.
}

<body> 
<a id="ax" href="">test</a>
<button id="linkButton" onclick="loadLinkButton();">asdf</button>
</body>

So basically, pressing the “asdf” button creates the data URL and then the link “test” opens the csv (with save-as dialog). Havn’t tried it in IE, but I’ve read that it’s not going to work.

Questions? Feedback? Feel free to comment!

silent computer – tyst stationär dator

June 8, 2010

For quite some time I have been searching for a new computer. I wanted it to have decent performance and be quiet but none of the stores I checked had any sound-preferences whatsoever. I didn’t want to build it myself so I went to a local store in Lund called itel and had them build me one. We chose the components together, after two days it was ready and the pricing was good. This is what I got:

  • Fractal Design Define R2 Black Pearl
  • Scythe 450W power supply
  • Asus P7H55, S-1156 DDR3 GbLAN HD-Audio
  • Intel Quad Core i5 2,66 GHz, S1156, 8Mb 14250
  • Noctua NH U12P SE1366 (CPU cooler)
  • Corsair Dominator DHX+ DDR3 1333MHz 4Gb(2*2Gb) XM
  • Seagate Barracuda 500Gb 16MB Cache S-ATA2
  • Asus Radeon HD 4350 512Mb Silent

Maybe all computers are fairly silent by now but I am really surprised by how quiet it is! I can really recommend this store! (Now I feel silly writing in English, clearly addressing Swedish people). Anyway, these are quiet components and they work good together (had the computer almost a week now, running Ubuntu Studio).

For a perfectly silent HTPC however, I can recommend the fit-PC2. It’s more like an industrial computers I work with. Slow, reliable, fanless, energy saving.. and it plays HD! I run ubuntu 8.04, but I hope for 10.40 support soon.

About EMU 0404 USB support for Ubuntu

June 7, 2010

For a few weeks I was searching for evidence that this particular sound card was supported in Ubuntu Studio 10.04. I found some evidence and clues, like this extensive thread and the ALSA page with beta drivers. I was still suspicious though, but since we (me and my boyfriend, he’s using the sound card for recording) really wanted to avoid windows, we decided to try.

So we downloaded Ubutu Studio 10.04 and installed it with all the suggested software bundles. We did the modprobing for drivers:

modprobe snd-emu10k1 ; modprobe snd-pcm-oss ; modprobe snd-mixer-oss ; modprobe snd-seq-oss

And then we started Audacity, chose EMU 0404 as playback & recording device in the preferences and we were up and running! Much faster than we would have been with windows. Just so awesome!! I’m not even sure I needed the modprobing. The quality was ok and recording and playback worked on both input channels (connected to a digital piano).

Enter key hangs

June 3, 2010

This is driving me crazy so I need to write it off!

A few days ago, a new problem started to interfere with my daily work. Every now and then the Enter- key keeps pressing itself (hangs) for no apparent reason. And  it stops when I press F2!

Of course I assumed it was a hardware problem, since several people around me had that problem with laptop keyboards (and solved it by replacing them). I’ve never been violent to my keyboard and don’t remember ever spilling liquid on it (I know, it’s a miracle since most of the stuff on my desk have been swimming in coffee at least once).

Anyway, I started looking into Linux forums and disabled my keyboard according to this post. I connected a usb-keyboard and started working again.

15 minutes later the same thing happened again! By pressing F2 on the usb-keyboard it stopped! So maybe it’s a software problem in Ubuntu?

I’ll get back when I’ve upgraded my OS. It’s time anyway, I’m running 9.04 and want to try 10.04 asap. Unfortunately I need a decent time span with low workload. If VMware (Server 2.0) fails me I can’t work.

Btw, I’m using a Dell Precision M90 anybody seen a similar problem with this laptop?

[update]

It seems like the problem is caused by Terminal Server Client. I stopped using it for VNC (connected to my virtual machine) and havn’t had the problem since.

Yet another missing irl feature

February 22, 2009

So, I’ve been through the ctrl-z feature and the stop, rewind and analyze feature. What else is missing in my life? A robot to take care of all house hold work? An index to the CD collection? To be able to search for quotes in all my books? Yes, all of that of course, but my whining today will be about the saving ability. Why can’t I record my memory and save it on a USB-stick for later? How come it’s so hard for me to put the cool dream I had out on youtube? There is so much media I’m just missing by forgetting!!

Dreams, memories, books that are like movies in my head. Lately, I’ve been reading a lot of Terry Pratchett novels. Each one of them makes such a great hollowood-production movie in my head. It makes me wanna change career into a film maker!

But nooo, I can’t even get a screenshot out of my head. That totally sucks.

About useful commands

February 22, 2009

A very useful command on linux (ubuntu in my case) is the dd command. All it requires is a little (or a lot of) courage (at least I’ve always been scared of memory management). For instance, I copied a CF-card to a bigger one and it worked like a charm! XP-embedded booted up fine and and the extra memory just showed up as unallocated. That is so cool!!

Then I stumbled upon this competition about the best UNIX commands ever: http://www.commandlinefu.com/commands/browse. For me, sudo !! (execute the last command as root) is definately a winner. I don’t remember the last time I remembered to write sudo.

Sometimes it feels like a waste having ubuntu as OS but always using vmware (server 2.0) and do all the actual work in xp. On the up-side though, when xp crashes, I can always use my ubuntu to write and surf until it’s rebooted.

I never remember the commands I want to use, and I never use the commands I have on my cheating-notes. Maybe if I wasn’t growing up with windows (3.11 was the first I remember clearly) unix would be more like a part of me. As it is, I didn’t get in touch with command based computer use until high school.

Addresses and stuff!

February 19, 2009

I wanted to write a short guide to using pointers and stuff, since I always forget that sort of thing. At least the three first times I “started doing it again”. Like, you go object-oriented for a year and then you’re suddenly thrown back into C and IEC61131-3 (languages for plc-programming (programmable logic controllers, for controlling machines within industrual automation)).

Anyway, it goes faster and faster now.. But I wanted a pedagogic picture also, with arrows and stuff.. maybe I’ll add it later.

C is first:

&myFirstVariable – “address of “, is an unsigned long that is the memory address to the place where myFirstVariable is stored.

*pMyFirstVariable – “on this address”, is whatever pMyFirstVariable is an address to. So pMyFirstVariable is an unsigned long (p is “pointer to”).

Once you mastered these to operators, you can do practically anything you want. And you know about computer memory. Some time maybe I can think of some really confusing examples to go with the above standalone useless information!

Just woke up…

February 15, 2009

So, I’m back from a loong winter hibernation. Christmas vacation, work for a couple of weeks and then another week skiing. Now it’s work for several months. Hopefully I will learn an awful lot of new things and develop a habit of waking up early in the morning, happy, and not curse my way up from bed!

However, it was fairly easy to get back to work. I tried hard not to think about work on my holiday, but the moment I opened the DE it all came back to me. Amazing, isn’t it? It’s like it never left.

It’s not a bug, it’s a feature..

December 16, 2008

Ever heard that line before? I use it a lot. Like all the time. About everything from kitchen utensils to strange software behaviours..

Anyway, the other thing I wanted to write about is the magical things about every development environment (and programs in general) that seems to exist everywhere. At first I thought it was just me that needed to find those workarounds, tweaks and weird irrational configurations, or that it was just this or that environment. Now I’ve seen a lot of DE:s (development environments) and I know it’s not just me. It can go something like this:

– This button doesn’t work!

– No, you have to focus that other window before you click.

– I can’t write into this parameter field!

– No, first you have to open Window->Configurations, go to the tab called “Parameter fields” and check the box called “Please”

– But it worked half an hour ago and I didn’t change anything!

– Yeah, well.. it does that sometimes..

..this is where I pick up my notebook and start writing the sequence down.. in 2-5 years I’m gonna need it again. Anyway, a little while later it develops to:

– And remember, when you update that file, on that server, you have to open this settings window and change this totally random value into something else. Then you have to minimize and maximize the window twice..

I can’t really explain it well, I hope to present a good example soon.

All applications have bugs. Not all av them have features : )

Another feature missing irl..

December 2, 2008

Conversations are sometimes boring because people don’t listen to each other. They (ok, we) tend to care more about our own next statement than to actually understand the other person’s arguments. Maybe it’s because it’s so hard to listen and think simultaneously. Or listen and remember..

Lately I’ve been missing the stop-and-rewind feature of conversations. Too often I either forget what I was going to say, or I forget what the other person just said. I get brilliant ideas and instantly forget them because I try to understand what the other person was saying.

For the first 23 years of my life this was not at all a problem. I never thought of this as a possibility and I got along just fine (well, ehm..). Now I suddenly feel like it’s a functionality that ought to exist.

Maybe I should not spend so much time with computers.