Friday, November 29, 2013

Setting textarea height adjusted to the contents

I have a page I would like to print out having <textarea> printed as well.
I would like to have this <textarea> having maximum width, and minimum height, so where there is no data it is only one line, but in case the data spans to, let's say, 10 rows, it expands <textarea> to 10 rows, and no scrollbar appears.

This is what I have found that works for me:

    $(".tarows").each(function(){
        $(this).height(0) ;
        $(this).height($(this).prop("scrollHeight") + "px") ;
     }) ;

- or similar using pure javascript:

    element.style.height=0;
    element.style.height=element.scrollHeight+'px';


This way, I can define my textarea (using class tarows) without cols or rows, and say in css to make it 100% width:

.tarows {
    width: 100%; 
}

<textarea class="tarows">multiline text which will be shown on the whole width of the page, and as many rows as needed.</textarea>


Wednesday, June 5, 2013

logrotate

logrotate -f /etc/logrotate.conf
Nothing more to say.

Wednesday, January 4, 2012

mediawiki: There seems to be a problem with your login session; this action has been canceled as a precaution against session hijacking. Go back to the previous page, reload that page and then try again

If you see:

There seems to be a problem with your login session; this action has been canceled as a precaution against session hijacking. Go back to the previous page, reload that page and then try again

Then the problem is with your file system.

Check the status of the file system that holds your /tmp directory.

I bet it is full.

Clean the /tmp directory or delete unneeded files/directories in the file system and you will be good to go.

Saturday, November 26, 2011

Life is Worth Living, CD 11 order of mp3

Something out of the ordinary of this blog...
The "Life is Worth Living, CD 11" has incorrect mp3 order (sequence.)
Just in case someone decided to look for proper here is the correct one:

  1. Life is worth livingk (0).mp3
  2. Life is worth livingk (2).mp3
  3. Life is worth livingk (b14).mp3
  4. Life is worth livingk (3).mp3
  5. Life is worth livingk (b12).mp3
  6. Life is worth livingk (b13).mp3
  7. Life is worth livingk (4).mp3
  8. Life is worth livingk (5).mp3
  9. Life is worth livingk (6).mp3
  10. Life is worth livingk (7).mp3
  11. Life is worth livingk (1).mp3
  12. Life is worth livingk (8).mp3
  13. Life is worth livingk (9).mp3
  14. Life is worth livingk (b10).mp3
  15. Life is worth livingk (b11).mp3

Friday, September 16, 2011

GDB - Accessing deque and queue


In O1 mode some of the functions are optimized out and it is impossible to call them.
In case of deque and queue (which is build over deque) it is a bummer for the size() method is calculated.

After finding some examples on the Internet we found nothing usable (I guess because our gcc was using different deque memory structure.)

So we created a new version.

pdequeue_info variable
- Shows size, first, and last element

pdequeue variable [firstidx [lastidx]]
- Shows contents or a range.

define pdequeue_info
 set $var=($arg0)
 set $sizeof=sizeof( **$var._M_impl._M_start._M_node )
 set $size=$sizeof < 512 ? ( 512 / $sizeof ) : 1
 set $i=0
 while $i < $var._M_impl._M_map_size && $var._M_impl._M_map[ $i ] == 0
  set $i++
 end
 set $rv = 0
 while $i < $var._M_impl._M_map_size && $var._M_impl._M_map[ $i ] != $var._M_impl._M_finish._M_first
  set $rv += $size
  set $i++
 end
 if $var._M_impl._M_map[ $i ] != 0
  set $rv += $var._M_impl._M_finish._M_cur - $var._M_impl._M_finish._M_first
 end
 printf "size  : "
 p $rv
 if $rv > 0
  printf "first : "
  p *$var._M_impl._M_start._M_cur
  if $rv > 1
   printf "last  : "
   p *( $var._M_impl._M_finish._M_cur - 1 )
  end
 end
end

define __pdeque_show_group
 set $cur=($arg0)
 set $size=($arg1)
 set $f=($arg2)
 set $l=($arg3)
 set $j=0
 while $j < $size && $n <= $l
  if $n >= $f
    printf "[%i] : ", $n
    p *$cur
  end
  set $cur++
  set $j++
  set $n++
 end
end
define pdequeue
 set $var=($arg0)
 set $f=-1
 set $l=9999999999
 if $argc == 2
  set $f=($arg1)
  set $l=$f
 end
 if $argc == 3
  set $f=($arg1)
  set $l=($arg2)
 end
 set $sizeof=sizeof( **$var._M_impl._M_start._M_node )
 set $size=$sizeof < 512 ? ( 512 / $sizeof ) : 1
 set $i=0
 while $i < $var._M_impl._M_map_size && $var._M_impl._M_map[ $i ] == 0
  set $i++
 end
 set $n=0
 while $i < $var._M_impl._M_map_size && $var._M_impl._M_map[ $i ] != $var._M_impl._M_finish._M_first && $n <= $l
  __pdeque_show_group $var._M_impl._M_map[$i] $size $f $l
  set $i++
 end
 if $var._M_impl._M_map[ $i ] != 0 && $n <= $l
  __pdeque_show_group $var._M_impl._M_map[$i] $var._M_impl._M_finish._M_cur-$var._M_impl._M_finish._M_first $f $l
 end
end

Wednesday, June 15, 2011

valgrind - dowloading, building and installing

First, I need to post all the links that will allow you to get to the creators information:

* WWW: http://valgrind.org
* Manual: http://valgrind.org/docs/manual/valgrind_manual.pdf
* Source: http://valgrind.org/downloads
* Building Instruction: http://valgrind.org/docs/manual/dist.readme.html

Building
* Download the source and put into your home account. Let's assume it is the valgrind-3.6.1 version.
Run these commands:

vver=valgrind-3.6.1
tar xf $vver.tar.bz2
cd $vver
ulimit -u 100 # ./configure has a bug ...
./configure --prefix=$HOME/valgrind # You need that in order to run make install without root privileges
make
make install
cd $HOME/valgrind/bin
./valgrind ls -l # see if it bombs out. If it does not you are good to go


Now, what you have is a $HOME/valgrind directory. If this is place where you want to use it then you are ready. The only one thing you need to do is set your path: export PATH=$HOME/valgrind/bin:$PATH

Ok... and what about if you need this valgrind now on a machine that does not have gcc?
The only thing you need to do is to pack the whole $HOME/valgrind directory, and copy it over to the destination machine.
The only caveat is that it has to be put into exactly the same directory as it was built in or else you will see this nice message:
valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory

Solution - ln -s $HOME/valgrind path-to-valgrind-on-the-build-machine
Example: ln -s $HOME/valgrind /home/myhome/valgrind

Sunday, May 16, 2010

Internal Server Error when password protecting directory

Do you see something like that:???

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@blahblah and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


There is a very simple explanation but it took me lots of time to discover the reason. Well, I'm not as good as I would like to be ;)

The reason -> FILE PERMISSION!!!

All directories have to have +xr access for the web server. You may have to make o+xr them.
Also the .htpasswd and .htaccess have to be accessible for the web browser.

Here is my .htaccess in the directory I want to have password protected:

AuthUserFile /home/myhome/.htpasswds/.htpasswd
AuthName "Login Area"
AuthType Basic
require valid-user


Since the web server is 'hosted', so the best thing to do is to run the phpinfo() on the web browser (create p.php file and put <?php phpinfo(); ?> in it) and look for DOCUMENT_ROOT to see where really are your web files located.
Make sure that all the directories leading to .htpasswd and .htaccess are having proper 'read/execute' attributes (644)

Tuesday, May 11, 2010

Google Calendar compatible Catholic Calendar in US

http://www.google.com/calendar/embed?src=vfc9s2tq7ugm3qutnm823pu9ec@group.calendar.google.com&ctz=America/New_York

Thursday, January 14, 2010

ls using boost

Want to use boost and get list of files matching a mask. The same list you would obtain running ls in the command prompt?

The idea is to have something like this:


BOOST_FOREACH( const std::string& fname, ls( "./*.cpp" ))
std::cout << fname << std::endl ;


So here is the solution. One function and one helper function (to_regex_copy()):


std::string to_regex_copy( std::string mask )
{
std::string rv = boost::regex_replace( boost::regex_replace( boost::regex_replace( mask, boost::regex( "\\." ), "\\\\." ), boost::regex( "\\?" ), "\\." ), boost::regex( "\\*" ), "\\.*" ) ;
return rv ;
}

std::vector< std::string > ls( const char* pcszMask )
{
namespace fs = boost::filesystem ;
boost::filesystem::path path ;
boost::regex mask ;
if ( fs::is_directory( pcszMask ))
{
path = pcszMask ;
mask = ".*" ;
}
else
{
path = fs::path( pcszMask ).remove_filename() ;
mask = to_regex_copy( fs::path( pcszMask ).filename()) ;
}

std::vector< std::string > rv ;
try
{
for ( fs::directory_iterator p(path), e; p!=e; ++p)
{
if ( boost::regex_match( p->filename(), mask ))
rv.push_back( p->filename()) ;
}
}
catch( ... )
{
}

return rv ;
}

Tuesday, January 12, 2010

Profiling shared library on Linux using sprof

It's not as easy as one would/should expect. (Read here about valgrind if you don't want to use sprof.)

First - FORGET ABOUT gprof. gprof is used for the applications but will NOT WORK for shared libraries. Sorry about that. I learned about it the hard way. What you need to use is sprof.

Second - sprof may make you bite your fingers if your glibc library is not up-to-date. It will be displaying the nasty message: "sprof: failed to load shared object"
If this is what you see then you HAVE TO update your glibc. Read about the bug: here. It may not be as simple to upgrade as well... If I have time I will write how to do it through the .iso file (if you have one.)

Third - Yes, as it is not enough, there is an other surprize! The -pg option works well for gprof, but screws up things for sprof! You need to remove this option in order to get proper results from the shared libraries. Otherwise you will get only zeroes as the execution time for the functions.

So, at the end, what to do?

Assuming you have the patch installed or you have glibc-2.5-34 or newer version installed do as follows (the best, in my opinion, way, assuming you have write access to the current directory.)

1) Compile your shared library (libmylib.so) in debug (-g) mode. No -pg.
2) export LD_PROFILE_OUTPUT=`pwd`
3) export LD_PROFILE=libmylib.so
4) rm -f $LD_PROFILE.profile
4) execute your program that loads libmylib.so
5) sprof PATH-TO-LIB/$LD_PROFILE $LD_PROFILE.profile -p >log
6) See the log.

I hope it will help you.

Friday, October 9, 2009

ssh, scp password-less connection

Below is possibly the simplest way it can be accomplished.
Simply enter username@ip-address, when asked after running this one-liner below:
printf "enter username@ip-address: " ; read UIP ; ssh $UIP "mkdir .ssh 2>/dev/null ; echo $(cat $HOME/.ssh/id_rsa.pub) >>.ssh/authorized_keys ; chmod 700 .ssh ; chmod 600 .ssh/authorized_keys" ; echo "hostname=$(ssh $UIP hostname)"
You should be done.
If everything was okay you should see the hostname command result run on the target.
From this moment, you can run your commands on the remote host by executing like this:
ssh username@ip-address "your command"
or copying files like that:
scp myfile username@ip-address:

Thursday, September 25, 2008

How do I find the name of the current shell that I am working in

There is a command that will work on all platforms I tested (HP-UX, SunOS, Linux, MacOS) and shells (sh,ksh,bash,csh,zsh)

ps -p $$ | grep $$ | awk '{ print $NF }'

Be aware that the shell name can be bash or -bash

Tuesday, June 24, 2008

At least one secondary cursor must be specified to DB->join error 22

Never found this problem on the Internet? Does it mean nobody except me run into it?

I have tested BerkeleyDB BTree 4.7.25 (from Oracle now) and when running a simple test described in their doc I got the following when opening (creating) a database:

At least one secondary cursor must be specified to DB->join error 22

After hours of searching here is what I found - the standard installation that comes the btree with is precompiled with a different Visual Studio that has a problem with VS 6.0 I was using. Even though I was able to download the dll (the release mode because the debug mode was wrong - shipped with improper MS nondebug libraries) the opening was returning this wrong message.

Only after opening the .dsw that came with the sources, and rebuilding it with VS 6.0 all went okay.

I hope it will help someone...

Friday, June 6, 2008

New download of the cvs repository on Windows

I have moved to a new laptop, and I had to get all the data from the cvs repository to this new one.
I wasn't even expecting so many problems with the WinCVS application to have!
No, it's not that WinCVS is bad. It's great. The point is that It gives so many options to accomodate so many users behaviours that at someome moment these options became a burden!

So I have finally decided to describe, step-by-step all the operations one needs to do in order to download new repository to his/her place.
This list is for cvs windows only.
I may to do this for Linux/Unix as well some time.
If you want to install WinCVS then, please, search on the Internet, wait for my new blog, or write to me in the comments.


RUN: <<<WinCVS>>>

MENU: <<<Admin/Login...>>>
EDIT: <<<CVSROOT:>>> - avoid using <<<...>>> It's overly confusing. It is better to enter the path:
:pserver;username=USERNAME;hostname=HOSTNAME:REPOSITORY
EXAMPLE: :pserver;username=john;hostname=our.server.org:/Projects

BUTTON: <<<OK>>>
The CVS will ask you for the password which will be stored at your machine
in an encrypted form and will be used for communication every time you
access the repository, but until you click MENU: <<<Admin/Logout>>>
MENU: <<<Remote/Checkout module...>>>
DIALOG: <<<Checkout settings>>>
EDIT: <<<Module name and path on the server:>>>
ProjectAlpha
EDIT: <<<Local folder to checkout to:>>>
CHANGE IT so it points at the ROOT directory where the ProjectAlpha directory will be created.
EXAMPLE: c:\JohnsProject\ (yes, add the backslash at the end!)

NOTE: If you DO NOT WANT to create the ProjectAlpha\ directory in the c:\JohnsProject one then you need to do:
CHECKBOX: <<<Check out into directory:>>> Turn in ON
EDIT: <<<Check out into directory:>>>
JohnsProject
COMBOBOX: <<<CVSROOT:>>>
Drop down menu and select the last one that you have enteted a few steps above.
BUTTON: <<<OK>>>
Off you go!



-------------------------------------
After this operation, you will have your selected directory (c:\JohnsProject\ProjectAlpha, or c:\JohnsProject only) populated with the data.
from the server.

Thursday, June 5, 2008

Sending an email from PHP (on Windows too.)

Yey, finally got something that really works.
It's not my stuff, but I was able to found it after a long time search!
Here is the link to sourceForge.net, to the page that hosts php Mailer for PHP 5 for Windows, and looks like for Unix too. If the link does not work then search for the word phpMailer.

The easiest way to install the stuff is to do as follows (example on Windows, with assumption that you have your php installed in the c:\php directory.)

> mkdir c:\php\mailer
Unzip phpMailer_v2.1.zip into c:\php\mailer
> notepad.exe c:\php\php.ini
Add at the very end:
include_path=".;c:\php\mailer"

Youre done!

Now, example:
>
<?php
require_once( "class.phpmailer.php" ) ;

$mail = new PHPMailer() ;
$mail->IsSMTP() ;
$mail->Host = "smtp.myserver.com:587" ;
$mail->SMTPAuth = true ;
$mail->Username = "username" ;
$mail->Password = "password" ;
$mail->From = "me@myserver.com" ;
$mail->FromName = "It is me!" ;
$mail->AddAddress( "testaddress@theirserver.com", "Poor Receiver" ) ;
$mail->AddReplyTo( "me@myserver.com", "do-not-reply" ) ;
$mail->AddAttachment( "c:\\mydog.jpg", "Isn't she cute?" ) ;
$mail->Subject = "Sorry for this test email!" ;
$mail->IsHTML( true ) ;
$mail->Body = file_get_contents( "c:\\myemail.html" ) ;
$mail->AltBody = "non-HTML mail client? Where are you from?" ;

if( !$mail->Send())
printf( "Sending Error: " . $mail->ErrorInfo . "\n" ) ;
else
printf( "Message has been sent successfully.\n" ) ;
?>

Friday, May 30, 2008

Script Shell Syntax checking

I'm writing a lot of stuff in shell (Korn,Bourne,Bash) and I had a need for syntax checker in the build time. Something I could use either in the command line (like a compiler) or in the make time which should stop the build whenever there is a syntax error in my script.

Here is what I came up to. Simply copy/paste the code below to a file named shck.sh (or whatever you wish to call it), do chmod+x shck.sh and off you go!

Usage:
shck.sh myscript.sh
-or-
cat myscript.sh | shck.sh

You can also use it in the makefile. It will return value 1 if there was an error.
-----------------------------------------------------
shck_return() {
    return $1
}
shck_errno=0
echo "set -n ">random.$$.sh
cat $1 >>random.$$.sh
chmod +x random.$$.sh
./random.$$.sh >errors.$$.err 2>errors.$$.err
rm -f random.$$.sh
grep -v ": warning: line" errors.$$.err | sed -e s/random.$$.sh/$1/g >errors.$$.err2
[ -s errors.$$.err2 ] && {
    shck_errno=1
    cat errors.$$.err2
}
rm -f errors.$$.err errors.$$.err2
shck_return $shck_errno

Wednesday, May 28, 2008

Opening unopenable attachments in Microsoft Outlook

The Microsoft Outlook software, starting, as I believe, from version 2003, turned opening some of the attachments for good. If you received, for example, an .mdb file (from Microsoft Access,) then you will only see that you got it, but you won't be able to copy it to the hard drive. Don't try searching in the options as suggested in the email. There is no option to turn the ability to detach the attachment on.
Microsoft says it clearly - because it is one of the most popular applications for managing emails, it has been constantly under attach by the hackers, so to 'save' their customers, they turned several options off for good. There is a workaround though. You can ask the sender to send you the file again, but ask him/her to rename the extension of the file or to zip/rar it. If such option is not a good one, or at least not for the very moment because you're in a hurry, there the following solution:

Run regedit: WARNING, WARNING: These operations are dangerous, so if you're not feeling secure, don't play with regedit. Screwing up in this file may screw up with your Windows installation and ultimatelly you may have to reinstall your OS!!!!

Open HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security
(11.0 is for Outlook 2003)

Create or add a New String Value under this key with the name: Level1Remove

Enter the file extensions separated with the semicolon (;) that you would like to support in the attachment. The file extensions should start with a coma.

EXAMPLE:
Level1Remove .mdb;.xlsx

Typical errors:
- forgetting to put a dot in the front of the extension
- putting spaces into the Level1Remove value
- Putting Level1Remove string into improper place in registry
- Creating a KEY instead of a STRING VALUE in registry.

When you are done, close the regedit program, close your Microsoft Outlook application, and open it again. From that moment, the files with the extensions you have just added into registry will be available for you.

Make sure you don't overdo and don't add others files 'just in case'. You may put yourself in danger by allowing to accept .exe, .bat, .js and other executable files. Use your head!

jpg - changing internal date and time stamp

Ooops. I have set an improper date on my digital camera and now, Picassa shows my pictures in improper order. I take care of setting the date and time stamp of the file but even though, Picassa puts my new pictures amont the last year ones.

I started searching for a tool that would allow me to change the internal jpeg (jpg) date and time stamps, and I have run onto a very nice one - file Tweak (http://filetweak.com) The sad part this tool, being really an excellent Windows addition to the file properties dialog box, cost money, and I didn't want to spend money to, from time to time, fixing my mistakes. (You can download a limited in time and functionality filetweak from them.)

I have decided to take a closer look to the jpg file and check if I can change the date and time opening the file in binary mode (I use Visual Studio, but you can find other free tools that can do it for you.)

What a surprize - the date time is stored in DOS open format!
Example: 2008:05:25 22:36:40

In my jpeg files are three dates (when the picture has been taken, when was digitalized and when was modified.)

The easiest way then, to change the timestamp of your jpeg files is:

Search for the year your picture has been taken (Right-click on the file, Properties,Summary tab,Make sure Advanced button is on, Search for Date Picture Taken.)
Simply, using any binary editor, modify the date and/or time of the jpg files (up to three places to be changed) and save the file. You're done. Picassa and you will be happy :)

Saturday, May 24, 2008

Running a command for each value comming back from an ODBC query in PHP

I have a need to read an ODBC datasource and run a query on a particual table. For each unique value of the table, I need to run a command in the shell.

Here is anexample:


<?php
$values = Array() ;
$command = "echo" ; /* for the example purposes the command is echo */
$columnName = "state" ; /* just for this example */

$hdbc = odbc_connect ( "dsn-name", NULL, NULL ) ;
if ( $hdbc != NULL )
{
$hstmt = odbc_prepare(
$hdbc
, "select distinct " . $columnName . " from tablename"
) ;
if ( $hstmt != NULL )
if ( odbc_execute( $hstmt ))
{
while ( odbc_fetch_row( $hstmt ))
$values[] = odbc_result( $hstmt, 1 ) ;
}
else
printf( "*** Unable to execute\n" ) ;
else
printf( "*** Unable to prepare the query.\n" ) ;

odbc_close( $hdbc ) ;
}
else
printf( "*** Unable to connect\n" ) ;

foreach ( $values as $value )
system( $command . " \"" . $value . "\"" ) ;
?>

Friday, May 23, 2008

Publishing an Excel table as static html using jscript.

Oh man! I have worked on it a few days, posted numerous questions on various newsgroups, spent hours on the Internet and in a book store, and finaly I got what I needed!

Requirement:
I have a sheet (Sheet1) in my xlsx document (Excel 2007) which I wanted to save as a static html page using.
I want to use jscript run in the command line, so I could automate the process.
I don't want to use SaveAs( ..., 44 ) method because it creates the sheet name at the bottom.
I also don't want to have the ActiveX embedded into the page (no dynamic html.)

Assuming that the document is c:\mydoc\test.xlsx, I want to generate c:\mydoc\test.html file.

Here is the code of doit.js file:

ea = new ActiveXObject( "Excel.Application" ) ;
ea.DisplayAlerts = 0 ; /* Don't want to see any questions on the screen! */
wb = ea.Workbooks.Open( "c:\\mydoc\\test.xlsx" ) ;
po = wb.PublishObjects ;
po.Add( 1, "c:\\mydoc\\test.html", "Sheet1" ) ; /* 1 == static html. */
po.Item( 1 ).Publish( true ) ; /* Yahoo! */
wb.Close( false ) ; /* I don't want to save the newly added PublishObject */

Isn't that cool!