Pages

Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, April 14, 2015

Have yaourt save compiled packages to /var/cache/pacman/pkg

   The title of this post might not mean much to most of you, but for those few lucky enough to use Arch Linux on a daily basis, this could be of use to you. By default, yaourt does not keep the package files it produces, it deletes them after installation. Since the AUR deals mostly with unsupported packages, making it imperative that you be able to roll back to older packages, this is not useful default behaviour.
   To have yaourt export your compiled packages to the standard location, /var/cache/pacman/pkg/, edit /etc/yaourtrc and change the line
#EXPORT=0
to
EXPORT=2
That is all. Have a nice day!

Friday, August 24, 2012

Fortran, C++ and qmake

Qt Creator Logo
   Call me a noob, but I love using Qt Creator even when I'm not programming a GUI. The UI greatly facilitates code writing: the syntax highlighting is very customizable, it shows you the methods of a class when you use the . or -> operators, it makes the build process faster and easier to configure (sometimes), etc.

   Now, I didn't want to make this a post about Qt Creator, so here comes the meat. I've been trying to add Fortran code to my numerical library, something I think is pretty common in scientific circles. Of course, that's been done before, but my research has yielded one link for Fortran and Qt. 

   I'm using D.E. Amos' Fortran code to compute Bessel and Hankel functions of complex arguments and all (real) orders (we use identities to convert the negative order computations to positive order ones). Complex orders are not supported. Work by Temme could be used for this, but maybe a later time. 

   I have two Fortran source files that must be incorporated into a C++ numerical library. Using qmake, this is child's play. 

  • First, add the Fortran source files as sources in your .pro file. 
  • SOURCES += machine.for zbesh.for

    Those are the names of the Fortran sources files used by Amos.  
  • Second, create a C++ header file that links to the Fortran subroutines inside the source files. 

    A couple things about this linkage. Notice that I appended a _ to the Fortran subroutine names. The extern keyword tells the compiler that a separately compiled object will be used. By default, g++ will append _ to Fortran subroutines when creating an object file. This means that if you change this compiler setting, be sure to remember to change your function declarations in your C++ header file.
    Also, the functions take pointers to variables. In Fortran, all functions take their arguments by reference. It is thus necessary to use pointers when using Fortran subroutines in C++. 
  • You're done! You can now use your Fortran subroutines in your C++ program! Just don't forget to add the
    -lgfortran
    when compiling either the program you are writing or a program that uses a library that uses Fortran subroutines.

Wow, that last sentence was terrible.

   Anyway, have fun programming!

Monday, July 23, 2012

Issues with Linux and HP printers

   Since I have access to a new printer, I (of course) had issues with it. As I tried different kinds of connection with CUPS (ipp://, ipps://, http://, socket://) and different drivers (hpijs, hpcups), the page would sometimes render blank lines as black strips of ink or print with some weird margins. 

   But, I have found the solution! 

   It turns out that the hplip package comes with a command called hp-setup, which can be used to configure your network printer. The tool setup the printer with the hpijs driver, but with an hp:// connection. The hp:// connection string I could not have guessed. It seems to be a combination of the printer model and other things, but it isn't explicited anywhere (that I know of). 

   Anyhow, now everything works fine. I hope this short post helps you. 

Thursday, March 29, 2012

Printer margins issues with Samsung CLP-310N

   Although this is a rather specific issue concerning the Samsung CLP-310N, I thought it could be a good idea to share the solution to a longstanding problem I was having. 

   For some reason, when I upgraded CUPS some time ago (I don't recall specifically when this began), printing PDFs and other documents from my Arch Linux box was difficult. The documents were not properly centered on the page (the top margin was way too low). So, I googled for something interesting. I came up with someone saying that the SPL-C driver seemed to be the cause and that switching to foo2qpdl solved the problem.

   I immediately tried to change my printer's driver to this one with CUPS (on my machine, I just go to http://localhost:631), but the driver was not in the list, even though the foo2qpdl XML file comes with foomatic-db, which I had installed a while back. 

   Okay, the quick solution is:
yaourt -S foo2zjs
then you will be able to select the Foomatic/foo2qpdl from the drop-down menu in CUPS. This is an AUR package, which seems to be well maintained. 

Anyway, hope this helps. Certainly helped me! 

Thursday, August 18, 2011

Return user-defined sets in PostgreSQL


   Returning sets of data with PL/pgSQL functions can be somewhat tricky. The documentation has a line saying how to do it somewhere, but the beginner SQL user (like the author of this post) might be confused at the impressive amount of information given by this document.

   This post is thus intended as an example that firsts creates a small database and a function that manipulates data. Let's do this!

First, let's create two tables with some data in them.
CREATE TABLE foo (
"IndexFoo" integer DEFAULT nextval('"sq_IndexFoo"'::regclass) NOT NULL,
"FOO_IndexCol1" integer NOT NULL,
"FOO_Timestamp" timestamp without time zone DEFAULT now()
);

And a table that is pointed to by foo:
CREATE TABLE foo_info (
"IndexInfoFoo" integer DEFAULT nextval('"sq_IndexFooInfo"'::regclass) NOT NULL,
"INF_Answer" integer DEFAULT 42
); 
Now say we want to return rows from both tables. Say we want the answer, given in foo_info and the timestamp, given in foo. We just have to create a function that does just
CREATE OR REPLACE FUNCTION "f_whatIsTheAnswer"(OUT answer integer, OUT "time" timestamp without time zone)

RETURNS SETOF record AS $$

BEGIN


RETURN QUERY SELECT fi."INF_Answer", f."FOO_Timestamp"
FROM foo f

JOIN "foo_info" fi ON f."FOO_IndexCol1" = fi."IndexInfoFoo";
END;
$$ LANGUAGE plpgsql;
Notice how the returned columns are defined in the function's arguments. This defines the column set returned by the function. If left out, PostgreSQL will complain that the record type has not been assigned any return type.

Because we use PL/pgSQL, the RETURN QUERY statement is used. Since this is a simple query with no complex data manipulation, it could have been a simple SQL request. The RETURN QUERY would have been unnecessary.

Try it yourself! Here's the database dump.

Wednesday, August 10, 2011

Removing files from working directory not under version control

   I've been using SVN since the beginning of summer and I'm liking it so far. However, I stumbled across a little problem this week.

    I use SVN to write a LaTeX document which spans multiple files. Being textual, the contents of the .tex files are diff-able and all the features of SVN can be used. However, when I compile the document to have a nice PDF file, a plethora of files are simultaneously created. I don't want to put these files under version control. I hear you say: "Well, do not add them to your repository, then!". Fair enough, here's the result of a svn st:
Cluttered up svn st. I hate cluttered 
I hate cluttered things! Now, the easy solution is to remove all files you do want to put under version control, marked by a '?'. You always the manual way, i.e. rm file1 file2 file3 ... fileX but that's cumbersome. Let's use some of our bash knowledge to solve this problem. 

WARNING. The following command will remove all files marked with a '?'. Be careful with it!

rm `svn st | grep ?`

Simple enough, huh? 

Tuesday, November 2, 2010

Perhaps there is a stale lock file?

  I recently ran into a seemingly severe problem with my computer. Since approximately 2003, I've been using Linux as my primary desktop. I have enjoyed the learning that inevitably came out of it, and have also joined the great community of Linux users. 

  Anyhow, when I booted my computer yesterday, the boot screen said that it couldn't not mount the local file systems, saying something along these lines:

Cannot link ... to /etc/mtab
Perhaps there is a stale lock file?

(I don't remember the exact error statement.) So, I did not have access to my /boot, /home, /var and other partitions on my hard drive. No X either. In short, my computer was unusable, as I did not have the necesarry files.
 I immediatly Googled the issue[*] and eventually found a solution:

sudo rm /etc/mtab~

This seemed to correct the issue without any consequence to the rest of the system. Of course, don't delete the /etc/mtab file proper, but the temporary file marked by the tilde. 

 I later found out that this problem originated from Transmission BitTorrent Client. An option in the software allows it to keep your computer to go to sleep, probably creating that /etc/mtab~ file in the process. I did some testing and it seems that it is well behaved about it, i.e. if you let it close properly, it will remove the lock file and allow your computer to sleep or shut down. 

Anyhow, in the hope that that helps someone. Oh, by the way, I'm using Arch Linux 64-bit. 


[*] On my iPod Touch because I still do not know how to connect to a WPA-protected access point with the command line.