Tricky sorting technique in MySQL

Recently, I faced an interesting challenge and I want to share my solution with the readers using a simple example. Suppose we have a list of TODO items. Each entry in the list may have a due date, the priority and creation date.

Now, suppose that you need to get the records from the database, sorted this way – first, show records with due date in ascending order, second, show records with no due date ordered by priority from higher to lower, and finally, show records that do not have due date and priority and sort them by date created. The first thing that comes to mind is to write this query:

SELECT * FROM todo WHERE ... ORDER BY due_date asc, priority desc, create_date asc

It would seem that’s all, the problem is solved, but there’s a catch – the first field (due_date) is not compulsory and that’s what we get as a result of this query:

Read the rest of this entry »

Grow file system on Fedora on VMWare

In this post I would like to show how to increase file system space on installed Fedora VMWare instance. You might need it if you use VMWare (and we know many people do) to spin VMs for Selenium testing.

In this particular case I use I installed Fedora and allocated 10GB but later I started using this VM for quite large databases and free space quickly disappeared.

# df -k
Filesystem                    1K-blocks    Used Available Use% Mounted on
devtmpfs                         498132       0    498132   0% /dev
tmpfs                            508060       0    508060   0% /dev/shm
tmpfs                            508060     772    507288   1% /run
/dev/mapper/vg_fedora-lv_root   7641992 6590912    656228  91% /
tmpfs                            508060       0    508060   0% /sys/fs/cgroup
tmpfs                            508060       0    508060   0% /media
/dev/sda1                        487652   84379    377673  19% /boot
# fdisk -l
 
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders, total 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000e3a8c
 
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    20971519     9972736   8e  Linux LVM
 
 
Disk /dev/mapper/vg_fedora-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders, total 4128768 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
 
 
Disk /dev/mapper/vg_fedora-lv_root: 8086 MB, 8086618112 bytes
255 heads, 63 sectors/track, 983 cylinders, total 15794176 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

To grow disk space I went to VMWare console and added one more disk as shown below:
 
 
Adding a disk to existing VMWare VM
 
 
Now we can see a new disk in “fdisk -l” command output.

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Now we create partition sdb1 covering all new disk using “fdisk /dev/sdb”.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
 
Command (m for help): v
Remaining 2047 unallocated 512-byte sectors
 
Command (m for help): w
The partition table has been altered!

Finally we just expand our volume group and file system:

pvcreate /dev/sdb1
vgextend vg_fedora /dev/sdb1
lvextend -l +100%FREE /dev/mapper/vg_fedora-lv_root
resize2fs /dev/mapper/vg_fedora-lv_root

Blogging

Some time ago we translated to Russian ‘Marketing by sharing’ talk by Jason Fried at ChicagoConvergence 2009 conference. Today we would like to share how it works for us so far. These are the stats for our two blogs only – Selenium and Development. Stats for Nerrvana and Startyco are not included.
 
 
Marketing by sharing - how it worked for us

‘Answers’ – questions & answers portal for your site

'Answers' - questions & answers portal for your site

Most of all we would not want to turn the Answers announcement into advertising. Instead, we decided to share our thoughts about two kinds of software – subscription based and the one you can pay for once and own, and specifically about web applications. As a rule, web apps are not to be for personal use, and to work in peer groups, like school teachers, employees, software developers. Then we actually explain how and why an idea was born to create some downloadable web applications. You don’t think we made Answers just because we didn’t want to use existing SaaS? Excellent! Then tune in to the philosophical mood (pipe, rocking chairs, a fireplace, and Sherlock Holmes nearby are highly recommended).

Because the whole internet world creates web services with monthly subscriptions (with some variations) and sells these services for a lot of money to the end user, we, at Deep Shift Labs, believe that there are still fans out there who like the concept of buying and owning a piece of software. System administrators are not yet extinct, they are the heroes, who are able to maintain the server software without spending hours on it, because they are professionals in their field and as a result are efficient and valuable.
Read the rest of this entry »

Out of touch with the clouds

No pasaran!

We decided to translate to English Michail Emel’yanikov’s post as we think it brings some importrant questions many people forget to ask. Did you?

“Over the past week, there seem to be more and more articles and notes about cloud computing – periodical influx of interest to any topic; nothing out of the ordinary. But after reading the latest material, I experienced a little déjà vu. All of this was written a year ago, if not more; worded the same way, and applicable to the same situations. On one hand, purveyors of cloud services try to convince us that their corporate clients are enthusiastically clambering into the clouds. On the other hand – all these years there has not been a single vivid answer to all of the simple, obvious questions. Namely:

1. What happens to the data when its uploaded to the cloud after the completion of any actions specified by the customer (editing, data processing, pressing the Delete key on the user’s computer, working with the cloud’s infrastructure)?
Read the rest of this entry »

How Ideas are different from Answers

In our new product – Ideas, users will be able to vote for a published idea only. In Answers we called responses – answers; in Ideas we call responses – comments. Users can comment on an original idea to improve or discuss things with the idea’s contributor. Also users can like/dislike other users’ comments or reply to other users comments (see below).

Startyco Ideas

If Answers is a modern implementation of FAQ, where your users can ask questions and get answers, Ideas is your public roadmap channel, where you and your users can collaborate on your product’s or service’s future.

Administrators of your Ideas portal will be able to create idea statuses like – rejected, in development, implemented etc. and maintain your Ideas portal in an up to date state with them.

All planned new features – WYSIWYG, spam protection, mobile version, widget, oAuth authorization will be added simultaneously to Answers and Ideas.

Dashboard UI in Answers

Managing our products from the configuration file is possible but inconvenient, and we understand this. We decided not to include it in our first release and concentrated on the creation of the install script’s UI instead. But we, at Deep Shift Labs, already started discussing the appearance of the dashboard, and what functionalities it will include.

No doubts it will be a single interface for all Startyco products our clients will buy and plug to the same core product. This is our goal; to create pluggable web apps with a single dashboard to manage them all.

For now we do not have many features (and we do not rush to implement them all), and this is how dashboard can look like to administer users:

Startyco Admin's Dashboard - Users

We think this would be a better way to share permissions rather than manipulate user IDs from the database and edit a configuration file.

Here is a wireframe of the spam protection part of our dashboard which shows messages which were suspected as spam by, for example, SpamAssassin. You will decide how Startyco products will react, post them, and notify you or delay posting and notify. You will be able to ban and train your own instance of SpamAssassin to make it smarter.

Startyco Admin's Dashboard - Spam

Comments in Answers


One of the features from our TODO list is ‘Comments’. This mode can be turned on to allow your users to clarify a question or an answer. We think, this mode will add some interactivity to your Answers portal and make it more convenient for your users.

Comments UI in Answers

Voting in Answers

We are adding a voting feature in the next Answers release. Users will be able to vote for questions (for example, ‘I also have this question’ or ‘this question does not make any sense’) and answers. You will be able to turn on voting by setting it in the configuration file. You can allow voting for questions only, for answers only, both, or none.

We thought it will be quite important to be able to show up and down votes split. To keep the UI simple you will be able to see it when you hover your mouse over voting arrows or score. It makes sense to show a votes split when there are a few votes in different directions which also means it has to be at least two votes. Maybe we will show votes spit without hover when an answer’s score is 0 with equal amount of votes up and down (‘controversial answer’, I would say).

Voting UI in Answers and Ideas Read the rest of this entry »

XSS and HTML formatted text

No pasaran!


We have been working on Starty.co Answers for quite a while, and we cannot stop adding new features and hone existing ones.
Finally we decided to release the first version of Answers without such a convenient thing as text markup, like BBCode. However, we did some preparatory work in this area and decided that in the near future it will include the TinyMCE  WYSYWIG and Highlight.js module to highlight code snippets.

Even though we decided not to include a full markup in version one, it was necessary to implement the basic things – to replace the line breaks with <br> and parse http(s):// links in the text and replace them with <a href=”"></a>.
Read the rest of this entry »

Looking for something? Visit the archives.