plugin, wordpress

Announcing Release of “The Video Popup” plugin at WordPress Repository

My plugin “The Video Popup” got approved and is now available for download in wordpress repository. Its a light-weight plugin that generates a YouTube video popup when a page is scrolled to the bottom. You can check it out here:

https://wordpress.org/plugins/the-video-popup/

The next version of the plugin is expected to have:

  • support for vimeo
  • custom point of trigger
  • overlay video popup

Feel free to suggest more features in comments below or rate the plugin in the repository. ;)

Standard
Project Euler, ruby

Project Euler in Ruby

I recently started solving project Euler. I am using Ruby to solve these problems. My aim is to get results in optimum time. I try refraining myself from using brute force however I have used them couple of places where the sample data was limited and it did not make any considerable difference in performance.

Leonhard_Euler_2

In the process I also tried implementing a few mathematical algorithms like – Fermat’s Factorization and Quadratic Sieve wherever necessary. Its a great experience solving these problems. Given the nature of these problems it demands you to be intelligent in your approach. Many times its quite tempting to use brute force and I did that too (ended up restarting my crashed laptop).

And boy! its fascinatingly addictive. I’ve been digging wiki for countless algorithms, analyzing their pros and cons and selecting them accordingly for my solution – and not to mention coding them.

As Project Euler discourages posting answers online, I won’t be posting answers however I will be sharing my solutions. In the end of each solution I have posted Ruby Benchmark score calculated on my system.

Here’s the link to my GitHub repository:
https://github.com/meshivam/Project-Euler-in-Ruby

Its a work in progress, so feel free to fork it, star it and collaborate to make it better.

Cheers! :)

Standard
wordpress

The Video Pop-up Plugin: WordPress

This plugin is still not released. You can access the source code here: https://github.com/meshivam/the-video-popup-plugin

Its been long since I originally wrote this plugin, however I think now it would be nice to get it out in the wordpress repository and let it live its life!

This post serves as the formal introduction to the plugin. Let’s start from the basics.

What do you mean by video pop-ups?
A Pop-up launches when you visit certain websites. Their main aim is to try to catch the visitors attention and to bring something to their notice. As the plugin name suggests, it will help you pop-up videos on your site.

Currently the plugin supports only youtube videos. I hope to extent support for vimeo soon by the next version upgrade.

When is the pop-up triggered?
The pop-up is triggered when the user scrolls to the bottom of the page (footer). This makes sure user has least distractions on the site, only when he reaches to the end, he gets the pop-up. This makes its less annoying for visitors. However future version may provide customization over trigger.

How to setup the plugin?
Once you install the plugin to your site, you need to activate it. After the plugin is activated, you can find ‘Video Popup’  settings in your dashboard left pane.

Selection_045

Click on the ‘Video Popup’ setting button to get the settings page. As below:

Selection_046

By default the height is 325px and width is 420px. You can however define your own custom dimensions.

Once you save changes, the popup gets activated.

Selection_047

Users have the option of minimizing/maximizing the video.

Standard
Framework

Getting Started With Google Web Starter Kit

Yesterday (Friday 20 Jun 2014) Google released its web starter kit. Here’s the formal overview of the project (GitHub):

“Web Starter Kit is a starting point for multi-screen web development. It encompasses opinionated recommendations on boilerplate and tooling for building an experience that works great across multiple devices. We help you stay productive and aligned with the best practices outlined in Google’s Web Fundamentals.”

The first thing that comes to one’s mind is – ‘Is this a bootstrap or foundation alternative?‘.

As per the developers the web starter kit is a very basic boilerplate to get started on web development and it is not developed to compete with bootstrap, foundation or any other such framework.

I tried to develop a basic webpage using the web starter kit. The first thing you realize is its very light weight. Its built on node, ruby, sass and gulp. It was my first experience with gulp and have to say I was impressed. The way it organizes the website assets and helps in testing with various browsers is amazing. It even takes care of minifying your css and js files.

Getting started

Getting Web Starter Kit

Get the framework directly by cloning it from github.

git clone https://github.com/google/web-starter-kit.git

The working directory will be: web-starter-kit/app

Installing Dependencies

As mentioned above, web starter kit is built on node, ruby, sass and gulp, which means you need to have these on your system before kicking-off with the starter kit.

You can check the same with following commands:

node -v
ruby -v
sass -node -v
gulp -v

If these commands respond back correctly, you are good to go, else install them as follows:

Nodejs

sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Ruby (using rvm)

sudo apt-get install curl
\curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
rvm install ruby
rvm use ruby --default
rvm rubygems current

Sass

sudo gem install sass

Gulp

sudo npm install --global gulp

This will install Gulp globally. Next, install the local dependencies Web Starter Kit requires:

cd web-starter-kit
sudo npm install

Finally to build the project, go to web-starter-kit/app and run:

gulp

That’s it! We are good to go now.

Starting the server:

Start the server by typing:

gulp serve

This will load you application on the browser. With gulp serve running, start editing your application in a different tab and observe the changes instantly in the browser.

Here is the demo webpage I made using the web-starter kit. Clone it to get basic idea of how it works. Fork to contribute building a better demo app. :)

https://github.com/meshivam/Web-Starter-Kit-Demo

Standard
localhost

Taking localhost To Internet

There can be many situations where you may want to get your localhost to internet. I was working on a project recently that involved using stripe. When working with tools like stripe that involves money transfers you need to listen to all the events generated in the process. Solution to that is a webhook. However the problem is, when in development, webhooks cannot connect (POST data) to your localhost. Therefore you need a way to take your localhost (development environment) to the internet.

Other such instance can be when you are designing a website for some remote client. You have completed all the development in your localhost, but before hosting the site your client needs to review it. You again need to somehow take your localhost to internet so that your client who is sitting in the other part of the world can review it.  There can be many such occasions like these.

There are several tools available for this purpose. Some of the prominent ones are: ngrok, PageKite and ProxyLocal. I however use ngrok, so this post will explain only about using ngrok in the simplest possible way.

ngrok is simple to use and hardly takes a minute to get started. It comes both as a free as well as paid service, we however will focus only on the free service.  To get started, you need to download the binary file from here. As the official website says, “a single binary with zero run-time dependencies for any major platform” and that’s all you need to get started.

Download the file to any preferred location and unzip it. On unziping you will get a binary file named ‘ngrok’ and that’s it!

Now to get your localhost online simply run the file with the desired port number. In most of the cases the port number will be 80 (default HTTP port).  In such case run:

./ngrok 80

And done! Your localhost is now on the internet. The above command will output something like this:

screenshot

 

The address mentioned as Forwarding is the one you can use to access the localhost on the internet. In this case: http://16f3e567.ngrok.com

Similary say you are working on a rails project. As webrick’s default port is 3000, you will run:

./ngrok 3000

The output will be like:

ngrok 3000

 

Also you may notice, ngrok provides a web interface too that can be accessed on address:

127.0.0.1:4040

Stop the tunneling by: Ctrl + c

Hope this helps you! :)

Standard
wordpress

Solving WordPress Pretty Permalink 404 Error

While working on a project recently I came across a weird error. I was examining the wordpress taxonomy tables for slugs when I realized pretty permalink was not working for my localhost wordpress setup. On making a few google searches I realized people face this quite often and yet I had to google and experiment for about 30 more minutes before solving the issue, and therefore I decided to write this post.

wordpress-404

First thing to check:

When WordPress creates custom permalinks or slugs, it overwrites the server’s defaults setups in its own .htaccess file.  For those who don’t know what .htaccess file is, here’s a quick definition (wikipedia):

“A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. They are placed inside the web tree, and are able to override a subset of the server’s global configuration for the directory that they are in, and all sub-directories.”

In simple words you describe your site specific server configurations in this file. As wordpress does most of such technical things all by itself, you should ideally not be worried about what goes in this file. However there may be situations when wordpress is not able to create/modify this file due to file permission issues. Make sure this is not the case.

Go to the wordpress folder. In my setup (debian/apache2) I go: /var/www/wordpress

To list all file permission do:

ls -al

Incase the file is not present. create a .htaccess file using

touch .htaccess

Now make sure wordpress has all the authority to modify it. If you are in your local system, you can safely do:

sudo chmod 777 .htaccess

To make sure this worked, re-enable to pretty permalinks from wordpress admin panel, save the settings and open the .htaccess file. It should contain something like;

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Meaning wordpress is able to modify it. Check if your issue is resolved.

 

Step Two

If 404 is still haunting your posts it means the problem is beyond the scope of your wordpress directory. We now need to look for master server configurations. You can find them in your httpd.conf file.simpson404

Note:  httpd.conf is empty (or nonexistent) in some distributions.

That was the case with me, so we can edit apache2.conf instead. Typically you can find this file here:

/etc/apache2/apache2.conf

In the conf file, look for:

<Directory /var/www/>
   Options Indexes FollowSymLinks
   AllowOverride None
   Require all granted
</Directory>

As you can see the AllowOverride option is set to ‘None’, therefore it is blocking our .htaccess file to override the server configuration for our particular site. Replace ‘None’ with ‘All’ to fix this. conf file should now look like:

<Directory /var/www/>
   Options Indexes FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>

Now restart the apache server by:

sudo service apache2 restart

Check the links in the browser. As we just edited the main server config file, our links should start working.

 

Still No Luck?

There maybe be possibility that your issue is still not solved. One explanation can be that this master configuration is getting overridden somewhere. Check the ‘sites-available folder’ inside apache2. Here: /etc/apache2/sites-available

In 000-default.conf make the same changes as above i.e. setting AllowOverride All

Restart the server again and check the links in the browser.

Incase its not working yet, we come to the last thing that can go wrong. mod_rewrite is yet not enabled. To enable mod_rewrite for Apache do:

sudo a2enmod rewrite

sudo service apache2 restart

Check the links and they got to be frigging working now!!

Standard
linux

Creating, Exploding and Defusing – The Fork Bomb

A fork bomb is a simple, Japanese emoticon looking, notorious, malicious, destructive, yet beautiful code. The motive is simple – keep on eating the system resources until the system runs out of resources and crashes.

In unix and likewise systems fork is an operation where process creates a copy of itself. Basically fork is a primary source of process creating in unix(and likewise OS).

 

The BOMB

:(){ :|:& };:

If you try this on your terminal, your system may stall and eventually crash, proving the bomb did its work (i.e. exploded) successfully. This kind of attack is called Denial-of-Service attack. As the name suggests, the attack intends to make all the resources busy or unavailable to the authorized user, hence interrupting or suspending the service.

 

Logic_bombs_are_harmful_to_your_computer.

Understanding the Bomb

This bomb is essentially a function calling itself recursively and the pipeline is made background. That said, lets visualize our code in this format:

:()          # Define a function
{ :|:& };    # The body of the function
:            # Invoking the function

If its still not clear to you, here’s the thing, our function name is ‘:’. Lets replace it with something else, say bomb, to make our code more readable.

bomb() {
bomb | bomb&
};
bomb

The trick here lies in invoking the process recursively and putting it in background. The ampersand operator is doing that for us. Since the function is being called recursively it will keep on creating new processes  and background them which will eventually eat all the resources and crash the system. If we do not put the process in background and just keep calling it recursively, it will still mess up the system but all the processes will immediately end after a stack overflow, which any system can deal with easily. Making the process background, however makes it immortal.

 

Defusing the bomb

The problem with this program is that even if you get all the PIDs and run a kill command, by the time the command executes many new child process will get created, which makes it difficult to stop.

One way is to freeze all the processes and then running a kill command. This can be done as follows:

killall -STOP processWithBombName   # Freezes all the notorious processes
killall -KILL processWithBombName    # Kills all freezes processes

However, there’s obviously a time constraint after which nothing can be done except a reboot!

Standard