Python api to priceminister webservice

If you need to manage sells on Priceminister, you can now use Shiba, the brand new python API designed by my team.

Publié dans dev, python

Doing some ec2 stuff (webservices) in crontab

Just add those lines in front of your crontab file :

 

PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/opt/aws/bin:/home/ec2-user/bin
EC2_HOME=/opt/aws/apitools/ec2
JAVA_HOME=/usr/lib/jvm/java

Publié dans amazon, centos, ec2, linux, tips Tagués avec : , , , ,

Finding unused index on postgresql 9

Just use this query on you database and find unwanted indexes :

 

SELECT
 t.tablename,
 indexname,
 c.reltuples AS num_rows,
 pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
 pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
 CASE WHEN x.is_unique = 1 THEN 'Y'
 ELSE 'N'
 END AS UNIQUE,
 idx_scan AS number_of_scans,
 idx_tup_read AS tuples_read,
 idx_tup_fetch AS tuples_fetched
FROM pg_tables t
LEFT OUTER JOIN pg_class c ON t.tablename=c.relname
LEFT OUTER JOIN
 (SELECT indrelid,
 max(CAST(indisunique AS integer)) AS is_unique
 FROM pg_index
 GROUP BY indrelid) x
 ON c.oid = x.indrelid
LEFT OUTER JOIN
 ( SELECT c.relname AS ctablename, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch,indexrelname FROM pg_index x
 JOIN pg_class c ON c.oid = x.indrelid
 JOIN pg_class ipg ON ipg.oid = x.indexrelid
 JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid )
 AS foo
 ON t.tablename = foo.ctablename
WHERE t.schemaname='public'
ORDER BY 1,2;

You can do pg_stat_reset() before that and let your db run for a time before anylisis

From http://wiki.postgresql.org/wiki/Index_Maintenance

Publié dans postgresql, sql Tagués avec : , ,

Postgresql : How to add an index on a computed column

Postgresql offers a great way to add computed column, but do you know there is a way to index those columns ?

 

CREATE INDEX your_table_ix
 ON your_table
 USING btree
 (computed_column_name(your_table.*)

 

Notice that the computed column has to be an IMMUTABLE function or it will not work

Publié dans postgresql, sql Tagués avec : ,

reset pgagent jobs

Here is the brutal method to reset jobs from a restart fails of postgresql pgAgent

delete from pgAgent.pga_jobagent;
 delete from pgAgent.pga_joblog;
 delete from pgAgent.pga_jobsteplog;
Publié dans sql Tagués avec : ,

How to install postgresql multicorn extension on debian 7.1

First we need pgxnclient

sudo aptitude install pgxnclient

Then, for building multicorn, we need several tools

sudo aptitude install postgresql-server-dev-all make python-dev python-setuptools

Then we can build the pgsql extension

sudo pgxn install multicorn --testing --verbose

Finally, you can install extension on your db/schema

CREATE EXTENSION multicorn;
Publié dans debian, linux, sql Tagués avec : , , ,

Shuffle a Java Vector

A good way to shuffle a Java vector :

Collections.shuffle(allPartenaires);
Publié dans dev, java Tagués avec :

Missing « publish » button in wordpress

I recently had a small issue with every wordpress blog I host on my dedicated EC2 cluster (Mysql + nginx + php) : The « Publish » button was missing.

There only was a « Submit to review » button , but nothing else !

After some investigation, It looks like the mysql db was involved.

 

The problem was two conf options in sql_mode from /etc/my.cnf : NO_ZERO_DATE and NO_ZERO_IN_DATE

 

If you want to know what those options are made for, take a look there

Publié dans bug, tips Tagués avec : , ,

How to count number of new line in a log file per seconds

Here is a good way to count number of new line in a log file per seconds in linux command line

 

tail -f /var/log/logfile | grep something | perl -e 'while (<>) {$l++;if (time > $e) {$e=time;print "$l\n";$l=0}}'

 

Credits to commandlinefu.com

Publié dans linux, tips Tagués avec : , ,

How to redirect root base tld to www.tld with nginx

You have to add those lines in your /etc/nginx/sites-enables/tld

server {
server_name tld;
rewrite ^(.*) http://www.tld $1 permanent;
}

Then reloads nginx

sudo /etc/init.d/nginx reload
Publié dans linux, nginx Tagués avec : ,