unix

Fastest way to get value of pi

Solutions welcome in any language. :-) I'm looking for the fastest way to obtain the value of pi, as a personal challenge. More specifically I'm using ways that don't involve using #defined constants like M_PI, or hard-coding the number in. The program below tests the various ways I know of. The inline assembly version is, in theory, th...

Is gettimeofday() guaranteed to be of microsecond resolution?

So I find myself porting a game that was originally written for the Win32 API to Linux (well, porting the OS X port of the Win32 port to Linux), and have implemented QueryPerformanceCounter by giving the uSeconds since the process start up: BOOL QueryPerformanceCounter(LARGE_INTEGER* performanceCount) { gettimeofday(&currentTime...

GTK implementation of MessageBox

I have been trying to implement Win32's MessageBox using GTK. The app using SDL/OpenGL, so this isn't a GTK app. I handle the initialisation (gtk_init) sort of stuff inside the MessageBox function as follows: int MessageBox(HWND hwnd, const char* text, const char* caption, UINT type){ GtkWidget *window = NULL; GtkWidget *dialog ...

Getting root permissions on a file inside of vi?

Often while editing config files, I'll open one with vi and then when I go to save it realize that I didn't type sudo vi filename Is there any way to give vi sudo privileges to save the file? I seem to recall seeing something about this while looking up some stuff about vi a while ago, but now I can't find it....

Process size on UNIX

What is the correct way to get the process size on Solaris, HP-UX and AIX? Should we use top or ps -o vsz or something else?...

How do I use (n)curses in Ruby?

I'd like to create a progress bar to indicate the status of an a batch job in Ruby. I've read some tutorials / libraries on using ncurses, none of which were particularly helpful in explaining how create an "animated" progress bar in the terminal or using curses with Ruby. I'm already aware of using a separate thread to monitor the progr...

What should a longtime Windows user know when starting to use Linux?

We've finally moved our websites to a decent host, and for the first time we have Shell Access. I know very little about using Linux, I can navigate through the file system, read files with Vim and I'm aware of the man command, and I have been able to work out solutions to problems as they show up (eventually), but I know I'm unaware of...

Choosing a static code analysis tool

I'm working on a project where I'm coding in C in a UNIX environment. I've been using the lint tool to check my source code. Lint has been around a long time (since 1979), can anyone suggest a more recent code analysis tool I could use ? Preferably a tool that is free....

How do I configure and communicate with a serial port?

I need to send and receive data over serial connections (RS-232 and RS-422). How do I set up and communicate with such a connection? How do I figure out what the configuration settings (e.g. baud rate) should be and how do I set them? In particular I am looking to do this in Java, C/C++, or one of the major Unix shells but I also have...

Windows Equivalent of 'nice'

Is there a Windows equivalent of the Unix command, nice? I'm specifically looking for something I can use at the command line, and not the "Set Priority" menu from the task manager. My attempts at finding this on Google have been thwarted by those who can't come up with better adjectives. ...

Using Xming X Window Server over a VPN

I have the Xming X Window Server installed on a laptop running Windows XP to connect to some UNIX development servers. It works fine when I connect directly to the company network in the office. However, it does not work when I connect to the network remotely over a VPN. When I start Xming when connected remotely none of my terminal w...

Date arithmetic in Unix shell scripts

I need to do date arithmetic in Unix shell scripts that I use to control the execution of third party programs. I'm using a function to increment a day and another to decrement: IncrementaDia(){echo $1 | awk 'BEGIN { diasDelMes[1] = 31 diasDelMes[2] = 28 diasDelMes[3] = 31 diasDelMes[4] = 30 diasDel...

Faster way to find duplicates conditioned by time

In a machine with AIX without PERL I need to filter records that will be considered duplicated if they have the same id and if they were registered between a period of four hours. I implemented this filter using AWK and work pretty well but I need a solution much faster: # Generar lista de Duplicados awk 'BEGIN { FS="," } /OK/ { ...

How can I encode xml files to xfdl (base64-gzip)?

Before reading anything else, please take time to read the original thread. A quick simple overview: A .xfdl file is a is a gzipped .xml file which has then been encoded in base64. I wish to de-encode the .xfdl into xml which I can then modify and then re-encode back into a .xfdl file. xfdl > xml.gz > xml > xml.gz > xfdl I have been...

How to avoid redefining VERSION, PACKAGE, etc.

I haven't seen any questions relating to GNU autoconf/automake builds, but I'm hoping at least some of you out there are familiar with it. Here goes: I have a project (I'll call it myproject) that includes another project (vendor). The vendor project is a standalone project maintained by someone else. Including a project like this is...

What is PHP Safe Mode GID?

According to the PHP Safe Mode Docs on safe_mode_gid: By default, Safe Mode does a UID compare check when opening files. If you want to relax this to a GID compare, then turn on safe_mode_gid. Whether to use UID (FALSE) or GID (TRUE) checking upon file access. To a PHP script running on a web server, what is the difference between ...

Allow user to set up an SSH tunnel, but nothing else

I'd like to allow a user to set up an SSH tunnel to a particular machine on a particular port (say, 5000), but I don't want to restrict this user as much as possible. (Authentication will be with public/private keypair). I know I need to edit the relevant ~/.ssh/authorized_keys file, but I'm not sure exactly what content to put in there...

What's in your .procmailrc

Are there any handy general items you put in your .procmailrc file? ...

How do I generate ASCII codes 2 and 3 in a Bash command line?

If I press ctrl-b that ought to give me ASCII code 2, but ctrl-c is going to be interpreted as a Break. So I figure I've got to redirect a file in. How do I get these characters into a file? ...

Using Visual Studio to develop for C++ for Unix

Does anyone have battle stories to share trying to use Visual Studio to develop applications for Unix? And I'm not talking using .NET with a Mono or Wine virtual platform running beneath. Our company has about 20 developers all running Windows XP/Vista and developing primarily for Linux & Solaris. Until recently we all logged into a m...