Wednesday, August 27, 2014

Supervisor Error: %(process_num) must be present within process_name when numprocs > 1

Problem:
As the error description implies, this happens when you set the, numprocs to a value greater than 1.

e.g. numprocs=4



Solution:
Supervisor will start as many instances of this program as named by numprocs so you need to include %(process_num) in the value you for program_name so that process will have unique names.

e.g. process_name = %(program_name)s_%(process_num)02d


Now you can restart supervisor






Tuesday, August 27, 2013

Select first row in each GROUP BY group (perform order by after group by)

PROBLEM

So you want to retrieve or select the top row of each set of rows in a group by clause after you have been given the ability to order your results.
Example:

SELECT * FROM orders
 
id | customer   | quantity
----------------------- 
 1 | Stanley    | 5
 2 | Martins    | 1
 3 | Stanley    | 3
 4 | Martins    | 8

If you want the query to return the largest quantity
ordered by each customer to have something like;

SELECT customer, TOP(quantity) 
       FROM orders 
       GROUP BY customer 
       ORDER BY quantity DESC;
 
 customer  |   TOP(id)   | TOP(quantity)
 Stanley   |   1         | 5
 Martins   |   4         | 8

But there is no function I can think of that does TOP for and ORDER BY
does not working before GROUP BY and behave differently after GROUP BY.
Note that this cannot be resolved by regular MAX/MIN aggregate functions because you don't know if (id) is necessarily bigger/smaller



SOLUTION 1 (with postgres array & subquery)
SELECT customer,
       (array_agg(id::text))[1] as id
       (array_agg(quantity::text))[1] as quantity
       FROM(
             (SELECT customer, quantity
                     FROM orders
                     ORDER BY quantity DESC ) as tmp
       )
       GROUP BY customer

 
What the above query does is to order results with a sub-query and then
make an array out of every row and select the first which is what you want.


SOLUTION 2
WITH summary AS (
    SELECT p.id
           p.customer, 
           p.quantity, 
           ROW_NUMBER() OVER(PARTITION BY p.customer 
                                 ORDER BY p.quantity DESC) AS rk
      FROM orders p)
SELECT s.*
  FROM summary s
 WHERE s.rk = 1
What the above query does is to order such that the first row number for every grouping is 1.





Thanks hope this helps.


Friday, October 19, 2012

netbeans Failed to connect to device 6! Reason: Emulator 6 failed to register in time

Failed to connect to device 6!
Reason:
Emulator 6 failed to register in time!

 
So you encounter this error when you are run netbeans right?
This is normally a data execution prevention issue. DO the ff.

Goto
control panel>>system>>advance system settings>>advanced tab>>settings under performance field set>>data execution prevention tab>>Turn on DEP for all programs and services except those I select

add "runMidlet.exe" as an exception by navigating to its directory in your netbeans installation folder
in my case it was located here

NetBeans/mobility/Java_ME_platform_SDK_3.0/runtimes/cldc-hi-javafx/bin

Restart your PC and you are good to go.
Sometimes you may have to go on to disable your firewall and antivirus if it is still not working.

If still not working, you are not out of luck...
In your netbeans, go to tools>java platforms>>CLDC Oracle Java(TM) Plaform Micro Edition SDK 3.0.5>>Click refresh
Do it again if it fails.
Then you should be good to go.
Hope this helps someone. :)

Friday, September 28, 2012

MSSQL Server: Database (In Recovery)


This can happen when the SQL Server Service has gone down hard in the middle of write operations and sometimes during mode during server startup
It means the database is still recovering and if the database is huge, it will cost a long time to finish the recovery. When this happens, it is advisable to remain calm and wait till the recovery is done.
Below is a script to help monitor and determine how long the database will be in recovery..

DECLARE @DBName VARCHAR(64) = 'GED_DRILLHOLES'
DECLARE @ErrorLog AS TABLE([LogDate] CHAR(24), [ProcessInfo] VARCHAR(64), [TEXT] VARCHAR(MAX))
INSERT INTO @ErrorLog
EXEC sys.xp_readerrorlog 0, 1, 'Recovery of database', @DBName
SELECT TOP 5
       [LogDate]
      ,SUBSTRING([TEXT], CHARINDEX(') is ', [TEXT]) + 4,CHARINDEX(' complete (', [TEXT]) - CHARINDEX(') is ', [TEXT]) - 4) AS PercentComplete
      ,CAST(SUBSTRING([TEXT], CHARINDEX('approximately', [TEXT]) + 13,CHARINDEX(' seconds remain', [TEXT]) - CHARINDEX('approximately', [TEXT]) - 13) AS FLOAT)/60.0 AS MinutesRemaining
      ,CAST(SUBSTRING([TEXT], CHARINDEX('approximately', [TEXT]) + 13,CHARINDEX(' seconds remain', [TEXT]) - CHARINDEX('approximately', [TEXT]) - 13) AS FLOAT)/60.0/60.0 AS HoursRemaining
      ,[TEXT]
FROM @ErrorLog ORDER BY [LogDate] DESC
Please note that towards the final completion(SAY 95%) of the recorvery, the file might not be updated anymore and this will indicate the end. Just REFRESH the DB and you are good to go

 

Saturday, July 21, 2012

php twitter: undefined index: oauth_token_secret



The problem is that there is an error in the request so you don't get oauth_token_secret in the respond from Twitter. Instead you get an error message.

Turn of php notice by typing the following at the top of the page
error_reporting(E_ALL ^ E_NOTICE);

print_r() the $request_token or $request variable to the screen. It will show you the type of error returned by twitter
print_r($request_token );

An example of the error message when you print the array is "Desktop applications only support the oauth_callback value 'oob' /oauth/request_token?oauth_callback=...."

Go to your app settings on twitter and make the correct settings.
In the case of the above error, set the callback url to the one you send in the request and try again!!

Good Luck.

Tuesday, July 17, 2012

svnserve: Can't bind server socket: Address already in use

I was done setting up svn and i ran "svnserve -d -r path"  and got the following:


svnserve: Can't bind server socket: Address already in use.

In my case I had previously set up svn which was already listening on the default port 3690.
I solved this simply by looking for that svn process and killing it.
Grep it on commandline with;
ps -ef  | grep svnserve

This will show the running svn process. Just get the processID/number and kill it and you should be set..

e.g sudo kill processID.





Thursday, July 28, 2011

pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022

Has anyone been face with this problem while trying some inserts into a postgres  DB with some character.

PHP Warning: pg_query(): Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe28022
HINT: This error can also happen if the byte sequence does not match the encoding expected by the server, which is controlled by "client_encoding".


Now this is not actually a posgres error but a php issue with html entity encode and decode functionalities. The same effect will happen on a MySQL db since MySQL and PostGre are fairly similar. This can be resolved by setting the character encoding in the php file to that of the database base. Eg for UTF-8 DB set the following in metadata the php file.

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />