Knowing how linux works is really an important skill to have, as a website developer you'll often have to use linux operating system, install GUI, setup web development or general environment where you can run a web server, we all know majority of servers run on linux OS so keep that in mind too.
Website I'm about to introduce to you really makes learning linux commands and get basic idea of OS pretty simple for beginners. Linux might seem complex but you'll really be using same commands over and over again. The most important thing to understand how it work and differ from yur day to day operating system, once you understand that, it'll just come down to googling for commands and executing them.
You gotta know what Kernel is.
Kernel is a nothing but a program that helps hardware interact with software. So basically there's applications, then Kernel in the middle and hardware and other devices at the bottom. It's a basic layer model.
Do you know what a shell is in linux?
Shell is just an interface like you've in windows, it's basic screen with text written on it where you can enter commands. If you don't like shell you can just install some interface and use it instead. But shell give you more flexibility and it's must you know how to use it. There's plenty of shell softwares available for linux, common one is BASH.
You'll keep hearing about UNIX
Unix is an old operating system that linux is based on.You could say Linux OS is version of Unix OS. That's pretty much all you need to know.
That's basic info there, you can learn more about linux here interactively
http://linuxsurvival.com/wp/?page_id=5&id=0
Saturday, 23 January 2016
Writing clean code PSR standards
Writing clean code is all about following conventions and standards that are generally understood by others. Imagine writing a program and sharing the source code with other developers out there, they will often go through your code and start scratching their head wondering what the hell this chunk of code does, trying to fix something they break everything else. Writing clean and tidy code is all about not making them tightly coupled(shouldn't depend on each other so badly that it breaks entire program if something's missing), write clean code that a somewhat experienced program should be easier able to read and undnerstand, and finally follow coding standards. I personally follow PSR 0, 1 and 2 standards.
PSR 0 is about auto loading and class names
PSR 1 is basic coding standards
PSR 2 extend and contrinues talking about standards.
Before you start reading PSR standards it's important you know what you must do, what's just a recommendation etc.. generally most standards use certain words what they mean is defined in RFC 2119 document http://www.ietf.org/rfc/rfc2119.txt
Once that read you should start reading the standards starting from 0. It's upto individual needed but those first 3 are must for anyone.
Example(Code must not product side effects, it should either declare class/functions or produce side effects - change variable value, echo something etc), if you're including a file it shouldn't just run and echo stuff on screen and run methods etc.. it should do one or another.
What you shouldn't do:
// side effect: change ini settings
ini_set('error_reporting', E_ALL);
// side effect: loads a file
include "file.php";
// side effect: generates output
echo "<html>\n";
// declaration function foo() {
// function body
}
Declare function is okay but echoing HTML in same file is not. Should only have function declaration in one file and other stuff in another. Upon including the file, your class shouldn't start executing unrelated logic that affects other code on page.
// declaration
function foo() {
// function body }
// conditional declaration is *not* a side effect
if (! function_exists('bar')) {
function bar() {
// function body
}
}
You can read more about accepted PSR standards
https://github.com/php-fig/fig-standards/tree/master/accepted
PSR 0 is about auto loading and class names
PSR 1 is basic coding standards
PSR 2 extend and contrinues talking about standards.
Before you start reading PSR standards it's important you know what you must do, what's just a recommendation etc.. generally most standards use certain words what they mean is defined in RFC 2119 document http://www.ietf.org/rfc/rfc2119.txt
Once that read you should start reading the standards starting from 0. It's upto individual needed but those first 3 are must for anyone.
Example(Code must not product side effects, it should either declare class/functions or produce side effects - change variable value, echo something etc), if you're including a file it shouldn't just run and echo stuff on screen and run methods etc.. it should do one or another.
What you shouldn't do:
// side effect: change ini settings
ini_set('error_reporting', E_ALL);
// side effect: loads a file
include "file.php";
// side effect: generates output
echo "<html>\n";
// declaration function foo() {
// function body
}
Declare function is okay but echoing HTML in same file is not. Should only have function declaration in one file and other stuff in another. Upon including the file, your class shouldn't start executing unrelated logic that affects other code on page.
// declaration
function foo() {
// function body }
// conditional declaration is *not* a side effect
if (! function_exists('bar')) {
function bar() {
// function body
}
}
You can read more about accepted PSR standards
https://github.com/php-fig/fig-standards/tree/master/accepted
Wednesday, 13 January 2016
How to get a domain name almost for free
Get discount on domain names
Web developers often create website for themselves when starting up a new project, it can be pretty expensive if you're working on projects one after another and buying new domain names. One of the way to get a cheap domain names is to find and test best coupon for maximum discount.It's not always that easy to search web and find best promotional codes. More often than not it's a complete waste of time.
JoinHoney is a free plugin that finds and gives the best coupon code that you can use withing a few seconds. Say you're using godaddy for new domain, just choose whatever domain name you'd like and open the basket. It will show you the total, form there you can either add a promotional code or proceed to checkout. Now click on JoinHoney icon on top right of screen and click 'Try Codes'. Once that's done you should get the best working coupon for discount. Just apply the coupon and discount will be applied.
Click on 'Add' to add a promotional code/coupon.
Tuesday, 12 January 2016
How to install a program on Linux VPS
Install third party program on VPS
Installing programs on linux really isn't a big deal, just like windows OS if you understand Linux it's a piece of cake, don't let linux command line Shell intimidate you!Here's basic steps you would need to follow to install a software on linux VPS.
- Login to your server using Putty. It's a software for windows that gives you access to Shell. Shell's is just a command line for linux where you can execute commands, except it encrypted all the data.
- You can find your login info in hositing access panel.
- Next download PSCP, Putty Secure Copy. It's a file transfer software.
- SET environment variable so PSCP can be called from command line. Read how to set environemnt variable http://www.computerhope.com/issues/ch000549.htm
- Now run just run pscp.exe PATH_WHERE_FILE_IS_IN_YOUR_PC LINUX_USERNAME@HOSTNAME WHERE_SAVE_ON_LINUX
Ex. pscp.exe c:\files\file.exe webdevtown@my-ipaddress:/home/webdevtown
From here you should follow Author's instructions. You might be required to install java or extract file and run make file command etc..
Thursday, 7 January 2016
OAuth Explained with real world example
OAuth's an authorization standard to access user information from a website that user is member on, without the need to know that user's password.
Problem
Imagine your friend comes up with a website where users post their pictures so others can rate them. He wants users to be able to get all their Facebook picture so they can be processed and uploaded onto his server or linked on his website for others to rate.
Facebook API allows website like this to have access to LIMITED information about user that he/she has granted, but due obvious security reasons facebook cannot allow everyone to access anyone's information. This information's only accessable when user himself grants you access to it.
To get access to user information you would need access to particular facebook API code to which you've been granted access.
Here's a general flow.
1. Your server/client application communicates with OAuth endpoint to make sure you're who you say you are. During this process your client id is being checked. If same client is used on different website google will throw an error. This process doesn't require any action from user side.
2. You send user to authorization page where user allows or denys permission you're asking for. If user allows it, you're sent back to redirect uri with 'Authorization code'.
3. 'Authorization code' now can used to get an 'access token' that you can exchange with server to get user info. Auth code is not sent alone, it's sent along with your secret ID, scope(info you want access to) and redirect URI..
4. Now if you asked user to give permission to access their pictures in step 2. You can use 'access token' to get their pictures and use them on your website for users to rate.
Wednesday, 6 January 2016
How to add google map to website
Embed Google Map to your website
Google map's something that business websites must always have. It's much more convinenent for users to look at map and find where you're located than to get the address, copy paste in google maps and try figuring out if it's the right place. All this is a hassle, if a customer likes your product, there's chances that'd want to visit your place. Don't forget the fact not everyone knows about google maps, or how to check address on online maps.We're going to use 'Google Maps Embed API' to create a map follow these steps:
1. Get your key for google Maps API. To get the key create a new Google Developer project and follow the instructions. When done you should get the Api key. Copy that.
Developer console https://console.developers.google.com/
2. Visit map building area and choose and fill necessary information
https://developers.google.com/maps/documentation/embed/start
3. When done click on 'Looks good', enter your API key and press 'Okay.
3. Google then will give you some HTML code that you'd paste into your website.
4. Copy paste the code in to your website and you should have your own map on your website
Monday, 4 January 2016
Check the Apps that have access to your information and revoke access
Revoke access to app
Just a quick little info about websites storing your details. OAuth gives web developer access token that can be used to access your information that you granted access to when trying to access an app online, sometimes you want to revoke the access as you no longer use their service. Note that you're just revoke that app access, usually developers store all your information in DB on your first login.To check who you're sharing info with:
1. Go to https://myaccount.google.com/
2. In 'Sign in & Security' Tab click 'Connected apps & sites'
3. Under the 'Apps connected to your account' section click on 'Manage apps'.
4. Now you can click on any app and revoke the access. When you click it will also show you the stuff that the app can do on your behalf.
For example, here fiverr app has access to:
-My basic account info
- Age
- Language
- List of people from circle
- Basic profile info
Sunday, 3 January 2016
Decision making if/else in batch programming
Decision making's very important in any programming, not just batch. It allows your program to decide what to do. Here we're going to create a small program where it asks user for password and allows of denies access depending on whether password's right or not.
Here's if statement structure in batch
if CONDITION (
do this
) else (
do this
)
To compare two numbers we use double equal signs '=='. Lets ask our program if 1 is equal to 2.
if 1 == 2 (
echo 1 is equal to 2
) else (
echo 1 is not equal to 2
)
It returns whatever we put in else because 1 is obviously not equal to 2.
Here's our complete script where
1. Turn command display off
2. Get user input and store it in password variable
3. Use if/else statement you just learned. It will only allow access if password is 'webdevtown', anything else it wil echo 'access denied'.
4. Pause so program doesn't exit.
@echo off
SET /p name="Please enter password "
if %name%==webdevtown (
echo Access granted
) else (
echo Access deinied
)
pause
Here's if statement structure in batch
if CONDITION (
do this
) else (
do this
)
To compare two numbers we use double equal signs '=='. Lets ask our program if 1 is equal to 2.
if 1 == 2 (
echo 1 is equal to 2
) else (
echo 1 is not equal to 2
)
It returns whatever we put in else because 1 is obviously not equal to 2.
Here's our complete script where
1. Turn command display off
2. Get user input and store it in password variable
3. Use if/else statement you just learned. It will only allow access if password is 'webdevtown', anything else it wil echo 'access denied'.
4. Pause so program doesn't exit.
@echo off
SET /p name="Please enter password "
if %name%==webdevtown (
echo Access granted
) else (
echo Access deinied
)
pause
How to get user input in batch
Get user input
You'll often need to get some soft of input from user that you can process and perhaps return some data back to user.To syntax to get user input is 'SET /p yourName=[PROMPT MESSAGE]'
Type that in CMD and press enter, then type your name in and press enter again. Now as you'd expect, your name's been stored in 'yourName' vairable, now you can retrieve it.
To see that name user enter. echo the variable 'yourName', note that variable name must between % percent sign, like %variableName%.
Alright, lets ask user for his name and tell him nice to meet you with his name at the end.
Here's how we'd go about it.
1. First off lets disable commands from appearing on screen using command '@alerts off'
2. Prompt user to enter his name using 'SET /p yourName="Enter your username "'. The reason I've surrounded Enter your name with double quote is to add little bit of space after 'username' to when user enter his name there's space between 'username' and his name.
3. Write back to user 'Nice to meet you HIS NAME' by calling the variable 'yourName'
4. Pause so it doesn't exit
@echo off
SET /p name="Please enter your name "
echo Nice to meet you %name%
pause
How to loop in batch programing
What is loop and how it works
Loopping is when you need to do a certain task again and again.Lets say your friend's been pissing you off lately and you decide to annoy him by creating a little prank virus that open a program again and again until the process is terminated.
Lets start, lets open notepad once.
You can open any program in your computer by using start command. 'start' command executes a program that's in front of it. You can also use full path to that program. If you save following code in batch file and run it you will see notepad opening.
start notepad.exe
Goto loop
Go to loop uses label to repeat itself. What's inside loop commands will execute. Having notepad.exe inside 'goto' loop will make notepad.exe open again and again.To start loop we define a label. Label's a part of code where loop starts, and goto is a command that tells CMD to go back to where the label is. Let me give an example to make it clear:
1. We define ':label'. Note label must have ':' color before it's name, and it can be named anything.
2. We tell it what to do while it's looping(loop body)
3. We tell it to go back to label.
:thisIsLabel
echo hi
goto thisIsLabel
Above code will echo 'hi' until CMD is closed.
Same thing can be done for our little notepad.exe prank. We replace 'echo hi' command with our start command and name of program that you'd want to open.
Back to batch basics
Saturday, 2 January 2016
Favorite websites opener
Quickly load your favorite websites with one click only
Well this is a little bot I created for myself, thought this may be useful for others too. Basically I often create threads on different forums about certain stuff, and when I come back from work or something I wanna open all those threads quickly as possible. So I wrote this little batch script this will open all the links in the file.
Source code
@echo off
echo For more bots or website development tutorials visit www.webdevtown.com
color 05
start firefox.exe
TIMEOUT 5
start www.google.com
start www.youtube.com/feed/subscriptions
start www.codernation.net
pause
How to use(firefox needed*)
Download
https://dl.dropboxusercontent.com/u/28490184/webdevtown/Favorite websites opener.bat
Virus scan
https://www.virustotal.com/en/file/f5a6c646d83ca926ca0eb2590fae57902be90142a8a02c94f3615f32c4c73736/analysis/1451781744/
https://www.hybrid-analysis.com/sample/f5a6c646d83ca926ca0eb2590fae57902be90142a8a02c94f3615f32c4c73736?environmentId=4
Well this is a little bot I created for myself, thought this may be useful for others too. Basically I often create threads on different forums about certain stuff, and when I come back from work or something I wanna open all those threads quickly as possible. So I wrote this little batch script this will open all the links in the file.
Source code
@echo off
echo For more bots or website development tutorials visit www.webdevtown.com
color 05
start firefox.exe
TIMEOUT 5
start www.google.com
start www.youtube.com/feed/subscriptions
start www.codernation.net
pause
Download the program, right click and edit.
Download the program, right click and edit.
Download the program, right click and edit. Write 'start WEBSITE' where WEBSITE is URL of site you want to open. One URL in each line.Download
https://dl.dropboxusercontent.com/u/28490184/webdevtown/Favorite websites opener.bat
Virus scan
https://www.virustotal.com/en/file/f5a6c646d83ca926ca0eb2590fae57902be90142a8a02c94f3615f32c4c73736/analysis/1451781744/
https://www.hybrid-analysis.com/sample/f5a6c646d83ca926ca0eb2590fae57902be90142a8a02c94f3615f32c4c73736?environmentId=4
Subscribe to:
Comments (Atom)



