Create a new file
$ sudo vim /etc/init.d/$NAME
Change the template to suit your needs
#!/bin/bash
case "$1" in
start)
# start commands here
;;
stop)
# stop commands here
;;
restart)
# restart commands here
;;
*) # no parameter specified
echo "Usage: /etc/init.d/$NAME start|stop|restart"
exit 1
;;
esac
exit 0
Hook the script to all runlevels
$ sudo update-rc.d $NAME defaults
Let’s say you have a gallery and it consists of three database tables (photos, category and gallery). Each of these tables has lots of related data, obviously…
By following the old database routine, I started indexing data from top to bottom (from gallery to photos table).
But this resulted in a weird behavior where SOLR would index gallery id and name, and only the first category; It simply ignored all other gallery categories and photos.
After spending days mind boggling what could go wrong, it suddenly occurred to me that the proper way to index data into SOLR would be to index is “opposite direction”, from bottom to top that is (from photos to gallery).
It was a great relief to finally see all relational data properly indexed :)
The example that bothered me was:
MySQL schema
photos
- id
- categoryId
- views
- url
- title
category
- id
- name
- galleryId
gallery
- id
- name
SOLR db-data-config.xml
<dataConfig>
<dataSource
type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/database"
user="username"
password="password"/>
<document name="gallery">
<entity rootEntity="true" name="photos" query="select *, rand() as uuid from photos">
<field name="photo_id" column="id" />
<field name="photo_categoryId" column="categoryId" />
<field name="photo_views" column="views" />
<field name="photo_url" column="url" />
<field name="photo_title" column="title" />
<entity name="category" query="select * from category where id='${photos.categoryId}'">
<field name="category_id" column="id" />
<field name="category_name" column="name" />
<field name="category_galleryId" column="galleryId" />
<entity name="gallery" query="select * from gallery where id='${category.galleryId}'">
<field name="gallery_id" column="id" />
<field name="gallery_name" column="name" />
</entity>
</entity>
</entity>
</document>
</dataConfig>
To create swap space in a file:
First, create a file. I have 4GB of RAM, hence I create 4GB large file
$ sudo dd if=/dev/zero of=/media/4GB.swap bs=1G count=4
Set proper file attributes
$ sudo chmod 600 /media/4GB.swap
Set created file as a swap space
$ sudo mkswap /media/4GB.swap
Start swapping
$ sudo swapon /media/4GB.swap
Edit the fstab file
$ sudo vim /etc/fstab
and set the swap file to mount automatically on next reboot
/media/4GB.swap swap swap defaults 0 0
With the release of PHP 5.3.0 there is an option to shorten the ternary operator.
So, if we start with variable $foo, which is true ($foo = true), instead of writing:
$bar = $foo ? true : false; // $bar = true
you can easily shorten it like this
$bar = $foo ?: false // $bar = true
The bad side of using a short ternary operator is that most of PHP IDEs are marking it as syntax error (well, at least for now)
One of the best ways to report a bug in Ubuntu is to report it right at Launchpad.
First, you need to identify a process that is causing a problem.
Open “System Monitor”, click on “Processes” tab and find a process ID that is bugging you.
Then open “Terminal” and run following command
$ ubuntu-bug $ID
The system will collect system and process data and upload it to Launchpad site.
All you need to provide is your description of a problem.
After that, just sit and wait (and provide aditional details about the bug to the developers)
DELETE
$table1
FROM
$table1
LEFT JOIN
$table2
ON
$table1.fieldId = $table2.fieldId
WHERE
$table2.fieldId == NULL
;
Java apps have a small issue with global menu in Unity.
To revert Zend Studio to old-style menus:
Create a “ZendStudio.sh” file in ZendStudio directory
#!/bin/bash
UBUNTU_MENUPROXY=0
/path/to/ZendStudio
Make the file executable
chmod +x ZendStudio.sh
Now create a lanucher icon “zend-studio.desktop”
vim ~/.local/share/applications/zend-studio.desktop
Add the following content to it
[Desktop Entry]
Name=Zend Studio
Exec=/path/to/ZendStudio/ZendStudio.sh
Icon=/path/to/ZendStudio/icon.xpm
Terminal=false
Type=Application
StartupNotify=true
Make the file executable
chmod +x ~/.local/share/applications/zend-studio.desktop
Then, navigate to that location via Nautilus (press CTRL+H to |un|hide files), run the “Zend Studio” icon and pin it to the launcher.