Browser view for HTML file from vim

Are you a big FAN of vim. Do you spend a lot of time in vim and editing HTML files. OK then. So if you want to preview HTML file from vim continue reading.

Create a .vimrc file in your ~ (home) directory in case you don’t have it. Paste the following code inside of the file:

nnoremap <C-g> :!google-chrome %<CR> " browser preview with ctrl-p
nnoremap <C-f> :!firefox %<CR> " browser preview with ctrl-o
nnoremap <C-c> :!chromium-browser %<CR> " browser preview with ctrl-c

Now all you need to do is to source your file or type bash and then zsh again. Now all you need to do is for example press CTRL+f for firefox and preview your HTML file.

It has its own drawback though. Every time you press CTRL+f/g/c a new tab will be opened.

How to remove index.php in Yii

Intro

The purpose of removing index.php is to make URLs nicer and more user-friendly. It doesn’t affect your way of doing things. The difference would be:

http://www.bugx.ir/index.php/display/demo

to

http://www.bugx.ir/display/demo

 

It’s obvious that users feel more comfortable with the second one.

Remove index.php in Yii – Howto

You should be aware that handling URLs and mapping a URL to another is a matter of apache rewrite rules rather than Yii. What we want to do is to tell Yii to hide index.php in URLs and tell Apache rewrite module to map URLs.

You should enable rewrite module in apache. In ubuntu you simply need to use a2enmod:  sudo a2enmod rewrite.

Now restart you apache with:  sudo service apache2 restart

Create a .htaccess file in your root directory and paste the following code in your newly created file:

Options+FollowSymLinks
IndexIgnore*/*
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

The above command turns RewriteEngine on and checks if requested resource is not file or directory then maps that request to index.php.

Now all you need to do is to hide index.php in Yii. Go to YourYiiProject/Protected/Config/main.php and go to UrlManager section (Uncomment this part in case it’s commented) and add the highlighted line to your project:


'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),

Voila! Your done. Enjoy your clean URLs. ;-)

How to connect to MySQL through NODE.js and fetch our data?

Roll up your sleeves! We’re gonna get our hands dirty.

Although stableness is questionable in node.js, I’d like the async way node behaves unlike PHP. You can of course use PHP react to do the same thing, making PHP async but I love working with new stuff. And of course there are tools to make NODE.js more robust like forever module.

I assume you have installed node.js. If you want to work with mysql module you need to install it in node.js. Installing it is pretty straight forward. use node package manager(npm):

npm install mysql

Every module needs to be included in case you want to use it by require().

OK then what do you waiting for? include it in your project with some other modules that we’re gonna use:


var http = require('http');
var mysql = require('mysql');

We create a server with http module to send and receive our data with appropriate header (200, 403, etc).

You know better than me that mysql connection needs username, host, password,database. It makes no difference here. We just need to use createConnection() method to establish our connection:

As NODE.js rooted in java script, we use var to define our variable:


var connection = mysql.createConnection({
    host: 'localhost',
    user: "root",
    password: "",
    database: "bugxdb"
});

Here we are making a connection to bugxdb database and saving the resource inside connection variable.

Create an HTTP server as noted before to send and receive data (requests and responses). This server should listen on a specific port. My 8080 port is open so I use it.


http.createServer(function (req, res) {
    // we put all of our code here
}).listen(8080);

It’s easy right? I knew you would say YES.

Let’s suppose we have users table in bugxdb database. Now we put our query inside of a variable:


var uname='admin';

var query = 'SELECT email FROM users WHERE username=\'uname\' ';

A sample query to fetch admin email address.

Now all we need to do is to run our query with query() method and return the response.


connection.query(query, function (error, rows, fields) {

// when we're here and error is null it means voila! we ran query successfully!

});

Data will be populated inside of the rows input parameter. A pat on the back is only a few inches from a kick in the ass, as you have done all of this steps correctly you get the first one. Congratulations! ;-)

Send 200 OK header:

res.writeHead(200);
res.end(rows);

You may now ask how to test it? Fair enough don’t make me to do the second part on you (kick in the A**).

First of all let’s see our example as a whole:

var http = require('http');
var mysql = require('mysql');

var connection = mysql.createConnection({
host: 'localhost',
user: "root",
password: "",
database: "bugxdb"
});

http.createServer(function (req, res) {

var uname='admin';

var query = 'SELECT email FROM users WHERE username=\' uname\' ';

connection.query(query, function (error, rows, fields) {

// when we're here and error is null it means voila! we ran query successfully!
    res.writeHead(200);
    res.end(rows);
});
}).listen(8080);

Write this code in a file named bugxnode.js. And now run our nodejs file in shell as below:

nodejs bugxnode.js

Leave it there. Now point to your browser and go to http://localhost:8080 to see the results.

If you want to print a message in console write: console.log(‘your message’) I personally use it to debug my code in NODE.js code.

Feedspot.com – manage your feeds in one place

feedspot-homepageI’ve recently used Feedspot to manage my feeds. What I like most about this website is that you can discover new feeds inside it. It even suggests popular feeds that you can follow.

sidebar-feedspotAt the left side you can see my feeds from different websites and how many new feeds are waiting to be eaten/read.

Click on the browse categories to go to a whole new world in which you can get drawn inside of the websites ocean.

You can act like professionals by using the below keyboard shortcuts (press SHIFT+?):

feedspot-shortcuts

Right to the point tips, NO bullshit:

  • click the star at the right of the articles to see it inside Favorites folder.
  • Click add-new-site-feedspot and the enter http://bugx.ir/feed  or any other site’s feed then click add to follow site’s feed.
  • Use n/p or j/k for quick navigation

Feel free to tell us about your feed manager. Maybe yours is better! ;-)