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 »
25th October 2009
Production: see http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-debian-etch – it is for Debian Etch (which is old-stable), but many of the steps apply equally well to Debian Lenny (current-stable). Also, this is a very basic guide, as if you are going to host multiple sites from multiple clients, you most definitely will need some hosting control panel.
Development: see http://www.ruzee.com/blog/2009/01/apache-virtual-hosts-a-clean-setup-for-php-developers. This setup works very well, unless you need to create several virtual hosts every day – in which case necessary actions could be partially scripted.
Posted in Links, Notepad, PHP, Programming, Software | 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 »
4th May 2009
Today I had a task of displaying random node in a Views-generated sidebar block.
This is how to do that:
- edit the view which makes the block available (follow http://your.site/admin/build/views/viewname/edit)
- in the Sort Criteria section, add the Random criteria.
It can't be simpler than that.
Posted in Drupal, Notepad, Software | 2 Comments »
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 »
2nd March 2009
I assume you already have configured and working desktop environment, but want to improve performance.
First of all, sudo aptitude install mesa-utils. Then run in a Terminal/Konsole glxgears, and wait for ~15 seconds; if your FPS is ~400 or less, then you do have sluggish video performance (usually manifesting itself as slow scrolling in Firefox/Iceweasel, slow window switching/minimziing/maximizing etc).
After reading through several forums and bug reports and blog posts, I've ended with the following modifications to my /etc/X11/xorg.conf:
Read the rest of this entry »
Posted in *nix, Hardware, how-to | 5 Comments »
20th February 2009
I assume that you already have your gitosis-admin repository working (this is described elsewhere).
- cd gitosis-admin && git pull - enter your gitosis administrative repository and ensure it is up-to-date
- $EDITOR gitosis.conf
- add [group newreponame] section (newreponame is the name of your new repository being added); add yourself with members = yourlogin@yourhost line; also add writable = newreponame line:
[group newreponame]
members = yourlogin@yourhost
writable = newreponame
- based on my assumption of a correctly setup gitosis-admin repository, you should already have the appropriate public key in the keydir directory, but if not - copy your user's ssh public key to keydir in the form of yourlogin@yourhostname.pub, then do git add keydir/yourlogin@yourhostname.pub
- git commit -am 'new repository: newreponame'; git push;
- now that you have the new repo permissions configured, let's actually create it. Navigate to the directory holding the files of your project (e.g. cd ~/newreponame), and do git init; git add . - this initializes empty git repository, and then adds all the files to it.
- git commit -m 'initial commit'
- git remote add origin ssh://gitosis@yourGitosisServerName/newreponame.git
- git push ––all
- final thing: git config ––add branch.master.remote origin && git config ––add branch.master.merge refs/heads/master; alternatively, cd .git && $EDITOR config, and then add these lines:
[branch "master"]
remote = origin
merge = refs/heads/master
Without these lines, you won't be able to git pull.
Posted in *nix, Software, how-to | 6 Comments »
13th February 2009
Since some WP release, the comment author's link in comments is broken - it has ' external nofollow' attached straight to the href attribute (which breaks the link).
I assume that the problem is caused by Google Analytics, namely the "track outgoing clicks" feature (as recalled, might be inaccurate feature name). "Track outgoing links" adds some JavaScript code to all outgoing links, and that script has tick characters like this one ' which, incidentally, are also used for delimiting the values of comment anchor tags.
To fix:
Read the rest of this entry »
Posted in CMS, PHP, Programming, Software, Web, how-to | 3 Comments »
13th February 2009
Once I accidentally added circa 300 MiB of archive files to one of my git repositories (which was as small as 5 MiB). I removed those files as soon as I noticed them, but the .git directory still preserved commits with those files, and still occupied over 300 MiB.
I have found the solution at stackoverflow.
This method worked for me, but I couldn't push my rebased repository to the gitosis. I would need to re-init the gitosis repository from my rebased, but I'm not yet prepared to do that.
There is also a slightly different method (which relies on a temporary tag instead of a temporary branch), documented in Git online manual pages; I prefer the temporary branch method.
Below is a full copy-paste of the winning answer by Charles Bailey:
# create and check out a temporary branch at the location of the bad merge
git checkout -b tmpfix
# remove the incorrectly added file
git rm somefile.orig
# commit the amended merge
git commit --amend
# go back to the master branch
git checkout master
# replant the master branch onto the corrected merge
git rebase tmpfix
# delete the temporary branch
git branch -d tmpfix
Also, in my case this thread at stackoverflow was highly useful. I start enjoying the concise and compact style of Charles Bailey
:
Read the rest of this entry »
Posted in Links, Programming, how-to | 1 Comment »