1st March 2010
There is an excellent step-by-step instruction on resetting the bad clusters counter of an NTFS partition with linux-ntfs tools. I’ve checked – it works as expected:
- Back up important data from partition just in case
- Find out size of ‘$Bad’ attribute in $Badclus using ntfsinfo -i 8 partition (partition is for example /dev/sda1). It will be the “Allocated size” value in the “Dumping attribute $DATA (0×80)” (there will be two 0×80 attributes. Only one has an “Allocated size” line). Let us write down (remember) this size as ntfs_size.
- Use ntfstruncate partition 8 0×80 ‘$Bad’ 0 to set $Bad’s attribute length to zero.
- Use ntfstruncate partition 8 0×80 ‘$Bad’ ntfs_size to set $Bad’s attribute length back to proper value ntfs_size which was recorded in step 2.
- Boot into Windows and run chkdsk -f diskname. It will find errors and should fix them.
However, Debian’s ntfsprogs package does not have the ntfstruncate binary.
Here’s how you can easily build one yourself (you may need a few extra packages with build tools for that):
Read the rest of this entry »
Posted in *nix, Software, how-to | No Comments »
27th October 2009
This query performs a table-wide search-and-repalce:
UPDATE `table_name` SET `table_field` = REPLACE(`table_field`,’string to search for and replace’,'replacement string’);
If you need a database-wide search-and-replace, you could try this script (I haven’t tested/used it myself).
Beware of the following gotchas:
- wrong query syntax may ruin the field you are performing replace on, so always backup first!
- be sure to provide “search-for” string as specific as possible, or you will get unexpected replacements (e.g. replacing mini with little will also convert all minivans into littlevans); also, do use WHERE clause when necessary to limit the number of rows modified
- the function in the example is case-sensitive, so replacing all minivans with vehicles won’t replace Minivans. However, I believe there exists a case-insensitive version of REPLACE function
Posted in Notepad, how-to | No Comments »
21st October 2009
If you get this message when opening vignettes:
Error in openPDF(vif) :
getOption(‘pdfviewer’) is ”; please use ‘options(pdfviewer=…)’
and you are tired of running this command every time:
> options(pdfviewer=”okular”)
then you should check if your system-wide Renviron file has proper PDF viewer set:
Read the rest of this entry »
Posted in *nix, Notepad, Software, how-to | No Comments »
30th September 2009
If you have happened to observe similar messages in your dmesg:

[ 0.004000] Checking aperture…
[ 0.004000] No AGP bridge found
[ 0.004000] Node 0: aperture @ 20000000 size 32 MB
[ 0.004000] Aperture pointing to e820 RAM. Ignoring.
[ 0.004000] Your BIOS doesn’t leave a aperture memory hole
[ 0.004000] Please enable the IOMMU option in the BIOS setup
[ 0.004000] This costs you 64 MB of RAM
[ 0.004000] Mapping aperture over 65536 KB of RAM @ 20000000
and you are using AMD-based system w/o AGP video, then my advice is: just leave that as is, do not bother “improving”! Any tinkering with kernel boot options won’t do you any good, as the kernel has already done the best it could.
Just a note: all those messages at the top of the post should only happen if you have 4 or more GiBs of RAM. If you have less than that, and do have those messages – my experience might be inappropriate for your case.
Another note: my BIOS does not have any IOMMU settings (or “Memory hole remapping” settings), so I didn’t try that. You should check if your BIOS has IOMMU-related options first, just as kernel message suggests.
Read on for details.
Read the rest of this entry »
Posted in *nix, how-to | No Comments »
11th June 2009
There is no way I'm aware of to do what the title says. However...
I'm sure that you are aware of the fact that floats representation in any programming language is limited by the precision of the internal binary representations. In other words, you can never have an exact float representation - there will always be some precision associated with the float you are working with. The simplest example is the difference in precision between the float and double types in C.
Suppose I have the following code fragment:
C:
-
if ( result.score >= input->raw_cut_off )
Both result.score and input->raw_cut_off are of type float, and can have positive and negative values. When compared with the greater than or equal ( >= ) operator, it is not always that condition is true - for the precision reasons shortly mentioned above.
As I already said, there is no precision specification for equality operators in C. But it is quite simple to "invent" precision specification; e.g. if I wanted to test for equality only, I could write
C:
-
if ( fabsf( result.score - input->raw_cut_off ) < 0.000001 )
In this example, I'm effectively asking for 6-digit precision for the equality comparison of floating-point values. Note, that if you replace that 0.000001 with the actual precision limit of the floating type you are using, you will be "exactly" comparing floating-point numbers - up to that type's precision, of course
.
The first-most example with the >= operator can be rewritten as
C:
-
if ( result.score > ( input->raw_cut_off - precision) )
where precision is exactly what it is named, e.g. precision = 0.000001.
Sources used:
Posted in Programming, how-to | No Comments »
8th June 2009
Found here.
Recursively set directories only to drwx-rx-rx (755):
find . -type d -exec chmod 755 {} \;
Recursively set files only to rwx-r-r (644):
find . -type f -exec chmod 644 {} \;
Recursively remove newlines from the end of all *.php files:
find . -type f -name "*.php" -exec /home/user/dos2unix.sh {} \;
In all these cases, {} is replaced with the filename/directory find has found matching your parameters; \; at the end just stops exec processing.
Posted in *nix, Links, Notepad, how-to | No Comments »
11th May 2009
SecuriTeam has an old, but still very useful article on SQL injection.
I've created a PDF of that article, containing some of the comments (all the 'thank-you' and 'help-me-hack' comments were removed): sql injection walkthrough pdf download.
Note: there were no specific license terms attached to the article; I believe that the word "free" on the SecuriTeam site logo refers to the "right of free use and copying". If you know this is not the case - please let me know to remove this PDF from public access. (see Brian's comment)
Posted in Links, Software, Web, how-to | 3 Comments »
7th May 2009
MC is a console file manager. It supports FTP connections, and in my experience is faster in FTP than both Krusader and Gnome Commander.
However, the default FTP connection format string [username[:password]@]hostname has a drawback of not allowing the use of usernames with '@'-symbol in them - which is very common for virtual hostings.
One of the solutions is (done in your home directory):
- if there is no .netrc file in your home directory -- touch .netrc && chmod 600 .netrc
- mcedit .netrc (or use vi, nano, or any other editor you prefer)
- add the following line to the file (replace all-caps words with your actual credentials): machine HOSTNAME login USER@HOSTNAME password PASSWORD
Now, start MC, choose FTP connect, and enter only the hostname. You will be automatically logged in to the remote FTP.
This will also work for console ftp clients like lftp.
Posted in *nix, how-to | 1 Comment »
30th March 2009
Imagine you have some styles.css transferred from Win machine to Linux via FTP in binary mode instead of ASCII mode; then
cat styles.css | tr -d "\r" > styles-nocarriage.css
will create styles-nocarriage.css with ^M's removed.
Alternative syntax:
tr -d "\r" < styles.css > styles-nocarriage.css
Most editors have global replace features which allow to get rid of control characters using regular expressions (exact instructions are editor-specific).
For multiple files, try this:
for f
do
mv $f ${f}~ && tr -d "\r" <${f}~ >$f
rm ${f}~
done
Save this shell script as a file (e.g. dos2unix.sh), then do ./dos2unix.sh . This script accepts wildcards (e.g. ./dos2unix.sh *.php), so be careful!
Posted in *nix, Notepad, how-to | 1 Comment »
23rd March 2009
First, learn about custom CDFs and why they are needed.
The aroma.affymetrix R package google group has a how-to: create a CDF annotation file from scratch.
Also useful: how to convert CDF into an R package, which has all CDF data available (as a PDF with more details).
Posted in Links, Science, how-to | No Comments »