Feb 26

Some Neat MVC4 Features

Hello Folks,
As I was playing around with MVC4 Beta and watching some of the hype and the presentations about it – I wanted to share with you some of the features that I’m mostly excited about.  These I think would directly come into play. I’ll share my opinion about them and give you few tips on how to use them y0′
Btw if you still haven’t tried it – you can do so at:  http://www.asp.net/mvc/mvc4

Here is the list:

  • New WebAPI using REST
  • View Switcher Component
  • Mobile specific views
  • Inbuilt bundlers and minifiers for JavaScript and CSS
  • Inbuilt Ajax Scaffolding plus cool looking default template
  • Recipes

So here we go… :)

Recipes

recipe

Basically the recipes would give us the option to automate processes inside of our application. To create a recipe you would need to create a class library and implement IRecipe Interface.

There is also a package that would make it easier for you to create recipes made by Phil Haack – AspNetMvc4.RecipeSdk. You can install it using Nuget – press Tools->Library Package Manager->Package Manager Console and then type: “Install-Package AspNetMvc4.RecipeSdk”.

I recommend you reading the whole blog post on how to create recipes  at  Haack’s blog:

http://haacked.com/archive/2011/09/21/writing-a-recipe-for-asp-net-mvc-4-developer-preview.aspx


View Switcher Component

This is very neat feature that would basically allow us to use jQuery Mobile for rendering our website! In order to use this we would need to install the following package using the package manager:

In the package manager please type:  Install-Package jQuery.Mobile.MVC
This will add automatically the jQuery.Mobile.MVC and few other references to your project. Also in the default View’s shared folder it will add 2 additional files:

Here is how _ViewSwitcher should look like:

It basically detects if a mobile version of the view should be passed to the client or not! If you directly let jQuery to do everything for you – your page could be translated into something completely different, like this:

Note that the styles of your website would be completely overwritten by jQuery mobile, and would be defaulted to cleared black/gray functional UI.
This – could look ok for you. At least it looks functional and easy to click etc.  - however if you want to preserve the original feel – colors and styling of your website – you should definetely make your own Mobile specific views.

Mobile specific views
This feature is the one that comes most straight forward – and basically is the easiest to use.
Simply rename your existing or create a new view with the follwing convention:

Basically you need to rename the view inside of your view folder from “ViewName.cshtml” to “ViewName.mobile.cshtml”. In ViewName.mobile.cshtml you should optimize the page for mobile device, you could change a couple of css selectors, use partials etc.
Now when the request for this view resource comes from a mobile device – the ASP .NET will automatically pass your mobile version of the view overriding the jQuery mobile’s default styling.
That’s it – no strings attached. You could simply decide to do this for several or all of your views – depending on what you want to achieve. Or if you are too lazy you could leave all the view styling up to jQuery mobile – it’s all up to you :)

Inbuilt bundlers and minifiers for JavaScript and CSS

So this is one of the features that it would be so easy to benefit from. By minifying your js and css files you gain could performance of your website, because any white-space and newline is removed.
Also it makes it extremely easy to include additional js files and css files into your project. By now you had to add a “<link href=… or <script src=… for each file. Now you can do this:

<script src=”~/Scripts/js”></scripts>
<link href=”~/Content/css” rel=”stylesheet” />

Voilla – all the css files inside of Content/css and all files inside of /Scripts/js are added to your website.

You can also use:  @System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl

 <script src=@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(”~/Scripts/js”)></scripts>
 <link href=@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(”~/Content/css”) rel=”stylesheet” />

The second option using Bundlers  will create a hash code in similar format:

<script src=”~/Scripts/js?fsdofso18eh1he9whd91”></scripts>

The generated hash will be different every time you change a js file inside of the Scripts/js folder. This way you will be always sure that the client always gets the lastes version of your css / js files. New hash-code  is generated only when you change / add something – this means that you havent changed anything in your js/css files and they will cached. Pretty cool huh :)
According to Scott Gu – there will be a helper with shorter syntax in the final version of .NET 4.5 (no kiddin :) ) Also the bundlers would be able to convert higher level languages like CoffeeScript directly into JavaScript!

The only bad thing is that you won’t be able to use this features with VS2010 and .NET 4.0 you will need to wait for VS2012 – or download the beta of VS2011 from here:
VS2011 Beta Offline Download

I’ll try to finish this post – adding info about the Inbuilt Ajax Scaffolding  and the updated default template in the next few days!

Peace

Jan 02

Using git and GitHub on windows machine

For a while I was using git and github for uploading my code and projects. ( In case you yet not familiar with it – github is really a great place for storing your code and collaborating/ sharing your work with others, so please check it out.)

I was using Ubuntu OS and ofcourse – on Linux machine git is basically installed with a single command and SSH keys are created very easy.

Windows users had the option for using stuff like cygwin, to be able to get the git functionality under windows, which at some point could be a little anoying for the GUI type of guys :) …Well  not anymore!

After switching back to windows I was amazed how much TortoiseGit has improved for the last few years, and how easy it is now for the windows users to use git :)

In this tutorial I’ll cover the following:

  • how to install everything you need to setup Git and TortoiseGIT on your lovely Windows OS.
  • how to generate a private key with PuttyGen and set this up on your github account
  • how to initially create your repo at github and clone the repo to your local machine

OK – lets do this !

Dec 13

finally blog update :)

Hello fellas,

I hope you are doing great!

I’ve also enrolled in very good programming course at Telerik Academy, so that I could refresh some of my C# and ASP .NET MVC skills. The lecturers there are really great people, and unlike the University – man can really learn some usefull practical stuff there.  I’ve also enrolled in SEO course in the same academy.

In this line of thoughts in the upcomming few months I’ll be writing tutorials and lessons about C# Programming and ASP .NET using MVC 4. PHP & Ruby on Rails tutorials could wait for now :)
I’ll try to write  2  per week. So if you want a help at specific topic related with C# or ASP .NET just let me know!

Cheers!
Georgi

Apr 29

Full backup of website’s mysql database using cron job

The MySql database backup website backup is very similar to the previous backup that I showed you 2 days ago. We are going to create a php file that is going to dump our database into filename with the current date and time.

Ok so let’s get going:
1. Create the file “backup_database.php” and input the following code into it:
<?php exec(‘cd /home/your_user/backup/db/;mysqldump –add-drop-table -h localhost –user=your_user –password=your_pass database_name > `date +%y-%m-%d_%H-%M`.sql’); ?>

Sometimes the path to your home dir looks different than ‘/home/your_user/’, so execute the ‘pwd’ command like explained in my previous post

Here we use the command mysqldump in a tutorial that I wrote previously about the dumping the sql database from one host to another. Now the database will be saved directly on the server that is hosting your website

Apr 26

Website file system backup using php and cron job

Hello guys and ladies,
Long time no see :) . Today I’m going to show you how to make a php script to perform full website backup the script can be executed via http request or via ssh shell or like a cron job .
We all know about the most standard way to add backup for your website maintenance for example using the Cron Jobs in the CPanel. If you already don’t know this – if your hosting provider does support CPanel you should be able to access it via this URL: www.yourwebsite.com/cpanel
Cron Job CPanel

May 10

HTTP, HTTPS, and SSL via PHP

Today i found this very cool tutorial regarding the using of using ssl with PHP.

I’ll copy here the most interesting of it.

HTTP with PHP Sockets

// don’t need to specify http, it’s the default protocol
$hostname = “www.google.com”;
$port = 80;

// create and configure the client socket
$fp = fsockopen($hostname, $port); // optional: $error_number, $error_string, $connect_timeout
if ($fp) {
stream_set_timeout($fp, 30); // seconds to wait for i/o operations

// send request headers
fwrite($fp, “GET / HTTP/1.1\r\n”);
fwrite($fp, “Host: $hostname\r\n”);
fwrite($fp, $additional_headers); // Accept, User-Agent, Referer, etc.
fwrite($fp, “Connection: close\r\n”);

// read response
$response = “”;
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
echo $response;

// close the socket
fclose($fp);
}

Apr 17

mysql copy entire database to remote host

I needed to create a backup on my mysql database on remote host. I found out that there is a way that you can actually do that with mysqldump :) . I didn’t believe that it will be so easy but i decided to give it a try. After all the stuff i read on the net about it there was’nt a single working example of it – so after some testing i managed to do it :)
so here it is:

first i will show you how to use mysqldump to backup your database on your harddrive on your local computer under windows. Go to your command prompt -> Start -> Run -> write “cmd” -> hit enter
go to your mysql bin directory, in case that you use xampp, and it’s installed on c:\xampp, it should be in c:\xampp\mysql\bin
you can do that by typing “cd \” and then “cd xampp\mysql\bin” (i’m trying to write this tutorial as simple as possible so that everybody will get it :) )

after that, to backup your database on local mashine you should write:
mysqldump –add-drop-table -h localhost –user=root –password=yourpass yourDBname > OutputFile.sql

voilla :)

so if you want to backup your database to remote host the command gets a bit more sophisticated ;)
here we go:

copy databse and it’s data from one server to another:
mysqldump –user=root –password=yourPassword –opt localDB | mysql -h 192.168.1.35 –user=root –password=remotePassword remoteDB

In our case we copy our local database “localDB” into the database “remoteDB” on the machine with 192.168.1.35

we can also do the command like this:
mysqldump -h 192.168.1.17 –user=test –password=12345 –opt remoteDB
| mysql -h 192.168.1.51 –user=root –password=bg_820918 remoteDB

in this case we copy the database “remoteDB” from remote host to another remote host in the database “remoteDB”

now you see how powerfull mysqldump really is, and that’s only few of the things it’s capable of :)
I hope this will was usefull for someone :)

Apr 08

Simple script to feed your site with some RSS that you like ;)

Hello fellas,  because these days i had a case where i had to include some RSS feed on my site and i needed a very simple and fast solution in php how to do it i was very dissapointed from what i’ve found on the web. There are all kind of widgets, tools PHP scripts using the xml-reader class, whatever – but i just needed some very simple solution. So ofcourse i had to write it myself at the end :)

in this example i’m going to import feed from yahoo’s technology news rss:

Mar 30

Simple Object Oriented aspects PHP

I’m going to talk about some good object oriented practices for small/medium projects. The object oriented programming itself will save you enourmous amount of time. The inheritance is part of the Object Oriented Programming (OOP) and is very good thing that is going to save you even more time when you start to use some object oriented model in your programming.

Let’s say we need to have some root class – lets say “Base”, with the __construct() (the class’s constructor) – notice that since PHP 5.0 the constructor of a class is defined in __constructs(), instead of “the-name-of-your-class”(). Anyway you can define the constructor information in Base() as well, but better do it in __construct, because you don’t know if there will be support for the old PHP 4 constructors in PHP 6 :)

so let’s get on business..

Mar 19

Dynamically (on request) Resize Images with PHP

Hello :) today i’m going to talk about resizing your the images in your site.
So let’s say for example that you have a CMS system – like Joomla for example. In the administration you usually have functionality like – uploading images and linking them in your content.
But often the problem with that is that usually the customers will upload too large images (copied in raw jpeg directly from their cameras) and when they link them to the content of their website, it get’s really messy.
Anyway you can fix this by writing some script that directly resize the image to some resolution like 500px/* for example, but what will happen if you want to put lightbox or something other to show the image in large resolution, or you just want to put some function to download the original file etc. You simply can’t because the image was resized at the moment it was uploaded on the server.

How about dinamically resize the image at the very  moment that client requests it?

So that way we wont have a big image that the client has to download, and at the same time we will still have the original, good resolution copy of the image, in case that we need it. We can also use the following PHP script for creating thumbnails.

Well – as you will see below it’s not hard at all to do it,  i mean not hard at all :)

Mar 12

Alien Hominid | flash arcade game

This is metal gear solid kind-a game W. i highly recommend it if you have’nt tried it before. You come in the role of the bad alien that kills FBI agents, and in the same time unknown why you must have to kill all sorts of weird robots etc. This is very classic game so don’t miss it ;D

alien arcade flash game

if you want to play the game – click the link below:

Mar 11

Shibaku – some realy smart and logical japanese game

If you see the image first – u will probably think – oh no this is some kind of sims flash game, or something like tycoon game where i have to build things and make money etc.
Nothing like that – Shibaku can’t be compared to any other game – in shibaku you can decide which technologies to develop more than others, and from that point on you have dozens of different scenarios in which the game will develop. Anyway if you choose good way to develop and grow your town you can get to level 10 and beat the game – unfortunately i just got to level 9 after million different scenarios :D Just give it a try – u won’t regret it :)
shibaku
To play the game click the link below .

Mar 09

Export / Import Excel file to sql / database using CSV and PHP

Hello everybody,

today i’ll be talking about how to export / import your Excel file into you your database using the PHP and the CSV file format.
First of all we need an Excel file with our data.

Every row of the excel file should be the same format as the previous row (so that we can make our life easier), for example if we want to import a excel file with name/url addres corresponding to this name we should have our excel file in a format like this:
exel file example
After u have the file in this excel format u should hit -> File -> Save as -> CSV (Comma Delimited) or more ofter its Called “Comma Separated Values”. For the comma separator use “;” if it asks you. So after you save the file in the CSV file format you should have something like this after you open the file with notepad etc.:

Mar 08

Get your freak on with SSL and Apache :P

for everybody who is just starting to learn about the SSL оpportunities that you have with Open SSL (tool) and the mod_ssl for Apache for securing your site. The simplest and fastest thing that you can do is to create a self-signed certificate, after you generate a free RSA key :) . Don’t worry it’s not so sophisticated as it sounds :) actually it’s pretty easy. You can read more on the link below
ssl graph

Securing an Apache 2 Web server can be an intimidating prospect for those new to secure sockets layer (SSL) certificates. However, this need not be the case. SSL secures Web server to Web browser connections. Read on to better understand SSL certificates, learn how to set them up on Apache and launch your SSL-enabled site.

Mar 08

Happy international women’s day

Don’t forget it or ur girlfriend will be really mad at you :D
And for all bulgarians happy Baba Marta with some delay :D (for all that don’t know what “Baba Marta” is – the chick below is one of the Baba Marta’s work girls – something like the Santa Claus and his work elfs ;)
so enjoy

Mar 07

Visual SVN Server under windows

Hello everybody :) it’s been a while since my last post, i actually almost forgot that i have a blog :P just kiddin doll :) anyway – from now on there will be every day updates on the topics that you are interested the most :)
And now let’s get to the point…
For everybody that uses Apache/Php/Mysql or Xampp under Windows is good to have a repository server to store their projects, update and commit their work etc.
installing the svn server

I’ve been using so far SVN server that you can install directly with your current Apache configuration, but to do so you have to install svn server, modify the httpd.conf to set up the SVN directory, and then write some lines in the cmd window so that you can create a service which is able to start the svn daemon automatically, so that you dont have to start it everytime you want to use it :P
if you are interested to do the thing the hard way – be my guest :) , follow the tutorials in the URLs below and you should be fine :)

However recently i updated to Windows 7 ( win7 ) beta 7022 which is actually pretty stable OS, and behaving much better than the shity Vista :P . So i had to reinstall the SVN all over again, which if you are lazy person can be pretty boring:)

So i found the Visual SVN Sever:

installing the svn server

http://visualsvn.com/server/

after some searching i found pretty damn good easy to understand tutorial in which even if you havent using it before, most probably you will get everything on ;)

so – check it here

http://rajibmahmud.wordpress.com/2009/01/09/work-with-visual-svn-server-tortoise-svn/

the Visual SVN will create separate apache process and will manage your repository via https (you have to write https://server-name/main-repository-name/your-project:port) insted of svn://server/project-name but i guess it’s ok cuz almost everything is done automaticaly. The only thing you have to config are the User rights and passwords etc :)

Nov 23

ScottGu’s Using LINQ to SQL (Part 1)

Georgi Mitev blog LinQ to SQL

Developers can use LINQ with any data source. They can express efficient query behavior in their programming language of choice, optionally transform/shape data query results into whatever format they want, and then easily manipulate the results. LINQ-enabled languages can provide full type-safety and compile-time checking of query expressions, and development tools can provide full intellisense, debugging, and rich refactoring support when writing LINQ code.

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

Nov 22

50 Excellent AJAX Tutorials

#

http://www.smashingmagazine.com/2007/01/26/tutorials-round-up-ajax-css-javascript-php-mysql-and-more/
AJAX provides Web developers with plenty of opportunities to enhance the user experience and improve the performance of their websites. There are countless ways that AJAX can be used, and fortunately there are plenty of good and useful AJAX tutorials out there to help you with your own implementation.

This post serves as a collection of useful tutorials on working with AJAX in a wide variety of ways. You’ll find tutorials on working with forms, building shopping carts, creating chat features, working with log-ins and usernames and much more.