Wednesday 14 November 2018

Multi process download

To fast up the process split up two different threads
   private static void Writer()
   {            
   try
      {               
         WebClient client = new WebClient();
         string status = client.DownloadString
  ("https://speckyboy.com/25-modern-content-heavy-websites/");
 
                 using (FileStream fs = File.Open("D:\\import\\111.txt", FileMode.Create,
   FileAccess.Write, FileShare.ReadWrite))
                 {
                     byte[] bytes = Encoding.ASCII.GetBytes(status);
                     int bytelen = bytes.Length / 2;
 
                    Thread t = new Thread(()=> NewMethod2(status, fs,0, bytelen));
                     t.Start();
 
                     Thread t1 = new Thread(()=> NewMethod2(status, fs, bytelen, bytes.Length));
                     t1.Start();
                    
                     while (true)
                     {
 
                         if (!t.IsAlive && !t1.IsAlive)
                         {
                             fs.Close();
                             break;
                         }
                     }
                     Console.Write("Write:" + status + Environment.NewLine);
                 }
                 System.Threading.Thread.Sleep(10);
               
             }
             catch (Exception ex)
             {
                 Console.Write("write" + ex.ToString());
                 Console.Read();
             }
         }
 
   private static void NewMethod2(string status, FileStream fs,int start, int bytelen)
          {
              for (int i = start; i < bytelen; i++)
              {
                  fs.Write(Encoding.ASCII.GetBytes(status[i].ToString()), 0,
   Encoding.ASCII.GetBytes(status[i].ToString()).Length);
  
              }
          }
 

Tuesday 11 August 2015

Download files

  1.  Create interface for downloads method and path property.  Interface :  An interface contains only the signatures of methods, properties, events or indexers.  A class or struct that implements the interface must implement the members of the interface  that are specified in the interface definition.
     public interface downloads 
     {
         string path { get; set; }
         void download();
     }
    
  2.  create class name general and inherit the interface class in it  Inheritance :   Inheritance allows us to define a class in terms of another class,   which makes it easier to create and maintain an application.  set the property and method for download by using httpresponse download the file from server to local system.
     public class general  : downloads
     {
    
         public string path
         {
             get;
             set;
         }
    
         public void download()
         {
             using (FileStream fs = File.OpenRead(this.path))
             {
                 int length = (int)fs.Length;
                 byte[] buffer;
    
                 using (BinaryReader br = new BinaryReader(fs))
                 {
                     buffer = br.ReadBytes(length);
                 }
    
                 HttpContext.Current.Response.Clear();
                 HttpContext.Current.Response.Buffer = true;
                 HttpContext.Current.Response.AddHeader("content-disposition", 
                 String.Format("attachment;filename={0}",  Path.GetFileName(path)));
                 HttpContext.Current.Response.ContentType = 
                      "application/" + Path.GetExtension(path).Substring(1);
                 HttpContext.Current.Response.BinaryWrite(buffer);
                 HttpContext.Current.Response.End();
             }   //
         }
     }
    
    
    
  3.  create the object for class general and set the path to property  call the download method to make a download the file.  
      public void sDownload()
         {
             downloads obj = new general();
             obj.path = @"C:\GoogleBackup\googleService.txt";
             obj.download();
         }
    
    

Sunday 2 August 2015

Search tables and procedures by given text in it

Find all tables and procedures by giving string in it using like operator in SQL
  1. FOR TABLES
     SELECT COLUMN_NAME, TABLE_NAME 
     FROM INFORMATION_SCHEMA.COLUMNS 
     WHERE COLUMN_NAME LIKE '%searchstring%'
    
  2. FOR PROCEDURES
     SELECT OBJECT_NAME(object_id), 
            OBJECT_DEFINITION(object_id)
     FROM sys.procedures
     WHERE OBJECT_DEFINITION(object_id) LIKE '%SearchString%'
    

Friday 31 July 2015

Get RAM and CPU usage in C#

Get Cpu and Ram Usage by kernel132.dll in c# How to get CPU percentage ?
  1. Step 1: include namespace in class file
     using System;
     using System.Diagnostics;
     using System.Runtime.InteropServices;
     using System.IO;
    
  2. Step 2: Declare performance counter and other variables and we just get average of cpu 5 times with difference of 5 seconds
     Public string GetCpuPercentage()
      {
       PerformanceCounter cpuCounter;
       double cpuUsage = 0;
       int totalCpuUsage = 0;
       double returnLoopCount = 0;
    
       cpuCounter = new PerformanceCounter();
       cpuCounter.CategoryName = "Processor";
       cpuCounter.CounterName = "% Processor Time";
       cpuCounter.InstanceName = "_Total";
       for (int i = 0; i < 5; i++)
       {
       cpuUsage += cpuCounter.NextValue();
       System.Threading.Thread.Sleep(1000);
       }
       totalCpuUsage = Convert.ToInt32(Math.Ceiling(cpuUsage / 5));
       return totalCpuUsage;
      }
    
  3. Step 3:Declare performance counter and other variables and we just get average of RAM memory usage by using 'Kernel32.dll'
     public string GetRamPercentage()
      {
          PerformanceCounter ramCounter;
               double ramUsage = 0;
               int TotalRamMemory = 0;
               int AvailableRamMemory = 0;
               int UsedRamMemory = 0;
               int RamUsagePercentage = 0;
               double returnLoopCount = 0;
               MEMORYSTATUSEX statEX = new MEMORYSTATUSEX();
               statEX.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
               GlobalMemoryStatusEx(ref statEX);
    
               double ram = (double)statEX.ullTotalPhys;
               //float ram = (float)stat.TotalPhysical;
               ram /= 1024;
               ram /= 1024;
    
               TotalRamMemory = Convert.ToInt32(Math.Round(ram, 0));
               ramCounter = new PerformanceCounter("Memory", "Available MBytes");
               for (int i = 0; i < 5; i++)
               {
                   ramUsage += ramCounter.NextValue();
                   System.Threading.Thread.Sleep(1000);
               }
               AvailableRamMemory = Convert.ToInt32(Math.Round((ramUsage / 5), 0));
               UsedRamMemory = TotalRamMemory - AvailableRamMemory;
               RamUsagePercentage = ((UsedRamMemory * 100) / TotalRamMemory);
    
       return RamUsagePercentage;
            
      }
    
         [return: MarshalAs(UnmanagedType.Bool)]
         [DllImport("Kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
         internal static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
    
     [StructLayout(LayoutKind.Sequential)]
     internal struct MEMORYSTATUSEX
      {
           internal uint dwLength;
           internal uint dwMemoryLoad;
           internal ulong ullTotalPhys;
           internal ulong ullAvailPhys;
           internal ulong ullTotalPageFile;
           internal ulong ullAvailPageFile;
           internal ulong ullTotalVirtual;
           internal ulong ullAvailVirtual;
           internal ulong ullAvailExtendedVirtual;
      }
    
    

Thursday 16 July 2015

How to create stored procedure in SQL?

SQL STORED PROCEDURE :
  1. SQL Procedure are nothing but set of sql statement grouped and perform a specific task. it will give high performance for database
  2. stored procedure compiled at once it created in database Then after it does not require recompilation before executing unless it is modified and reutilizes the same execution plan
  3. it is usability of SQL code and re-usability purpose of same kind of operation using twice in our source code
How to create stored procedure ?
 SYNTAX:

 CREATE PROCEDURE <PROC NAME>
 AS
 @param1 <datatype>
 BEGIN
  //Code of T-SQL
 END


EXPLAINATION : 

 CREATE PROC <PROC NAME>
 AS
 @param1 BIGINT  //input param
 BEGIN

 CREATE TABLE #TEMP (name VARCHAR(50)) // CREATiNG TEMP TABLE
 INSERT INTO #TEMP    // bulk insert
 SELECT * FROM table1 WHERE salary > @param // get users from table 1 
  UNION 
 SELECT * FROM table2 WHERE salary < @param  // get users from table 2

 SELECT * FROM #TEMP
 DROP TABLE #TEMP

 END


How to alter stored procedure ?
 SYNTAX:

 ALTER PROCEDURE <PROC NAME>
 AS
 @param1 <datatype>
 BEGIN
  //code of T-SQL
 END

EXPLAIN : 
//instead of create we can give alter and we can save changes in sp(STORED PROC)

EXPLAINATION : 

 ALTER PROC <PROC NAME>
 AS
 @param1 BIGINT   //input param
 BEGIN

 CREATE TABLE #TEMP (name VARCHAR(50)) // CREATiNG TEMP TABLE
 INSERT INTO #TEMP    // bulk insert
 SELECT * FROM table1 WHERE salary > @param // get users from table 1 
  UNION 
 SELECT * FROM table2 WHERE salary < @param  // get users from table 2

 SELECT * FROM #TEMP ORDER BY name DESC
 DROP TABLE #TEMP

 END


How to execute stored procedure ?
 SYNTAX:
 EXECUTE <sp_name> @param = 1000
  OR
 EXEC <sp_name> 1000
  OR 
 <sp_name> 1000
Summary : Stored procedure is reusing the code,performance of execution plan,reduce the traffic of the network sp(STORED PROC) is one of the best way to use in heavy transactions over the network

Wednesday 15 July 2015

Bulk insert from one table to another table in SQL

Bulk Insert
  1. we can use two types of bulk insert in MSSQL
  2. it is very useful to transfer whole data or particular data from one table to another
  3. Type 1: we need to create schema or we can use existing schema for insertion
  4. Type 2: we cannot insert data's in existing table schema.this type will copy the schema of selected table and create table in database or we can use temp table
  5. Mostly this bulk insert are used in stored procedure or user-defined functions for calculations.
Type 1:
 CREATE TABLE TABLE1( name INT,EmpSalary BIGINT)
 INSERT INTO TABLE1
 SELECT name,salary FROM TABLE2
 WHERE salary > 1000

Type 2 :
 SELECT * INTO #TEMP FROM TABLE2 //this will create temp table with selected table schema
 WHERE salary > 1000
   OR
 SELECT * INTO TABLE FROM TABLE2   // this will create real table with selected table schema in DB
 WHERE salary > 1000

Sunday 12 July 2015

Bulk Update using join in SQL


UPDATE WITH JOIN
 UPDATE t1
  SET t1.name = t2.empname  //copy content from one table to another
 FROM table1 t1
    INNER JOIN table2 t2 ON
        t1.id = t2.t1id

Sunday 14 July 2013

how to implement Tweet snd linkedin button for each and every post in Your blog ??


how to implement Tweet snd linkedin share button for each and every post in Your blog ??

Some of the Steps we have to follow to complete the above task.

1.Go to Dashboard->Template
2.Click Edit HTML
3.Search <data:post.body/>
4.Paste the below code 
<!--TWITTER-->
<b:if cond='data:blog.pageType != &quot;static_page&quot;'> <div style='text-align:left;padding:5px 5px 5px 0;'> <a class='twitter-share-button' data-count='horizontal' data-related='' data-via='technoblaze1' expr:data-text='data:post.title' expr:data-url='data:post.url' href='http://twitter.com/share'>Tweet</a> <script src='http://platform.twitter.com/widgets.js' type='text/javascript'/> </div> </b:if>
<p>
<!--LINKEDIN-->
<script src='http://platform.linkedin.com/in.js' type='text/javascript'/> 

  <script data-counter='right' type='IN/Share'/></p>

SCREEN SHOTS:

STEP:1
STEP:2 & 3


STEP:4
STEP:5&6



Friday 12 July 2013

Facebook like button for each post in blogger


how to implement Facebook like button for each and every post in Your blog ??

Some of the Steps we have to follow to complete the above task.

1.Go to Dashboard->Template
2.Click Edit HTML
3.Search <data:post.body/>
4.Paste the below code 
   
<p><iframe allowTransparency='true' expr:src='&quot;http://www.facebook.com/plugins/like.php?href=&quot; + data:post.url + &quot;&amp;layout=button_count&amp;show_faces=false&amp;width=100&amp; action=like&amp;font=arial&amp;colorscheme=light&quot;' frameborder='0' scrolling='no' style='border:none; overflow:hidden; width:100px; height:20px;'/></p>

5.Click Save template
6.View your blog.

Screen shots:

Step:1


Step:2 & 3


Step:4

Step: 5 & 6


Wednesday 10 July 2013

Facebook like and unlike system using [php-mysql-ajax] and facebook wall post system with time calculation system for each post and display it in users wall



We have to make Facebook wall system,Face book like system and Facebook time management system  for each and every post
-In my previous post Facebook wall system will be implemented
-In this Post contains facebook like system and facebook time management system along with wall post system  will be implemented
-in this section i have created separate login system for every users 
-users can login and post their words in their wall 
-others users will like or unlike the post using their user-id
-face book time management means, users posts display the time when they   posted and how many hours,minutes or seconds ago they posted their words or quotes and all
- this are the task we have to done 
-there are several steps to complete our task
-Create database and following tables 
-there are 3 Table contains in database

      1.Login
      2.Messages
      3.message_like

1.Login table :

CREATE TABLE IF NOT EXISTS `login` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(250) NOT NULL,
  `password` varchar(250) NOT NULL,
  PRIMARY KEY (`uid`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;

2.Message table:

CREATE TABLE IF NOT EXISTS `messages` (
  `msg_id` int(11) NOT NULL AUTO_INCREMENT,
  `message` varchar(200) NOT NULL,
  `uid_fk` int(11) NOT NULL,
  `like_count` int(11) DEFAULT NULL,
  `created` varchar(250) DEFAULT NULL,
  PRIMARY KEY (`msg_id`),
  KEY `uid_fk` (`uid_fk`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;

3.message_like table :


CREATE TABLE IF NOT EXISTS `message_like` (
  `like_id` int(11) NOT NULL AUTO_INCREMENT,
  `msg_id_fk` int(11) DEFAULT NULL,
  `uid_fk` int(11) NOT NULL,
  `created` varchar(250) NOT NULL,
  PRIMARY KEY (`like_id`),
  KEY `uid_fk` (`uid_fk`),
  KEY `msg_id_fk` (`msg_id_fk`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=59 ;

-Download the file and configure your hostname,username and password
-Live demo is available,check it 
- if any queries regarding, post your commands





Screen Shots: