How To Use Rails and Twitter Bootstrap to Start a Simple and Beautiful Blog

Ruby on Rails, often shortened to Rails, is an open source full-stack web application framework for the Ruby programming language.
Twitter Bootstrap is a free collection of tools for creating websites and web applications.
Today I will use Rails and Bootstrap to start a blog web application, just a few lines of command, you can create a simple and beautiful blog web, now let's start.
First, open the Terminal, we have to create a new rails application named blog.
    rails new blog
then we use scaffolding to create a post scafflod and connect to the database.
cd blog
rails generate scaffold Post title:string content:text
rake db:migrate
then we add the bootstrap to the application, open the Gemfile in the blog forder, and add the gem.
group :assets do
    gem 'twitter-bootstrap-rails'
end
then we run the command to install the gem.
bundle install
and it is time to use the bootstrap make the application look beautiful.
rails generate bootstrap:install static
rails g bootstrap:layout application fixed -f
rails g bootstrap:themed Posts -f
at last, you have to open the web server
    rails server
Now, just enjoy you blog application in your web browser through http://localhost:3000/posts

How To Make A Console Program Launcher

create a new project and select console application and name it whatever you want , this a simple tutorial to create a application launcher using console , this works like this : when user input the application name and press enter the application will launch if the application exist

i typed soundrecorder.exe and pressed enter so you can see sound recorder is been launched
if the application name is wrong then
lets make the program , create a new project and select console application and name it whatever you want, codes below


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

//Author : Mohamed Shimran
//Blog : http://www.ultimateprogrammingtutorials.blogspot.com

namespace Launch_Application

{
        class Program

        {
                static void Main()

                {
                        String txtApp;
                        Console.Write("Option: ");
                        txtApp = Console.ReadLine();
                        try
                        {
                               Process.Start(txtApp);
                                Console.WriteLine("Application: " + txtApp + ", Launched!!!!");
                        }
                        catch (Exception ex)
                        {
     Console.WriteLine(ex.Message);
                        }
                        Console.Read();
                }
        }

}

now debug , your done

How To Make A Simple Console Application In C#

this is a simple program to separate 6 digits from input, first you create string and name it (shim)  and you prompt the user to enter the number using console.write(); then you assign the user to input shim using the console.readline function so on you display each display/character using writeline , in this the argument comes after the comma in this argument

Console.WriteLine("First digit: {0}", shim.Substring(0,1));
shim.Substring(0,1) 

shim.substring(0,1) , when you use susbstring its going to read the string which is , the user input

console.readkey(); will keep the application awake

lets make the application , create a new project and select console application and name it whatever you want , add the codes below
using System;

namespace simple_console_application

{
        class Program

        {
                      static void Main(string[] args)

                {
                        string shim = "";

                        Console.Write("Enter a 6 digit Number: ");

                        shim = Console.ReadLine();

                        Console.WriteLine("First digit: {0}", shim.Substring(0,1));

                        Console.WriteLine("Second digit: {0}", shim.Substring(1, 1));

                        Console.WriteLine("Third digit: {0}", shim.Substring(2,1));

                        Console.WriteLine("Fourth digit: {0}", shim.Substring(3,1));

                        Console.WriteLine("Fifth digit: {0}", shim.Substring(4,1));

                        Console.WriteLine("Sixth digit: {0}", shim.Substring(5, 1));

                        Console.ReadKey();
                }

        }
}
now debug and see how it works , enjoy

How To Generate Random Numbers In C#

This is a simple tutorial
   
Random random = new Random();
int num = random.Next(1, 100000);
it generate numbers between 1 - 100000 , you can also change them . if you want to generate numbers between 1 - 500
you can use this
   
Random random = new Random();
int num = random.Next(1, 500);
just a simple change
make a new project and add a label and a button and use this code to generate random numbers
  
  private void button1_Click(object sender, EventArgs e)
        {
            Random random = new Random();
                        int num = random.Next(1, 100000);
                        label1.Text = Convert.ToString(num);
        }
   
you can even use a textbox instead label

Useful Snippets For C#

Opening another form

new Form2().Show();

Minimize Form 

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;

Maximize Form

this.WindowState = System.Windows.Forms.FormWindowState.Maximized;

Copy A File

File.Copy("C://program files/test.txt", dialog.FileName);

Delete A File

File.Delete("C://program files/test.txt");

Open A Website

System.Diagnostics.Process.Start("http://www.ultimateprogrammingtutorials.blogspot.com");

How To : Matrix on C# Console

hello all , after a long time i am back to write , so today i am gonna teach you to create a matrix screen on c# console , its pretty easy so lets begin making it , open your visual c# 2008/2010 and select console application and name it whatever you want now add this code


#define readkey
using System;

namespace m7tr1x
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "Matrix";
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WindowLeft = Console.WindowTop = 0;
            Console.WindowHeight = Console.BufferHeight = Console.LargestWindowHeight;
            Console.WindowWidth = Console.BufferWidth = Console.LargestWindowWidth;
#if readkey
            Console.WriteLine("Press Any Key to Continue");
            Console.ReadKey();
#endif
            Console.CursorVisible = false;
            int width, height;
            int[] y;
            int[] l;
            Initialize(out width, out height, out y, out l);
            int ms;
            while (true)
            {
                DateTime t1 = DateTime.Now;
                MatrixStep(width, height, y, l);
                ms = 10 - (int)((TimeSpan)(DateTime.Now - t1)).TotalMilliseconds;
                if (ms > 0)
                    System.Threading.Thread.Sleep(ms);
                if (Console.KeyAvailable)
                    if (Console.ReadKey().Key == ConsoleKey.F5)
                        Initialize(out width, out height, out y, out l);
            }
        }

        static bool thistime = false;

        private static void MatrixStep(int width, int height, int[] y, int[] l)
        {
            int x;
            thistime = !thistime;
            for (x = 0; x < width; ++x)
            {
                if (x % 11 == 10)
                {
                    if (!thistime)
                        continue;
                    Console.ForegroundColor = ConsoleColor.White;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.SetCursorPosition(x, inBoxY(y[x] - 2 - (l[x] / 40 * 2), height));
                    Console.Write(R);
                    Console.ForegroundColor = ConsoleColor.Green;
                }
                Console.SetCursorPosition(x, y[x]);
                Console.Write(R);
                y[x] = inBoxY(y[x] + 1, height);
                Console.SetCursorPosition(x, inBoxY(y[x] - l[x], height));
                Console.Write(' ');
            }
        }

        private static void Initialize(out int width, out int height, out int[] y, out int[] l)
        {
            int h1;
            int h2 = (h1 = (height = Console.WindowHeight) / 2) / 2;
            width = Console.WindowWidth - 1;
            y = new int[width];
            l = new int[width];
            int x;
            Console.Clear();
            for (x = 0; x < width; ++x)
            {
                y[x] = r.Next(height);
                l[x] = r.Next(h2 * ((x % 11 != 10) ? 2 : 1), h1 * ((x % 11 != 10) ? 2 : 1));
            }
        }

        static Random r = new Random();
        static char R
        {
            get
            {
                int t = r.Next(10);
                if (t <= 2)
                    return (char)('0' + r.Next(10));
                else if (t <= 4)
                    return (char)('a' + r.Next(27));
                else if (t <= 6)
                    return (char)('A' + r.Next(27));
                else
                    return (char)(r.Next(32, 255));
            }
        }

        public static int inBoxY(int n, int height)
        {
            n = n % height;
            if (n < 0)
                return n + height;
            else
                return n;
        }
    }
}


now run the application , enjoy

How To Change Extensions In VB.NET

In this tutorial i'm going to tell you how to change file extensions.
     Dim type As String = ".mp4"
        MsgBox(TextBox1.Text + " is changed into a " + type + " file.")
        Dim oldFile As String = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 4)
        FileCopy(TextBox1.Text, oldFile + type)
How to use it:
You have a form containing: 2 buttons, 1 textbox (or combobox)
When you click button one you can say it must open a openfiledialog:
Dim ofd As New Openfiledialog
If ofd.showdialog = dialogresult.OK then
TextBox1.Text = ofd.filename
End If
If we click the button, a openfiledialog will appear and we can choose a file name and if we click on 'ok', then the textbox will contain the filename of the openfiledialog.
Now double click on the other button and fill in the code above.
That's it!

How To Make Fade Effect In VB.NET

fade in / out , fade in when your app starts and fade out when your app getting closed .

you just need to add these codes , fade in for form_load and fade out for form_closing.

Public Class Form1
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        For FadeOut = 90 To 10 Step -10
            Me.Opacity = FadeOut / 100
            Me.Refresh()
            Threading.Thread.Sleep(50)
        Next
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        For FadeIn = 0.0 To 1.1 Step 0.1
            Me.Opacity = FadeIn
            Me.Refresh()
            Threading.Thread.Sleep(100)
        Next
    End Sub
End Class
preview -

How To Get The Source Code Of A Website Using Web Browser And HttpWebRequest In VB.NET

this is going to be a simple tutorial , there are two ways to get the source code of a website in vb.net you know what are they so lets start making them

Web Browser

1.open your visual basic 2008/2010

2.create a new project and name it whatever

3.add a webbrowser from toolbox and place it some where else

4.add a richtextbox and a textbox

5.add a button and change the button text property to get source code

6.double click your form and erase everything add this code
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate(TextBox1.Text)

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        RichTextBox1.Text = WebBrowser1.DocumentText
    End Sub
End Class
7.debug

preview -



HttpWebRequest

httpwebrequest is fast and more efficient than webbrowser 

1.open your visual basic 2008/2010

2.create a new project and name it whatever you want

3.add a richtextbox and a textbox

4.add a button and name it get source code

5.double click your form and erase everything and add these code
Imports System.Net
Imports System.IO

Public Class Form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(TextBox1.Text)
        Dim response As System.Net.HttpWebResponse = request.GetResponse()

        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

        Dim sourcecode As String = sr.ReadToEnd()

        RichTextBox1.Text = sourcecode
    End Sub
End Class
6.debug

preview -