We optimize your website by analyzing the pattern of the website. By using improved methods of optimization we makes your web pages fly while rendering. Some of the points from our checklist are: By improving your code, optimizing JS for non-blocking while rendering. Sharing the web page load(I/O) by using a CDN and Seprate Session
SyntaxError: Use of const in strict mode
I’m working with node.js, and in one of my js files I’m using const
in "strict mode"
. When trying to run it, I’m getting an error:
SyntaxError: Use of const in strict mode.
If this is happening in nodejs, it is due to the older version of nodejs. Update node by using,
1) Clear NPM’s cache:
sudo npm cache clean -f
2) Install a little helper called ‘n’
sudo npm install -g n
3) Install latest stable NodeJS version
sudo n stable
Update nodejs instructions taken from, http://stackoverflow.com/a/19584407/698072
Web performance Optimization
We optimize your website by analyzing the pattern of the website. By using improved methods of optimization we makes your web pages fly while rendering.
Some of the points from our checklist are:
- By improving your code, optimizing JS for non-blocking while rendering.
- Sharing the web page load(I/O) by using a CDN and Seprate Session and Caching servers.
- By Using Caching technology like Varnish, aiCache.
- Using shared network caching like Memcached, Redis.
- Optimizing the structure of your website for faster rendering in browsers like IE.
- Optimizing Database Servers like Mysql, PostgreSQL for dynamic websites.
- Web Server Optimization for web servers like Nginx, Apache, IIS, Tomcat, IBM Http Server, JBOSS, Express.
- Using right Headers for Cache Control.
- Image Optimization and Compression.
Get list of product attribute in Magento
# Get list of colors from Magento Installation
Let’s create a file called getcolors.php on Magento root folder.
require_once ( “app/Mage.php” );
umask(0);
Mage::app(“default”);
Mage::getSingleton(“core/session”, array(“name” => “frontend”));
$attribute = Mage::getSingleton(‘eav/config’)->getAttribute(‘catalog_product’, ‘color’);
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
}
print_r($options);
When you excute the file getcolors.php either from shell or browser, It will print the list of color used in product catalog.
Mindgeek Video Commerce Engine
Contact For more details.
Change a product’s attribute value without loading the entire product model
Loading product in a collection and saving them again and again over will take lot of time. To make it quick there is an alternate solution available which uses the same function used by Update attributes action from the product grid:
Mage::getModel('catalog/product_action')
->updateAttributes(array($productId), array('attribute_code'=>'value'), 0);
Parse query string in shell script
Sometimes we have to integrate multiple languages like node.js/php/shell script into bash shell script and parse query string to array for supplying query string data for manipulation.
Here is the simple script which will help you to achieve that goal:
#!/usr/bin/env bash
declare -A querydict
populate_querystring_array () {
query=”$1″
while IFS== read arg value
do
querydict[“$arg”]=”$value”
done < <(echo “$query” | sed ‘s/&/\n/g’ )
}
q=’user=mindgeek&password=1234f’
populate_querystring_array “$q”
printf “${querydict[user]}\n”
Flickr: Computer vision at scale with Hadoop and Storm
No package ‘opencv’ found
If you are getting this error while compiling certain modules which requires opencv library which is causing the execution to be aborted.
For fixing it, you need to install lib-opencv using following command:
Ubunntu/Debian – sudo apt-get install libopencv-dev
Centos/Red Hat – sudo yum install opencv-devel
After you do so, pkg-config –cflags opencv and pkg-config –libs opencv will work as expected.
Using underscore.js with node.js
Underscore.js:
Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. It’s the answer to the question: “If I sit down in front of a blank HTML page, and want to start being productive immediately, what do I need?” … and the tie to go along with jQuery‘s tux andBackbone‘s suspenders.
Underscore provides over 100 functions that support both your favorite workaday functional helpers: map, filter, invoke — as well as more specialized goodies: function binding, javascript templating, creating quick indexes, deep equality testing, and so on.
Source: http://underscorejs.org/
To install underscore.js in a node.js project use: npm install underscore
After installing it you can use underscore now on your node.js project as : var _ = require(‘underscore’);
Things you can do with _ :
1. Merge two json objects:
var obj1 = {foo:”bar”};
var obj2 = {name:”john”};
var merged = _.extend(obj1,obj2);
Error: /lib64/libc.so.6: version ‘GLIBC_2.14’ not found
Sometimes on your node.js project you have seen problems like “Error: /lib64/libc.so.6: version ‘GLIBC_2.14’ not found” by some npm modules.
Error: /lib64/libc.so.6: version ‘GLIBC_2.14’ not found
This error comes when the available version of glibc is not compatible by the node module.
So, if you still want to work with that module, you need to rebuild that module on your project.
To do this simply go to Github, Clone a repo for node module where its installed in project, may be in node_modules directory.
Inside the node_modules directory clone that repo:
Example- git clone https://github.com/node-xmpp/node-expat.git
Now go to the cloned module, cd node-expat
Then install all node module dependencies.
– npm install
After installing it to a clean build for that module:
– node-gyp rebuild
Voila! Use the module in your project now.
XML into MongoDB – quick and dirty
Import XML from various API’s to MongoDB.
Better way to load layout blocks outside of Magento
For loading Magento Layout Blocks externally or in a controller without any complexity, use this:
From external file, we need to initiate Magento session:
Mage::getSingleton(‘core/session’, array(‘name’=>’frontend’));
$session = Mage::getSingleton(‘customer/session’, array(‘name’=>’frontend’));
$layout = Mage::app()->getLayout();
$layout->getUpdate()->addHandle(‘default’)->load();
$layout->generateXml()->generateBlocks();
$top = $layout->getBlock(‘top.links’)->toHtml();
echo $top;
From internal controller:
$layout = Mage::app()->getLayout();
$layout->getUpdate()->addHandle(‘default’)->load();
$layout->generateXml()->generateBlocks();
$top = $layout->getBlock(‘top.links’)->toHtml();
echo $top;
How to configure libstdc++ with GCC 4.8?
You need to tell your dynamic linker (it’s executed when you run your program) where to find the library. Set LD_LIBRARY_PATH to the path of the library (probably somewhere under /app/gcc/4.8.0/lib or something).
Use find /app/gcc/4.8.0 -name “libstdc++.so.6”. Add the directory to your LD_LIBRARY_PATH. e.g with the path I mentioned:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/app/gcc/4.8.0/lib (if you’re using a bourne-like shell which the default on Linux).
Then try to run your program.
Voila!!
Openresty : Programming with Magento/Mysql – Get Inventory of Products REST API
Skills Requried – LUA, nginx, mysql
If you have nginx-openresty installed, open the vhost file of your domain, than follow this:
Let your REST API path is http://<your-domain>.com/getstockserv?p=123450,12145
where p is the parameter where all product ids of Magento Products has been supplied.
Now add this entry to the vhost file –
location ^~ /getstockserv {
content_by_lua ‘
local mysql = require “resty/mysql”;
local cjson = require “cjson”;
args = ngx.req.get_uri_args();
local query = “select product_id from cataloginventory_stock_item where is_in_stock = 0 and product_id in (“.. args.p ..”)”;
local db, err = mysql:new();
db:set_timeout(5000);
local ok, err, errno, sqlstate = db:connect{
host = “<Enter Mysql Hostname>”,
port = 3306,
database = “<Enter Database Name>”,
user = “<Enter Mysql User>”,
password = “<Enter Mysql Password>”,
max_packet_size = 1024 * 1024 };
res, err, errno, sqlstate = db:query(query);
ngx.header[“Content-Type”] = “application/json”;
ngx.say(cjson.encode(res));
ngx.exit(ngx.HTTP_OK);
return;
‘;
}
Reload nginx : nginx -s reload
Voila!! Now you can get the inventory of products without using Magento.
How to add a Volume to EC2 Instance?
Go to EC2 console to create the volume and attach it to the instance, and then we’ll mount the volume to make it available.
– under Elastic Block Store, click Volumes.
– Click on Create Volume – Select the General Purpose (SSD) volume type.
– Wait for your Volume to be available.
– Right click on it and select Attach Volume, Select the instance and specify an unused device name say /dev/xvdk
For making it available follow these steps:
[ec2-user ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdk 202:80 0 22G 0 disk
xvda1 202:1 0 8G 0 disk /
here xvdk device is not mounted.
To Mount it – mkfs -t ext4 /dev/xvdk
# mkdir /mnt/space
# mount /dev/xvdf /mnt/space
Voila, You just added the volume to the system.
To check it, df -h
[ec2-user ~]$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 1.1G 6.8G 14% /
tmpfs 298M 0 298M 0% /dev/shm
/dev/xvdk 22G 0 22G 0% /mnt/space
How to make nginx works with Geo IP?
NGINX GeoIP Installation:
Follow these steps to install GeoIP with nginx:
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
cd GeoIP-1.4.8/
./configure
make
make install
echo ‘/usr/local/lib’ > /etc/ld.so.conf.d/geoip.conf
yum install gcc pcre-devel.x86_64 openssl-devel.x86_64
yum install readline-devel pcre-devel openssl-develWe are using openresty – nginx here:wget http://openresty.org/download/ngx_openresty-1.7.2.1.tar.gz
tar xzvf ngx_openresty-1.7.2.1.tar.gz
cd ngx_openresty-1.7.2.1
./configure –with-luajit –with-http_geoip_module
gmake
gmake installwget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz -O /usr/local/share/GeoIP/GeoIP.dat.gz
gunzip /usr/local/share/GeoIP/GeoIP.dat.gz
In nginx.conf http block – geoip_country /usr/local/share/GeoIP/GeoIP.dat;Reload nginx – nginx -s reload
Nginx Openresty Get/Set Cookies using LUA.
To set cookies using lua while using nginx_lua module in openresty/nginx server, use this code:
local expires = 3600 * 24 — 1 day
ngx.header[“Set-Cookie”] = “session=demo; Path=/; Expires=” .. ngx.cookie_time(ngx.time() + expires)
This will set cookie session = demo for 1 day from current time on path /.
Use PHP Functions in LUA Code
Based on [PHP explode]
if (div==”) then return false end
local pos,arr = 0,{}
— for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,string.sub(str,pos,st-1)) — Attach chars left of current divider
pos = sp + 1 — Jump past current divider
end
table.insert(arr,string.sub(str,pos)) — Attach chars right of last divider
return arr
endimplode
Based on [PHP implode]Use table.concat:
PHP implode(join,array) is equivalent to Lua table.concat(table,join)
PHP: implode(” “,array(“this”,”is”,”a”,”test”,”array”)) –> “this is a test array”
Lua: table.concat({“this”,”is”,”a”,”test”,”array”},” “) –> “this is a test array”
Reference – http://lua-users.org/wiki/MakingLuaLikePhp
Purge redis keys in matching pattern
After logging in to linux shell execute this command
redis-cli KEYS “*$1*” | xargs redis-cli DEL
Mysql get size of tables in a database
To find the detail of size of tables in a database use this query in mysql console:
SELECT table_name AS “Tables”,
round(((data_length + index_length) / 1024 / 1024), 2) “Size in MB”
FROM information_schema.TABLES
WHERE table_schema = “$DB_NAME”
ORDER BY (data_length + index_length) DESC;
E.g. for database name mydatabase :
SELECT table_name AS “Tables”,
round(((data_length + index_length) / 1024 / 1024), 2) “Size in MB”
FROM information_schema.TABLES
WHERE table_schema = “mydatabase”
ORDER BY (data_length + index_length) DESC;