Calling APIs from Javascript/Node.js

This is one of the most common things now-a-days developers are doing more then before. Raise of Microservices based architecture and distributed software development needs more inter service communication i.e more codes for api consuming stuff, sometimes more then actual business logics. It is good that business logic coding is now less redundant.

Consuming API with nodeJS

Node.js comes with native http and https to request apis. http.get() or https.get() is good when you have simple api GET calls. No third-party module needed just wrap with promises. It outputs as a stream of api response.

Using “request” module: This library is here since 2011. it’s the very popular one. Request library has no support for promises. so you have to wrap it with promise, some promise library like ‘when‘ and ‘deferred‘ can be perfect for complex promises.

Using “axios” module: axios returns promise so you don’t have to wrap with a promise. It parse json response by default. since I like to build sdk module for apis where I have to wrap with another promise. axios has relatively less dependency.

Using “superagent“: superagent is another nice library. As the documentation says it was build for front-end ajax based use case. it works with browserify and webpack. but it works with node.js. superagent is easy has lots of community plugins

Docker Logging with Elasticsearch Fluentd Kibana(EFK) Stack

Keeping logs for apps running in Docker with EFK is nice.
First of all why Fluentd not Logstash(ELK) ? Fluentd is lite and fast ! “Fluent Bit” is more fast with less filtering features.

Using docker-compose we can have containers for Elasticsearch, Fluentd, Kibana and Containers for actual apps.

Here is a example docker-compose.yml file
Continue reading Docker Logging with Elasticsearch Fluentd Kibana(EFK) Stack

Docker Security Checklist

  • Use official images.
  • Restrict network/links within containers.
  • Make sure docker daemon REST api is off, and then use traditional UNIX permission checks to Limit access to the control socket.
  • Limit docker daemon permission on host.
  • Run as non-root.
  • Add an extra layer of safety by enabling AppArmor, SELinux, GRSEC, or your fav hardening solution.

Control Your Laptop with an Android Phone using Python, Twisted, and Django


It’s always fun to put your Android or Python programming skills on display. A while back, I figured it’d be cool to try and control my laptop via my Android mobile device. Think about it: remote laptop access including being able to play and pause music, start and stop programming jobs or downloads, etc., all by sending messages from your phone. Neat, huh?

Before you keep on reading, please bear in mind that this is a pet project, still in its early stages—but the basic platform is there. By gluing together some mainstream tools, I was able to setup my Android phone to control my laptop via a Python interpreter.

By the way: the project is open source. You can check out the client code here, and the server code here.

The Remote Laptop Access Tool Belt: Python, Twisted, Django, and Amarok

This project involves the following technologies, some of which you may be familiar with, some of which are quite specific to the task at-hand:

  • Python 2.7+
  • Twisted: an excellent event-driven framework especially crafted for network hackers.
  • Django: I used v1.4, so you’ll have to adjust the location of some files if you want to run a lower version.
  • Amarok: a D-BUS (more on this below) manageable media player. This could be subbed out for other such media players (Clementine, VLC, or anything that supports MPRIS) if you know their messaging structures. I chose Amarok because it comes with my KDE distribution by default. Plus, it’s fast and easily configurable.
  • An Android phone with Python for Android installed (more on this below). The process is pretty straightforward—even for Py3k!
  • Remote Amarok and Remote Amarok Web.

At a High Level

At a high level, we consider our Android phone to be the client and our laptop, the server. I’ll go through this remote access architecture in-depth below, but the basic flow of the project is as follows:

  1. The user types some command into the Python interpreter.
  2. The command is sent to the Django instance.
  3. Django then passes the command along to Twisted.
  4. Twisted then parses the command sends a new command via D-Bus to Amarok.
  5. Amarok interacts with the actual laptop, controlling the playing/pausing of music.

Using this toolbelt, learn how to control a laptop with Python, Twisted, and Django.

Now, lets dig in.

Continue reading Control Your Laptop with an Android Phone using Python, Twisted, and Django

How to Integrate OAuth 2 Into Your Django/DRF Back-end Without Going Insane

We’ve all been there. You’re working on the API back-end, and you’re happy with how it’s going. You’ve recently completed the minimal viable product (MVP), the tests are all passing, and you’re looking forward to implementing some new features.

Then the boss sends you an email: “By the way, we need to let people log in via Facebook and Google; they shouldn’t have to create an account just for a little site like ours.”

Great. Scope creep strikes again.

The good news is that OAuth 2 has emerged as the industry standard for social and third-party authentication (used by services such as Facebook, Google, etc.) so you can focus on understanding and implementing that standard to support a wide range of social authentication providers.

It’s likely you’re not familiar with OAuth 2; I wasn’t, when this happened to me.

Integrate OAuth 2 Into Your Django/DRF Back-end

Continue reading How to Integrate OAuth 2 Into Your Django/DRF Back-end Without Going Insane

Installing Django on IIS: A Step-by-Step Tutorial

Though many Django Developers might consider it blasphemous, sometimes it is actually necessary to deploy Django applications on Windows/IIS, especially when working with a client that has based its infrastructure around the Windows ecosystem. The “blasphemy” part comes from Django having really been targeted at the Unix environment, relying heavily on features like WSGI, FastCGI, and command-line tooling, all of which are foreign to Windows. Fortunately, Django/IIS compatibility is improving, thanks to the addition of features (which would otherwise be a kludge) on both the Windows and the Python+Django sides of the equation, thereby helping to resolve compatibility issues between these two disparate technical worlds.

Installing Django on IIS
Continue reading Installing Django on IIS: A Step-by-Step Tutorial

A Guide to Responsive Web Design Image Solutions

As mobile and tablet devices come closer to achieving final world domination, web design and technology is in a race to accommodate the ever-growing number of screen sizes. However, devising tools to meet the challenges of this phenomenon brings a whole new set of problems, with one of the latest buzzwords to emerge being “responsive web”. This is the challenge of making the web work on most, if not all, devices without degrading the user’s experience. Instead of designing content to fit desktop or laptops, information has to be available for mobile phones, tablets or any surface connected to the web. However, this responsive web design evolution has proven to be a difficult and sometimes painful one.

While it can be almost trivial to accommodate textual information, the tricky part comes when we put into consideration content like responsive images, infographics, videos, an so forth, which were once designed with only desktops in mind. This not only brings up the question of displaying the content correctly, but also how the content itself is consumed using different devices. Users on smart phones are different to users on desktops. Things like data plans and processing speed have to be considered as well. Google has started to highlight mobile-friendly sites on its search results, with some speculating that it will lead to a substantial pagerank boost to such sites. Earlier solutions addressed this by deploying mobile-only subdomains (and redirects) but this increased complexity and fell out of fashion quickly. (Not every site has the ability to afford this route.)

On the Quest for Responsive Web Images
Responsive web design images simply must scale to fit common devices in the modern age.

Continue reading A Guide to Responsive Web Design Image Solutions

Automatic plant watering by aquarium air pump

This is how we water our plats in last vacation for 10 days, worked perfectly.
Using a fish tank aquarium air pump.
All you have to do is make some hole in air pipe and pass pipe through water bucket. make sure holes in pipe are under water. Then water will get into pipe and air flow will pass water to plant pot.

Good way to connect database in Phalcon php framework

Database connection settings can be done by registering services in the container.
Here is how we can connect a postgresql database

Make image to base64 dataUri in NodeJS

Images are already in server, may be uploaded by multer. now have to make dataUri for s3.

PHP Data Filtering

PHP have native extension to filter data by either validating or sanitizing it.

PostgreSQL plsql method with json argument

To get a element of json we can call with index name like this i_json::json->>’bar’
Here is a sample method with josn argument

Calling with a json will return “world” which is the value of json index bar

Interesting features of Phalcon PHP framework

First of all Phalcon is not like any other php framework because it’s a php extension written in C. Php extension are .so files like
Since it’s a php extension it’s always loaded if the extension is enabled in php.ini file, even with nothing build. And this going to make this perform fast.

The framework have no defined directory structure, so you can build your application in different pattern like multi-module, HMVC etc

to be continue…

Magento truncate a table

Truncating may needed if you want to reset all your module data, In your tables Mage_Core_Model_Resource_Db_Abstract model add a function truncate

Call the truncate when needed

Change/Override Base Url from local.xml of Magento

For ‘default’ store
Open /app/etc/local.xml
Add just before closing tag.

Magento Re-Install Extension by Script

Create a file reinstall.php in magneto’s root directory and run by url
Sometimes it helps to fix broken installation of any extension.

Quick Install Apache PHP Mysql for Magento on Ubuntu

Continue reading Quick Install Apache PHP Mysql for Magento on Ubuntu

How to add DNS record in Ubuntu/Linux

Point domain to unmanaged VPS/Dedicated server or add any DNS record in Ubuntu/CentOS

To serve DNS records we need to install DNS server package like BIND9
Update Package manager “apt-get update” or CentOS “yum update”

Install BIND9

or CentOS

Configure and Create Zone File for domains to add records
open file name.conf.local and insert zone file name for domain

save and close file.

Create Zone File for domain

To create name server and added NS and A records. replace with server IP

Now add and as child nameserver in domain register panel and also add in nameserver address in domain register.

To add another domain to same vps

Make jQuery colorbox plugin responsive

Use jQuery colorbox lightbox plugin in responsive design with some native colorbox options