tag:blogger.com,1999:blog-47925500036664562832024-03-07T22:31:24.004-08:00All about software and web developmentA blog about web application development mainly on backend sideTonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.comBlogger38125tag:blogger.com,1999:blog-4792550003666456283.post-36266426604433817582024-02-18T03:22:00.000-08:002024-02-18T03:22:09.879-08:00What is DaemonSet in Kubernetes<p><span style="font-family: helvetica;"> A DaemonSet is a type of controller object that ensures that a specific pod runs on each node in the cluster. DaemonSets are useful for deploying system daemons or other background tasks that need to run on every node.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Here's how DaemonSets work and some key points to understand:</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">One Pod per Node: A DaemonSet guarantees that there is exactly one instance of a specified pod running on each node in the Kubernetes cluster. If new nodes are added to the cluster, the DaemonSet automatically schedules pods onto those nodes.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">DaemonSet Controller: The Kubernetes control plane includes a DaemonSet controller that continuously monitors the cluster's state. When a DaemonSet is created or updated, the controller ensures that the desired number of pods is running on each node.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Node Selector and Affinity: DaemonSets can be configured to run on specific nodes using node selectors or node affinity rules. This allows you to control which nodes the DaemonSet's pods are scheduled on based on labels assigned to nodes.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Updating DaemonSets: When you update a DaemonSet (e.g., by changing the pod template), Kubernetes will automatically roll out the changes to all nodes. It follows a rolling update strategy by default, ensuring that there is no downtime during the update process.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Pod Eviction: DaemonSets also handle pod eviction gracefully. If a node becomes unhealthy or is removed from the cluster, the DaemonSet controller ensures that the pod running on that node is rescheduled onto a healthy node.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Use Cases: DaemonSets are commonly used for deploying cluster-level services or agents, such as monitoring agents (e.g., Prometheus Node Exporter), logging agents (e.g., Fluentd), or networking plugins (e.g., CNI plugins like Calico or Flannel).</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Here's a basic example of a DaemonSet YAML manifest:</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><br /></p><p><span style="font-family: helvetica;">apiVersion: apps/v1</span></p><p><span style="font-family: helvetica;">kind: DaemonSet</span></p><p><span style="font-family: helvetica;">metadata:</span></p><p><span style="font-family: helvetica;"> name: example-daemonset</span></p><p><span style="font-family: helvetica;">spec:</span></p><p><span style="font-family: helvetica;"> selector:</span></p><p><span style="font-family: helvetica;"> matchLabels:</span></p><p><span style="font-family: helvetica;"> app: example</span></p><p><span style="font-family: helvetica;"> template:</span></p><p><span style="font-family: helvetica;"> metadata:</span></p><p><span style="font-family: helvetica;"> labels:</span></p><p><span style="font-family: helvetica;"> app: example</span></p><p><span style="font-family: helvetica;"> spec:</span></p><p><span style="font-family: helvetica;"> containers:</span></p><p><span style="font-family: helvetica;"> - name: example-container</span></p><p><span style="font-family: helvetica;"> image: example-image:tag</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">This DaemonSet definition ensures that one pod with the label app: example runs on each node in the cluster, using the specified container image.</span></p><p><span style="font-family: helvetica;"><br /></span></p><p><span style="font-family: helvetica;">Overall, DaemonSets are a powerful tool in Kubernetes for deploying and managing background tasks or system-level services across a cluster of nodes.</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-9893150191718057322024-02-13T21:13:00.000-08:002024-02-13T21:13:46.323-08:00How ASP.NET Core applications boot up and start<p> Take the following Program.cs class as example -</p><div style="background-color: #1f1f1f; color: #cccccc; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;"><div><span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">builder</span> <span style="color: #d4d4d4;">=</span> <span style="color: #4ec9b0;">WebApplication</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">CreateBuilder</span>(<span style="color: #569cd6;">args</span>);</div><br /><div><span style="color: #6a9955;">// Add services to the container.</span></div><div><span style="color: #9cdcfe;">builder</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">Services</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">AddControllersWithViews</span>();</div><br /><div><span style="color: #569cd6;">var</span> <span style="color: #9cdcfe;">app</span> <span style="color: #d4d4d4;">=</span> <span style="color: #9cdcfe;">builder</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">Build</span>();</div><br /><div><span style="color: #6a9955;">// Configure the HTTP request pipeline.</span></div><div><span style="color: #c586c0;">if</span> (<span style="color: #d4d4d4;">!</span><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #9cdcfe;">Environment</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">IsDevelopment</span>())</div><div>{</div><div> <span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseExceptionHandler</span>(<span style="color: #ce9178;">"/Home/Error"</span>);</div><div><span style="color: #6a9955;"> </span><span style="color: #6a9955;">// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.</span></div><div> <span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseHsts</span>();</div><div>}</div><br /><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseHttpsRedirection</span>();</div><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseStaticFiles</span>();</div><br /><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseRouting</span>();</div><br /><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">UseAuthorization</span>();</div><br /><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">MapControllerRoute</span>(</div><div> <span style="color: #9cdcfe;">name</span>: <span style="color: #ce9178;">"default"</span>,</div><div> <span style="color: #9cdcfe;">pattern</span>: <span style="color: #ce9178;">"</span><span style="color: #d16969;">{</span><span style="color: #ce9178;">controller</span><span style="color: #d16969;">=</span><span style="color: #ce9178;">Home</span><span style="color: #d16969;">}</span><span style="color: #ce9178;">/</span><span style="color: #d16969;">{</span><span style="color: #ce9178;">action</span><span style="color: #d16969;">=</span><span style="color: #ce9178;">Index</span><span style="color: #d16969;">}</span><span style="color: #ce9178;">/</span><span style="color: #d16969;">{</span><span style="color: #ce9178;">id</span><span style="color: #dcdcaa;">?</span><span style="color: #d16969;">}</span><span style="color: #ce9178;">"</span>);</div><br /><div><span style="color: #9cdcfe;">app</span><span style="color: #d4d4d4;">.</span><span style="color: #dcdcaa;">Run</span>();</div><br /></div><p><br /></p><p>Here is an explanation of how ASP.NET Core applications boot up and start:</p><p><br /></p><p>The entry point is the Main method in Program.cs. This is where the application startup process begins.</p><p><br /></p><p>The WebApplication.CreateBuilder() method is called to create a new WebApplicationBuilder. This sets up the initial configuration for building the web app host.</p><p><br /></p><p>Services like MVC controllers are added to the builder to be included in the application. These extend the functionality of the app.</p><p><br /></p><p>The builder configures the services and components, and then builds the WebApplication object. This is the core app host.</p><p><br /></p><p>The application configuration methods are called on the built WebApplication. This configures the HTTP request handling pipeline.</p><p><br /></p><p>Middleware components are added to the pipeline in a specific order. These handle requests and responses.</p><p><br /></p><p>Endpoints like route mappings and authorization are configured.</p><p><br /></p><p>Finally app.Run() is called to start the web host, begin listening for requests, and start the app!</p><p><br /></p><p>ASP.NET Core has now fully booted up and is ready to receive and handle HTTP requests.</p><p><br /></p><p>Requests come in and flow through the middleware pipeline. Each component can handle the request or pass it to the next one.</p><p><br /></p><p>Endpoints like MVC controllers take over and execute app logic to generate responses.</p><p><br /></p><p>Responses flow back out through the middleware pipeline and are sent back to clients.</p><p><br /></p><p>So in summary, the Main method bootstraps the host, sets up configuration, wires up the pipeline, and launches the app to start handling requests using the configured middleware and endpoints.</p><p><br /></p><p><br /></p><p><br /></p><p><br /></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-6273591003064824992024-02-11T23:09:00.000-08:002024-02-11T23:09:40.007-08:00What is SOLID principal?<p style="text-align: left;"><span style="font-family: helvetica; font-size: medium;"> SOLID is an acronym that stands for five principles of object-oriented programming design: Single Responsibility Principle, Open-Closed Principle, Liskov Substitution Principle, Interface Segregation Principle, and Dependency Inversion Principle. These principles help in designing software that is easy to maintain, understand, and extend.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">Let's take an example in C# to understand SOLID principles. Suppose we have a class called `Car` that represents a car object. Here's how each SOLID principle can be applied:</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">1. Single Responsibility Principle (SRP): The `Car` class should have only one reason to change. It should be responsible for managing the car's properties and behavior related to a car, such as accelerating, braking, and changing gears.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">2. Open-Closed Principle (OCP): The `Car` class should be open for extension but closed for modification. This means that we should be able to add new features or behaviors to the `Car` class without modifying its existing code. For example, we can create a new class called `ElectricCar` that inherits from the `Car` class and adds additional behavior specific to electric cars, such as charging.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">3. Liskov Substitution Principle (LSP): Objects of a superclass should be replaceable with objects of its subclasses without affecting the correctness of the program. In our example, if we have a method that accepts a `Car` object as a parameter, we should be able to pass an instance of `ElectricCar` without any issues.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">4. Interface Segregation Principle (ISP): Clients should not be forced to depend on interfaces they do not use. Instead of having a single interface with many methods, we should have multiple smaller interfaces that are specific to the needs of the clients. For example, instead of having a single `ICar` interface with methods for accelerating, braking, and changing gears, we can have separate interfaces like `IAcceleratable`, `IBrakable`, and `IGearChangeable`.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">5. Dependency Inversion Principle (DIP): High-level modules should not depend on low-level modules. Both should depend on abstractions. In our example, instead of directly instantiating dependencies within the `Car` class, we can use dependency injection to provide the required dependencies. This allows for easier testing and decouples the `Car` class from its dependencies.</span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;"><br /></span></p>
<p style="margin: 0px; text-align: left;"><span style="font-family: helvetica; font-size: medium;">By following these SOLID principles, we can create more maintainable, flexible, and scalable software systems.</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-85163533259483732922024-02-10T23:51:00.000-08:002024-02-10T23:51:59.242-08:00Abstract Class vs Interface in .Net Programming: Understanding the Differences <p><span style="font-family: helvetica; font-size: medium;"> </span></p><p><span style="font-family: helvetica; font-size: medium;">In any software development process, it is crucial to understand the differences between various types of classes. Two such classes are abstract class and interface. Both these concepts have their own unique characteristics </span></p><p><span style="font-family: helvetica; font-size: medium;">and uses in .net programming. In this post, we will discuss what they are, how they differ from each other, and when you should use them.</span></p><p><span style="font-family: helvetica; font-size: medium;"><br /></span></p><p><span style="font-family: helvetica; font-size: medium;">An Abstract Class is a base class that cannot be instantiated on its own. It can only be used to define methods that must be implemented by any concrete (or derived) classes that inherit from it. This means that an abstract </span></p><p><span style="font-family: helvetica; font-size: medium;">class provides a common interface for all its subclasses, but each subclass must provide its implementation of the required methods.</span></p><p><span style="font-family: helvetica; font-size: medium;"><br /></span></p><p><span style="font-family: helvetica; font-size: medium;">On the other hand, an Interface is a contract between two or more components. It specifies the methods and properties that any object implementing the interface should have. Unlike an abstract class, an interface can be </span></p><p><span style="font-family: helvetica; font-size: medium;">instantiated directly, as it does not have to inherit from any other class.</span></p><p><span style="font-family: helvetica; font-size: medium;"><br /></span></p><p><span style="font-family: helvetica; font-size: medium;">When should you use abstract classes versus interfaces in .net programming? Abstract classes are useful when you want to define a common interface for all your subclasses, while interfaces are ideal when you need multiple </span></p><p><span style="font-family: helvetica; font-size: medium;">components to communicate with each other without specifying their implementations.</span></p><p><span style="font-family: helvetica; font-size: medium;"><br /></span></p><p><span style="font-family: helvetica; font-size: medium;">In conclusion, understanding the differences between an abstract class and an interface is essential in any .net development project. Both these concepts have their own uses and applications, but it's important to choose the</span></p><p><span style="font-family: helvetica; font-size: medium;">right one based on your specific requirements.</span></p><p><span style="font-family: helvetica; font-size: medium;"><br /></span></p><p><span style="font-family: helvetica; font-size: medium;">I hope this post helps you understand these concepts better!</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-51811294148674563092024-02-06T00:15:00.000-08:002024-02-06T00:15:44.099-08:00key features of MAUI<p><span style="background-color: white;">Cross-platform compatibility: MAUI allows developers to write code that can run on multiple platforms with minimal modifications.</span></p><p><span style="background-color: white;">Shared codebase: Developers can use a single codebase for all three platforms, which can save time and reduce complexity.</span></p><p><span style="background-color: white;">Improved performance: MAUI provides improved performance by using the best of breed libraries and frameworks from Microsoft and the open-source community.</span></p><p><span style="background-color: white;">Enhanced security: MAUI includes enhanced security features such as better authentication and authorization capabilities, as well as improved support for encryption and digital signatures.</span></p><p><span style="background-color: white;">Simplified development: MAUI provides a simplified development experience through the use of Xamarin, Visual Studio, and other Microsoft tools.</span></p><p><span style="background-color: white;">Better support for AI and ML: MAUI includes better support for machine learning and artificial intelligence, with new libraries and tools for developing and deploying AI and ML models.</span></p><p><span style="background-color: white;">Enhanced support for web development: MAUI includes new tools and libraries for building web applications, including a new version of Visual Studio Code that is specifically designed for web development.</span></p><p><span style="background-color: white;">Improved support for IoT and cloud applications: MAUI provides improved performance and scalability for Internet of Things (IoT) and cloud applications.</span></p><p><span style="background-color: white;">Better support for microservices architecture: MAUI includes better support for building and deploying microservices architectures, with improved performance and scalability.</span></p><p><span style="background-color: white;">Enhanced libraries and tools: MAUI includes enhanced libraries and tools for developers, including improved support for C# and F#, as well as new libraries and tools for developing and deploying applications in a variety of languages and frameworks.</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-4299442899819013522024-02-04T22:26:00.000-08:002024-02-04T22:26:42.112-08:00What is the difference between abstract class and interface?<p><span style="font-family: georgia;"> Abstract classes and interfaces are two concepts in object-oriented programming that serve distinct purposes.</span></p><p><span style="font-family: georgia;">Abstract classes, also known as abstract base classes, are classes that cannot be instantiated directly. They can only be used as bases for other classes, providing a common ancestor for inheritance. Abstract classes define methods that must be implemented by any class that inherits from them. In other words, you'll need to write code to fill in the blanks when inheriting from an abstract class.</span></p><p><span style="font-family: georgia;">On the other hand, interfaces are collections of method signatures that declare how a class should behave. They serve as contracts between the code and the outside world. Interfaces cannot be instantiated directly, either. However, they can be implemented by any class that wants to interact with them. Think of interfaces like blueprints for your code's behavior.</span></p><p><span style="font-family: georgia;">To summarize: abstract classes define how a class should behave, while interfaces declare how a class should interact with other classes. </span></p><p><span style="font-family: georgia;">Here's an example of how abstract classes and interfaces work in C#: </span></p><p><span style="font-family: georgia;">Let's say you're building a library management system. You could use an abstract class to define the behavior of a book, like this:</span></p><p><span style="font-family: georgia;">public abstract class Book {</span></p><p><span style="font-family: georgia;"> public virtual string GetTitle() { return "The Great Gatsby"; }</span></p><p><span style="font-family: georgia;"> public virtual int GetPageCount() { return 250; }</span></p><p><span style="font-family: georgia;"> // Other methods that must be implemented by any inheriting class</span></p><p><span style="font-family: georgia;">}</span></p><p><span style="font-family: georgia;">Now, let's say you want to create a class called "FictionBook" that inherits from the abstract class "Book". Here's how you could do it:</span></p><p><span style="font-family: georgia;">public class FictionBook : Book {</span></p><p><span style="font-family: georgia;"> public override string GetTitle() { return "The Catcher in the Rye"; } // Implement this method</span></p><p><span style="font-family: georgia;"> public override int GetPageCount() { return 300; } // Implement this method</span></p><p><span style="font-family: georgia;">}</span></p><p><span style="font-family: georgia;">As you can see, by inheriting from the abstract class "Book", the class "FictionBook" is required to implement the methods declared in the abstract class. This way, all books will have a title and page count that can be used uniformly throughout your code. </span></p><p><span style="font-family: georgia;">Now, let's say you want to create an interface called "PrintableBook". You could define it like this:</span></p><p><span style="font-family: georgia;">public interface PrintableBook {</span></p><p><span style="font-family: georgia;"> public virtual void Print() { } // Declare this method</span></p><p><span style="font-family: georgia;">}</span></p><p><span style="font-family: georgia;">Next, let's say you have a class called "Novel" that wants to be able to interact with the "PrintableBook" interface. Here's how you could do it:</span></p><p><span style="font-family: georgia;">public class Novel : IPrintableBook {</span></p><p><span style="font-family: georgia;"> public void Print() { } // Implement this method</span></p><p><span style="font-family: georgia;">}</span></p><p><span style="font-family: georgia;">By implementing the methods declared in the interface "IPrintableBook", the class "Novel" can interact with any class that implements that interface, like the "FictionBook" class we created earlier. </span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-44229405907582642582024-02-04T04:29:00.000-08:002024-02-04T04:29:11.318-08:00Some differences between .net and NodeJs<p> Both .NET and NodeJS are popular programming frameworks that have their own strengths and weaknesses, which makes for an interesting comparison. Here's how they differ in some key areas:</p><p><br /></p><p>Language Support: .NET supports multiple languages such as C#, F#, and Visual Basic, while NodeJS only supports JavaScript. If you primarily work with one language, the choice between these frameworks may be obvious. However, if your project requires multiple programming languages, then .NET might be a better fit due to its broader language support.</p><p>Performance: Both frameworks have their own performance characteristics that can affect application development times and runtimes. For example, NodeJS is known for its fast-paced event loop, which makes it ideal for real-time applications with high traffic loads. On the other hand, .NET has a more mature garbage collector that reduces memory fragmentation during runtime, leading to better performance in large-scale enterprise applications.</p><p>Concurrency: NodeJS is designed around non-blocking I/O operations and asynchrony by default, which makes it easier to write highly concurrent code with many threads running simultaneously. In contrast, .NET has a more traditional synchronous programming model that can be less efficient for high-concurrency applications but offers better support for parallel processing through its Task Parallel Library (TPL).</p><p>Libraries and Frameworks: Both frameworks have their own set of libraries and frameworks that can help developers build robust applications quickly. For example, .NET has a rich ecosystem of libraries and frameworks such as ASP.NET, Entity Framework, and SignalR, while NodeJS has its extensive npm library collection with popular packages like Express, MongoDB, and Redis.</p><p>Learning Curve: Both frameworks have their own learning curves depending on your background and experience level. For example, if you're already familiar with C# or Visual Basic, then transitioning to .NET may be easier due to the similar syntax and programming paradigms. On the other hand, NodeJS has a steeper learning curve for developers who are new to JavaScript but offers more opportunities for creative problem-solving through its event-driven architecture.</p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-77651016638347829782024-02-02T22:37:00.000-08:002024-02-02T22:37:41.450-08:00Run a ChatGPT-like AI Bot on a Raspberry Pi.<h2 style="text-align: left;"><span style="font-family: arial;"> Prepare development environment</span></h2><div><pre style="overflow-wrap: break-word; text-wrap: wrap;"><span style="font-family: arial;">To start you need to have the C/C++ compiler, and tools like make and git.</span></pre><pre style="overflow-wrap: break-word; text-wrap: wrap;"><blockquote><span style="font-family: arial;">sudo apt update
sudo apt install git g++ wget build-essential</span></blockquote></pre><pre style="overflow-wrap: break-word; text-wrap: wrap;"><span style="font-family: arial;"><br /></span></pre><h2 style="overflow-wrap: break-word; text-align: left; text-wrap: wrap;"><span style="font-family: arial;">Download and compile llama.cpp</span></h2></div><div><pre style="overflow-wrap: break-word;"><blockquote style="text-wrap: wrap;"><span style="font-family: arial;">git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
make -j</span></blockquote><p style="text-wrap: wrap;"><span style="font-family: arial;"><br /></span></p><h2 style="text-align: left; text-wrap: wrap;"><span style="font-family: arial;">Download a LLM </span></h2><div><span style="text-wrap: wrap;"><span style="font-family: arial;">You now need to download a language model. Choose one of the models listed below or download your preferred model. Make sure you get the GGUF version (not the GGML variety).
These model files are many gigabytes each so make sure you have plenty of free space. If your SD Card does not have enough space, consider utilizing additional storage, such as a USB flash drive.</span></span></div><div><span style="text-wrap: wrap;"><span style="font-family: arial;"><br /></span></span></div><div><pre style="overflow-wrap: break-word; text-wrap: wrap;"><span style="font-family: arial;">You can check the free space on the drive which holds your home directory using `df -h ~`</span></pre><pre style="overflow-wrap: break-word; text-wrap: wrap;"><span style="font-family: arial;"><br /></span></pre><h2 style="overflow-wrap: break-word; text-align: left; text-wrap: wrap;">Download a Llama 2 Chat 7B @ Q4_K_S</h2><div><pre style="overflow-wrap: break-word; text-wrap: wrap;"><blockquote>cd models
wget https://huggingface.co/TheBloke/Llama-2-7b-Chat-GGUF/resolve/main/llama-2-7b-chat.Q4_K_S.gguf</blockquote><p><br /></p><p><br /></p><h2 style="overflow-wrap: break-word; text-align: left; text-wrap: wrap;">Test the LLM</h2><div><pre style="overflow-wrap: break-word; text-wrap: wrap;">Change directory back to the main llama.cpp directory, where the `main` binary has been built (i.e. `cd ..`)</pre><pre style="overflow-wrap: break-word; text-wrap: wrap;"><blockquote>./main -m models/<MODEL-NAME.gguf> -p "Building a website can be done in 10 simple steps:\nStep 1:" -n 400 -e</blockquote><p>For example:</p><p></p><blockquote>./main -m models/llama-2-7b-chat.Q4_K_S.gguf -p "Building a blog can be done in 10 simple steps:\nStep 1:" -n 400 -e </blockquote><p><br /></p><p> </p><p></p></pre></div></pre></div></div></pre></div>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-74358130330368616622024-02-01T03:00:00.000-08:002024-02-01T03:00:27.055-08:00How to write scalable code<p> Writing scalable code is crucial for ensuring that your software can handle increased workload and growth without a significant decrease in performance. Here are some tips on writing scalable code:</p><p><br /></p><h2 style="text-align: left;">Modularization and Abstraction:</h2><p><br /></p><p>Break your code into small, independent modules or functions.</p><p>Use classes and objects to encapsulate functionality.</p><p>Encourage the use of interfaces to define contracts between components.</p><p><br /></p><h2 style="text-align: left;">Efficient Algorithms and Data Structures:</h2><p><br /></p><p>Choose algorithms and data structures that are efficient for the problem at hand.</p><p>Optimize your code for time and space complexity.</p><p>Understand the trade-offs between different algorithms and data structures.</p><p><br /></p><h2 style="text-align: left;">Avoid Global State:</h2><p><br /></p><p>Minimize the use of global variables and mutable state.</p><p>Embrace immutability where applicable to reduce side effects.</p><p>Prefer passing parameters and returning values over using global state.</p><p><br /></p><h2 style="text-align: left;">Concurrency and Parallelism:</h2><p><br /></p><p>Design your code to be concurrent and take advantage of parallel processing when possible.</p><p>Use threading, multiprocessing, or asynchronous programming as appropriate.</p><p>Be mindful of potential race conditions and use proper synchronization mechanisms.</p><p><br /></p><h2 style="text-align: left;">Caching:</h2><p><br /></p><p>Implement caching strategically to store and retrieve frequently used data.</p><p>Cache at different levels, such as application-level caching, database-level caching, and content delivery network (CDN) caching.</p><p><br /></p><h2 style="text-align: left;">Database Optimization:</h2><p><br /></p><p>Optimize database queries for performance.</p><p>Index database tables appropriately.</p><p>Consider denormalization for read-heavy operations and normalization for write-heavy operations.</p><p><br /></p><h2 style="text-align: left;">Scalable Architecture:</h2><p><br /></p><p>Design a scalable architecture that can handle increased load by adding more resources (horizontal scaling).</p><p>Use load balancing to distribute incoming traffic across multiple servers.</p><p>Employ microservices architecture for better scalability and maintainability.</p><p><br /></p><h2 style="text-align: left;">Monitoring and Profiling:</h2><p><br /></p><p>Implement logging and monitoring to track system behavior and performance.</p><p>Use profiling tools to identify bottlenecks and optimize critical sections of code.</p><p><br /></p><h2 style="text-align: left;">Code Reviews and Testing:</h2><p><br /></p><p>Conduct regular code reviews to ensure code quality and adherence to best practices.</p><p>Write comprehensive unit tests and perform scalability testing.</p><p>Implement continuous integration and continuous deployment (CI/CD) pipelines.</p><p><br /></p><h2 style="text-align: left;">Documentation:</h2><p><br /></p><p>Provide clear and comprehensive documentation for your codebase.</p><p>Include information on how to scale the application, configure performance-related settings, and troubleshoot issues.</p><p><br /></p><h2 style="text-align: left;">Scalable Communication:</h2><p><br /></p><p>Optimize communication between components to reduce latency.</p><p>Use message queues or event-driven architectures for decoupled communication.</p><p><br /></p><h2 style="text-align: left;">Keep Abreast of Technology:</h2><p><br /></p><p>Stay informed about the latest technologies and best practices in software development.</p><p>Embrace new tools and frameworks that can enhance scalability.</p><p>By incorporating these principles into your coding practices, you can create code that is more resilient and able to scale effectively as your application grows.</p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-34267287250571441302024-01-30T04:32:00.000-08:002024-01-30T04:32:16.669-08:00Designing a Scalable SQL Table for Millions of Users<h2 style="text-align: left;"> Introduction:</h2>
<p style="margin: 0px;">In today's digital age, managing large amounts of user data is a common challenge for many businesses. With millions of users and a minimum of one million active users, it is crucial to design a scalable SQL table that can efficiently handle the load. In this blog post, we will explore the key considerations and best practices for designing a database that can handle such a high volume of users.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">1. Choosing the Right Database Management System (DBMS):</h2>
<p style="margin: 0px;">The first step in designing a scalable SQL table is selecting the appropriate DBMS. Considerations such as performance, scalability, and availability should guide your decision. Popular choices for large-scale applications include MySQL, PostgreSQL, and Oracle.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">2. Normalization and Denormalization:</h2>
<p style="margin: 0px;">Normalization is a database design technique that minimizes data redundancy and improves data integrity. However, in a high-traffic scenario, excessive normalization can lead to performance issues. Denormalization, on the other hand, involves duplicating data to improve query performance. Finding the right balance between normalization and denormalization is crucial for a scalable SQL table.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">3. Partitioning:</h2>
<p style="margin: 0px;">Partitioning involves dividing a large table into smaller, more manageable pieces called partitions. This technique improves query performance by allowing parallel processing and reducing the amount of data that needs to be scanned. Partitioning can be done based on various criteria such as range, list, or hash.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">4. Indexing:</h2>
<p style="margin: 0px;">Proper indexing is essential for efficient data retrieval in a large-scale SQL table. Identify the most frequently used columns in your queries and create indexes on those columns. However, be cautious not to over-index, as it can negatively impact write performance.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">5. Sharding:</h2>
<p style="margin: 0px;">Sharding is a technique that involves distributing data across multiple database instances or servers. Each shard contains a subset of the data, allowing for horizontal scaling. When implementing sharding, consider factors such as data distribution strategy, shard key selection, and data consistency.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">6. Caching:</h2>
<p style="margin: 0px;">Implementing a caching layer can significantly improve the performance of your SQL table. Consider using technologies like Memcached or Redis to cache frequently accessed data and reduce the load on your database.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">7. Load Balancing:</h2>
<p style="margin: 0px;">To handle a large number of active users, distributing the workload across multiple database servers is crucial. Load balancing techniques such as round-robin, least connections, or weighted distribution can help evenly distribute the load and ensure optimal performance.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">8. Monitoring and Optimization:</h2>
<p style="margin: 0px;">Regularly monitor the performance of your SQL table and identify any bottlenecks or areas for optimization. Use tools like query analyzers, performance monitoring tools, and database profiling to identify and resolve performance issues.</p>
<p style="margin: 0px;"><br /></p>
<h2 style="margin: 0px; text-align: left;">Conclusion:</h2>
<p style="margin: 0px;">Designing a scalable SQL table for millions of users requires careful consideration of various factors such as database management system selection, normalization vs. denormalization, partitioning, indexing, sharding, caching, load balancing, and ongoing monitoring and optimization. By following these best practices, you can ensure that your SQL table can efficiently handle the load and provide a seamless user experience for millions of active users.</p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-60107330905555996392024-01-29T00:08:00.000-08:002024-01-29T00:08:37.333-08:00Maximizing Productivity and Code Quality with Visual Studio IDE and Its Extensions<h2 style="text-align: left;"> Introduction:</h2><p><br /></p><p>In the dynamic world of software development, the tools we use play a crucial role in shaping our workflow and influencing the quality of our code. Microsoft's Visual Studio IDE stands out as a powerful integrated development environment that caters to the diverse needs of developers across different platforms and programming languages. In this blog post, I'll explore how Visual Studio and its rich ecosystem of extensions can be harnessed to enhance productivity and elevate the overall code quality.</p><p><br /></p><h2 style="text-align: left;">1. Streamlined Development with Visual Studio:</h2><p>Visual Studio offers a robust set of features that streamline the development process. Its intuitive interface, intelligent code completion, and debugging capabilities provide a seamless environment for developers to write, test, and deploy code efficiently. Additionally, its compatibility with various programming languages such as C#, C++, Python, and more, makes it a versatile choice for diverse development projects.</p><p><br /></p><h2 style="text-align: left;">2. Code Navigation and Understanding:</h2><p>Understanding and navigating through codebases can be a daunting task, especially in large projects. Visual Studio comes equipped with powerful code navigation tools like Go to Definition, Find All References, and Navigate To. These features enable developers to quickly jump between different parts of the codebase, facilitating a deeper understanding of the project structure and aiding in efficient code exploration.</p><p><br /></p><h2 style="text-align: left;">3. Code Analysis and Refactoring:</h2><p>Maintaining code quality is a continuous process, and Visual Studio assists developers in this endeavor through its built-in code analysis tools. By identifying potential issues and suggesting improvements, the IDE helps developers write cleaner, more maintainable code. Additionally, Visual Studio supports various refactoring operations, allowing developers to restructure their code without introducing errors.</p><p><br /></p><h2 style="text-align: left;">4. Integrating Extensions for Enhanced Functionality:</h2><p>One of the standout features of Visual Studio is its extensibility. The Visual Studio Marketplace is home to a plethora of extensions that cater to specific needs and technologies. Some noteworthy extensions include ReSharper, SonarLint, and Live Share. These extensions can augment the capabilities of Visual Studio, providing enhanced code analysis, formatting, and collaborative development features.</p><p><br /></p><p><b>ReSharper</b>: Known for its powerful code analysis and refactoring tools, ReSharper significantly improves code quality by suggesting improvements, identifying potential issues, and enforcing coding standards.</p><p><br /></p><p><b>SonarLint</b>: Integrating static code analysis into the development process, SonarLint helps identify and fix code quality issues as developers write code. This extension supports multiple languages and integrates seamlessly with Visual Studio.</p><p><br /></p><p><b>Live Share</b>: Collaboration is made easy with Live Share, allowing developers to collaborate in real-time by sharing their coding session with others. This extension fosters teamwork and accelerates the development process.</p><p><br /></p><h2 style="text-align: left;">5. Code Reviews and Collaboration:</h2><p>Visual Studio facilitates effective code reviews through features like pull requests and code commenting. Developers can use pull requests to propose changes, review code, and discuss improvements collaboratively. The built-in code review tools ensure that the entire development team is on the same page regarding coding standards, best practices, and project goals.</p><p><br /></p><h2 style="text-align: left;">6. Automated Testing and Continuous Integration:</h2><p>Ensuring code quality involves thorough testing, and Visual Studio supports various testing frameworks. By integrating with popular testing tools and enabling continuous integration, developers can automate the testing process, catching bugs early and maintaining a reliable and stable codebase.</p><p><br /></p><h2 style="text-align: left;">Conclusion:</h2><p>Visual Studio, with its feature-rich environment and extensive ecosystem of extensions, stands as a powerful ally for developers striving to enhance productivity and code quality. By leveraging the IDE's built-in capabilities and integrating purpose-built extensions, development teams can streamline their workflows, catch potential issues early in the development process, and collaborate seamlessly. As the software development landscape continues to evolve, Visual Studio remains a cornerstone in empowering developers to write efficient, high-quality code.</p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-80464135905072455722024-01-28T02:06:00.000-08:002024-01-28T02:06:45.467-08:00Understanding OAuth 2 in the Context of Microsoft Azure<h2 style="text-align: left;"><span style="font-size: medium;"> Introduction:</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">OAuth 2 has become the de facto standard for securing APIs and enabling secure access to resources. In the context of Microsoft Azure, OAuth 2 plays a crucial role in providing secure authentication and authorization mechanisms. This blog post aims to provide a comprehensive understanding of OAuth 2 in the context of Microsoft Azure, covering its key concepts, components, and how it can be leveraged to enhance the security of your applications.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">Table of Contents:</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">1. What is OAuth 2?</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">2. Key Concepts of OAuth 2</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 2.1. Clients</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 2.2. Authorization Server</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 2.3. Resource Server</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 2.4. User</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 2.5. Tokens</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">3. OAuth 2 Flows</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 3.1. Authorization Code Flow</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 3.2. Implicit Flow</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 3.3. Client Credentials Flow</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 3.4. Device Authorization Flow</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">4. Azure Active Directory (Azure AD)</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 4.1. Azure AD as an Authorization Server</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 4.2. Azure AD as a Resource Server</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 4.3. Azure AD as an Identity Provider</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">5. Integrating OAuth 2 with Azure Services</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 5.1. Azure API Management</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 5.2. Azure Functions</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 5.3. Azure Logic Apps</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 5.4. Azure App Service</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">6. Best Practices for OAuth 2 in Azure</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 6.1. Secure Token Management</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 6.2. Implementing Multi-factor Authentication</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 6.3. Monitoring and Auditing</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"> 6.4. Regularly Updating OAuth 2 Configurations</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">7. OAuth 2 and Azure Security Center</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">8. Conclusion</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">1. What is OAuth 2?</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">OAuth 2 is an open standard protocol that allows users to grant limited access to their resources on one website to another website without sharing their credentials. It provides a secure and standardized way for applications to access resources on behalf of users.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">2. Key Concepts of OAuth 2</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">2.1. Clients: Applications that request access to protected resources on behalf of users.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">2.2. Authorization Server: The server responsible for authenticating users and issuing access tokens.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">2.3. Resource Server: The server hosting the protected resources that clients want to access.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">2.4. User: The end-user who owns the resources and grants access to them.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">2.5. Tokens: The credentials issued by the authorization server to the client, used to access protected resources.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">3. OAuth 2 Flows</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">OAuth 2 defines several flows to obtain access tokens, depending on the type of client and the level of trust between the client and the authorization server.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">3.1. Authorization Code Flow: Suitable for web applications and native applications with a server-side component.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">3.2. Implicit Flow: Suitable for browser-based applications and mobile applications.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">3.3. Client Credentials Flow: Suitable for machine-to-machine communication.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">3.4. Device Authorization Flow: Suitable for devices with limited input capabilities.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">4. Azure Active Directory (Azure AD)</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">Azure AD is Microsoft's cloud-based identity and access management service. It can act as an authorization server, resource server, and identity provider, making it a powerful tool for implementing OAuth 2 in Azure-based applications.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">5. Integrating OAuth 2 with Azure Services</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">Azure provides various services that can be integrated with OAuth 2 to enhance security and enable secure access to resources.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">5.1. Azure API Management: Securely expose APIs and manage access using OAuth 2.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">5.2. Azure Functions: Authenticate and authorize function invocations using OAuth 2.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">5.3. Azure Logic Apps: Securely connect and automate workflows using OAuth 2.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">5.4. Azure App Service: Protect web applications using OAuth 2 authentication and authorization.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">6. Best Practices for OAuth 2 in Azure</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">To ensure the security of your applications, it is essential to follow best practices when implementing OAuth 2 in Azure.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">6.1. Secure Token Management: Safely store and manage access tokens to prevent unauthorized access.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">6.2. Implementing Multi-factor Authentication: Add an extra layer of security by requiring multiple factors for authentication.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">6.3. Monitoring and Auditing: Regularly monitor and audit OAuth 2 configurations to detect and mitigate potential security risks.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;">6.4. Regularly Updating OAuth 2 Configurations: Stay up-to-date with the latest security recommendations and update OAuth 2 configurations accordingly.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">7. OAuth 2 and Azure Security Center</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">Azure Security Center provides advanced threat protection for Azure resources, including OAuth 2-enabled applications. It helps identify and remediate security vulnerabilities and provides insights into potential attacks.</span></p>
<p style="margin: 0px;"><span style="font-size: medium;"><br /></span></p>
<h2 style="margin: 0px; text-align: left;"><span style="font-size: medium;">Conclusion:</span></h2>
<p style="margin: 0px;"><span style="font-size: medium;">OAuth 2 is a powerful protocol for securing APIs and enabling secure access to resources. In the context of Microsoft Azure, OAuth 2 plays a crucial role in providing secure authentication and authorization mechanisms. By understanding the key concepts, integrating with Azure services, and following best practices, developers can leverage OAuth 2 to enhance the security of their applications in the Azure ecosystem.</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-50329788601008349632024-01-28T01:46:00.000-08:002024-01-28T01:46:23.396-08:00Different types of API authentication<p><span style="font-size: medium;"> Hopefully this will help you to understand how API authentication works and what are the different types of authentication</span></p><p><span style="font-size: medium;">API authentication is an essential aspect of securing RESTful APIs. It ensures that only authorized users or services can access the API and perform actions on behalf of the user. In this post, we'll explore the different types of API authentication and how they work.</span></p><p><span style="font-size: medium;">Types of API Authentication</span></p><p><span style="font-size: medium;">1. Basic Authentication:</span></p><p><span style="font-size: medium;">Basic authentication is the simplest form of API authentication. It involves sending a username and password in plain text with every request to the API. This method is not secure as the credentials are sent unencrypted, making it vulnerable to interception by third parties. Therefore, basic authentication should only be used for internal use cases where the API is hosted on a trusted domain.</span></p><p><span style="font-size: medium;">2. Digest Authentication:</span></p><p><span style="font-size: medium;">Digest authentication is an improvement over basic authentication. It uses a challenge-response mechanism that requires clients to authenticate by responding with a nonce (a random number) and a response value derived from the client's username, password, and salt. The server then verifies the response using a hash of the client's credentials and the nonce. This method is more secure than basic authentication as it doesn't send plain text credentials over the network. However, it can still be vulnerable to replay attacks if not implemented correctly.</span></p><p><span style="font-size: medium;">3. OAuth:</span></p><p><span style="font-size: medium;">OAuth (Open Authentication) is a popular authentication protocol that allows users to grant applications limited access to their resources without sharing their login credentials. Instead of sending the entire password with every request, OAuth generates a token that can be used for a specific purpose and duration. The token is generated on the client-side and passed back to the server in each request. This method provides better security than basic or digest authentication as it doesn't share plain text credentials between parties.</span></p><p><span style="font-size: medium;">4. Token-Based Authentication:</span></p><p><span style="font-size: medium;">Token-based authentication involves generating a token that can be used for authentication purposes. The token is generated on the client-side and passed back to the server with each request. The server then verifies the token using a secret key or token store. This method provides better security than basic or digest authentication as it doesn't share plain text credentials between parties.</span></p><p><span style="font-size: medium;">5. JWT (JSON Web Tokens):</span></p><p><span style="font-size: medium;">JWT is a standardized method of generating tokens that can be used for authentication purposes. The token is generated using a secret key and passed back to the server with each request. The server then verifies the token using a public key or token store. This method provides better security than basic or digest authentication as it doesn't share plain text credentials between parties.</span></p><p><span style="font-size: medium;">6. Cookie-Based Authentication:</span></p><p><span style="font-size: medium;">Cookie-based authentication involves storing an authentication token in a cookie on the client-side. The server then verifies the token using the same secret key used to generate the cookie. This method provides better security than basic or digest authentication as it doesn't share plain text credentials between parties. However, it can still be vulnerable to session fixation attacks if not implemented correctly.</span></p><p><span style="font-size: medium;">7. Two-Factor Authentication:</span></p><p><span style="font-size: medium;">Two-factor authentication involves using two different forms of authentication, such as a password and a fingerprint or a password and a one-time code sent via SMS. This method provides better security than single-factor authentication methods as it requires both something you know (password) and something you have (fingerprint or code).</span></p><p><span style="font-size: medium;"><br /></span></p><p><span style="font-size: medium;">In conclusion, there are many different types of authentication methods available, each with its own advantages and disadvantages. The choice of which method to use will depend on the specific requirements of the application being developed. However, in general, multi-factor authentication methods provide better security than single-factor methods as they require multiple forms of authentication.</span></p>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-3970672972609340562014-03-23T06:50:00.002-07:002014-03-23T06:51:32.462-07:00Create byte array from string and vice versa<div dir="ltr" style="text-align: left;" trbidi="on">
Here is the code<br />
<br />
<pre class="lang-cs prettyprint prettyprinted" style="-webkit-text-stroke-width: 0px; background-color: #eeeeee; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin: 0px 0px 10px; max-height: 600px; orphans: auto; overflow: auto; padding: 5px; text-align: left; text-indent: 0px; text-transform: none; vertical-align: baseline; widows: auto; width: auto; word-spacing: 0px; word-wrap: normal;"><code style="background-color: #eeeeee; background-position: initial initial; background-repeat: initial initial; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline; white-space: inherit;"><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">static</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">byte</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">GetBytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">string</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> str</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">byte</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes </span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">byte</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Length</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">*</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">sizeof</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">)];</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">System</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Buffer</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">BlockCopy</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">str</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">ToCharArray</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(),</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: maroon; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: maroon; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Length</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">;</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">static</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">string</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">GetString</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">byte</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">)</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">{</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[]</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> chars </span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">=</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">[</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Length</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">/</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">sizeof</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">char</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">)];</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">System</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Buffer</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">BlockCopy</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: maroon; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> chars</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="lit" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: maroon; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">0</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">,</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> bytes</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">.</span><span class="typ" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: #2b91af; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">Length</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">return</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">new</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;"> </span><span class="kwd" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: darkblue; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">string</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">(</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">chars</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">);</span><span class="pln" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">
</span><span class="pun" style="background-color: transparent; background-position: initial initial; background-repeat: initial initial; border: 0px; color: black; font-size: 14px; margin: 0px; padding: 0px; vertical-align: baseline;">}</span></code></pre>
</div>
Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-48066827230445053092013-05-20T10:53:00.000-07:002013-05-24T01:46:23.188-07:00Remove index.php from Codeigniter application<div dir="ltr" style="text-align: left;" trbidi="on">
I have got a nice post here http://www.danielwmoore.com/extras/index.php?topic=7691.0<br />
<br />
<a name='more'></a><br />
<br />
<br />
<pre class="brush: php"><code>#-------------------------------------------------------------------------------
# CodeIgniter .htaccess file for the main index.php directory
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# If you must have your CI "system" directory at http://www.domain.tld/system/,
# Then I advise you to place a .htaccess file in that directory
# with "deny from all" in it.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Be sure to replace "domain.tld" with your actual domain and tld anywhere this
# appears in this file.
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Restore "allow from all" / I use a "deny from all" in some directory
# structures, especially where I am hosting multiple sub-domains that point to
# subdirectories of the main domain, this restores it.
#-------------------------------------------------------------------------------
#allow from all
#-------------------------------------------------------------------------------
# Turn off directory listings for increased security
#-------------------------------------------------------------------------------
Options -Indexes
#-------------------------------------------------------------------------------
# Turn on following symbolic links.
#-------------------------------------------------------------------------------
Options +FollowSymLinks
#-------------------------------------------------------------------------------
# Some web servers require this for index.php to be removed properly. You may
# try your .htaccess with or without the following line.
# Most work fine with it.
#-------------------------------------------------------------------------------
Options -MultiViews
#-------------------------------------------------------------------------------
# Make index.php the directory index page
#-------------------------------------------------------------------------------
DirectoryIndex index.php
#-------------------------------------------------------------------------------
# Always make sure mod_rewrite is installed before using.
# If you are on a Linux server, uncomment the line with mod_rewrite.c
# If on a Windows server using XAMPP, uncomment the line with mod_rewrite.so
#-------------------------------------------------------------------------------
<IfModule mod_rewrite.c>
#<IfModule mod_rewrite.so>
#-----------------------------------------------------------------------------
# Turn on the RewriteEngine
#-----------------------------------------------------------------------------
RewriteEngine on
#-----------------------------------------------------------------------------
# Set the base directory where the application root is located.
#-----------------------------------------------------------------------------
# If your application is at http://www.domain.tld/path/to/CI_Application/
# then uncomment the following line. Change /path/to/CI_Application/ to the
# actual URL path not including the domain.tld (or localhost).
# This includes using a subdirectory on localhost, like
# http://localhost/path/to/CI_Application/
#RewriteBase /path/to/CI_Application/
# If your application is at http://www.domain.tld/ (or is http://localhost/)
# then uncomment the following line.
RewriteBase /
#-----------------------------------------------------------------------------
# The following 2 lines will force a [url=http://www.prefix]www.prefix[/url]. If you want to make sure
# your site always displays the www subdomain, then uncomment the following
# 2 lines.
#-----------------------------------------------------------------------------
#RewriteCond %{HTTP_HOST} !^www\.domain\.tld$ [NC]
#RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]
#-----------------------------------------------------------------------------
# The following 2 lines will remove a www prefix. If you wish to remove the
# www and always have http://domain.tld instead of http://www.domain.tld
# then uncomment the following 2 lines.
#-----------------------------------------------------------------------------
#RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
#-----------------------------------------------------------------------------
# If a controler can't be found - then issue a 404 error from PHP
# Error messages (via the "error" plugin)
#-----------------------------------------------------------------------------
#ErrorDocument 403 /index.php/403/
#ErrorDocument 404 /index.php/404/
#ErrorDocument 500 /index.php/500/
#-----------------------------------------------------------------------------
# Deny any people (or bots) from the following sites: (to stop spam comments)
#-----------------------------------------------------------------------------
#RewriteCond %{HTTP_REFERER} nienschanz\.ru [NC,OR]
#RewriteCond %{HTTP_REFERER} porn\.com
#RewriteRule .* - [F]
# NOTE: If you are having trouble from a certain URL just
# add it above to forbid all visitors from that site.
#-----------------------------------------------------------------------------
# You can also uncomment this if you know the IP:
# Just place the IP address you wish to deny here.
# You may use multiple IP addresses separated by a space.
# You may also use a domain, tld, or a part thereof.
# Deny from 192.168.1.1 127.0.0.1
# Deny from .net example.com
# The above will deny from example.com and from all .net locations.
#-----------------------------------------------------------------------------
#Deny from 192.168.1.1
#-----------------------------------------------------------------------------
# METHOD #1 of HIDING PHP FILES. (There is an alternate method further down.)
# If the file is NOT the index.php file then
# Hide all PHP files so none can be accessed by HTTP.
# This may not be desirable in all cases.
#-----------------------------------------------------------------------------
#RewriteCond %{REQUEST_FILENAME} !index.php
#RewriteRule (.*)\.php$ index.php/$1
#-----------------------------------------------------------------------------
# The following lines begin the conditional setup for removing index.php
# Use either METHOD #1 or METHOD #2, but not both.
#-----------------------------------------------------------------------------
# METHOD #1
# If you want to redirect all files and directories that do not exist (404)
# then use the following 2 statements. This is how
# http://domain.tld/controller/ is redirected to http://domain.tld/index.php
# because /controller/ doesn't really exist, so now CI can use the URL to
# call the correct controller. This is the standard and default method.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# METHOD #2
# If you want to redirect all files/directories that are not a request
# for the following:
# index.php, robots.txt, favicon.ico, /public/, /img/, /css/, /js/
# then use the following statement.
# If you have other applications that are non-CI integrated into your site,
# Like a third-party forum or blog, then this will disable it. Do not
# use if you need to call third-party PHP files.
#RewriteCond $1 !^(index\.php|public|img|css|js|robots\.txt|favicon\.ico)
# ADDITIONAL REWRITE CONDITION: This may be used in addition to one of the
# above METHODs.
# METHOD #2 of HIDING PHP FILES: This is to be used exclusively of the
# method #1 of hiding PHP files listed above. Do not use both methods.
# Explanation: If you would like to hide all PHP files so none can be
# accessed by HTTP, then use the following line.
# NOTE: If you have other applications that are non-CI integrated into your
# site, like a third-party forum or blog, then this will disable it. Do not
# use if you need to call third-party PHP files.
# If you need heightened security against use of PHP files, see my tutorial
# on how to properly protect your directories.
# NOTE: I have not personally tested this condition yet. If you have tested
# it and verified it works or does not work, please contact me and tell me
# about it. http://www.danielwmoore.com/contact.
#RewriteCond %{REQUEST_FILENAME}\.php -f [NC]
#-----------------------------------------------------------------------------
# use the following line if CI is in the root of the URL.
# You may need to use index.php/$1 or index.php?/$1
# Try it with or without the ? after index.php to see which works for you.
# GoDaddy accounts require the ?
# My localhost with XAMPP on Windows also requires the ?
# Most hosts work correctly without the ?, so try it without first unless
# you know your host requires it. It is placed here so you will know where
# it goes in case you need it.
# [NC] = no case - case insensitive
# [L] = Last rule, last rewrite for this set of conditions
# [QSA] = Query String Append, should be used to prevent all redirects from
# going to your default controller, which happens on some server
# configurations.
#-----------------------------------------------------------------------------
#RewriteRule ^(.*)$ index.php?/$1 [NC,L,QSA]
RewriteRule ^(.*)$ index.php/$1 [NC,L,QSA]
#-----------------------------------------------------------------------------
# use the following if CI is in a sub-directory, and place this
# file IN that subdirectory.
# If your CI Application is at http://www.domain.tld/CI_Application/
# Replace 'CI_Application' with the name of the sub-directory.
# Try it with or without the ? after index.php to see which works for you.
# See above for the reasons for the '?'.
# Be sure that this matches the RewriteBase above.
# [NC] = no case - case insensitive
# [L] = Last rule, last rewrite for this set of conditions
# [QSA] = Query String Append, should be used to prevent all redirects from
# going to your default controller, which happens on some server
# configurations.
#-----------------------------------------------------------------------------
#RewriteRule ^(.*)$ CI_Application/index.php?/$1 [NC,L,QSA]
#RewriteRule ^(.*)$ CI_Application/index.php/$1 [NC,L,QSA]
#-------------------------------------------------------------------------------
# Don't forget to end the IfModule check for the rewrite engine.
#-------------------------------------------------------------------------------
</IfModule>
#-------------------------------------------------------------------------------
# If Mod_rewrite is NOT installed go to index.php
# Remember to use mod_rewrite.c for Linux and mod_rewrite.so for Windows.
#-------------------------------------------------------------------------------
<IfModule !mod_rewrite.c>
#<IfModule !mod_rewrite.so>
ErrorDocument 404 index.php
</IfModule></code></pre>
</div>
Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-31230708102835378202013-05-19T23:34:00.000-07:002013-05-24T01:15:05.147-07:00Send 160 character sms instead of 80 character on Samsung galaxy s3If you can not send sms of 160 character using your samsung galaxy s3 then you can use handcent app from playstore.<br/><br/>Using Handcent should fix the problem.<br/><br/>https://market.android.com/details?id=com.handcent.nextsms&hl=enTonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-34737807217413172702013-02-26T22:12:00.000-08:002013-05-24T01:35:17.946-07:00Generate Class from table using T4 template<div dir="ltr" style="text-align: left;" trbidi="on">
here is a t4 file. save it using .tt extension and change the connection accordingly and drag to visual studio solution.<br />
<br />
<br />
<br />
<a name='more'></a><br /><br />
<br />
<br />
<#@ template language="C#" debug="True" #><br />
<br />
<#@ assembly name="System" #><br />
<#@ assembly name="System.Data" #><br />
<#@ assembly name="System.Core" #><br />
<#@ assembly name="System.Xml" #><br />
<br />
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #><br />
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #><br />
<#@ assembly name="Microsoft.SqlServer.Smo" #><br />
<br />
<#@ import namespace="System" #><br />
<#@ import namespace="System.Text" #><br />
<#@ import namespace="System.Xml" #><br />
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #><br />
<#@ import namespace="System.Data.SqlClient" #><br />
<#@ import namespace="Microsoft.SqlServer.Management.Common" #><br />
<br />
namespace Namespace<br />
{<br />
<br />
<#<br />
var databaseName = "testDb";<br />
var serverConnection = new SqlConnection(<br />
@"Data Source=.\SQLEXPRESS; Integrated Security=true; Initial Catalog=" + databaseName);<br />
var svrConnection = new ServerConnection(serverConnection);<br />
<br />
Server srv = new Server(svrConnection);<br />
foreach (Table table in srv.Databases[databaseName].Tables)<br />
{<br />
<br />
#><br />
class <#= table.Name #><br />
{<br />
<#<br />
foreach (Column col in table.Columns)<br />
{<br />
#><br />
public <#= GetNetDataType(col.DataType.Name) #> <#= col.Name #> { get; set; }<br />
<#<br />
}<br />
#><br />
}<br />
<br />
<# }<br />
#><br />
}<br />
<br />
<br />
<br />
<#+<br />
public static string GetNetDataType(string sqlDataTypeName)<br />
{<br />
<br />
switch (sqlDataTypeName.ToLower())<br />
{<br />
case "bigint":<br />
return "Int64";<br />
case "binary":<br />
return "Byte[]";<br />
case "bit":<br />
return "bool";<br />
case "char":<br />
return "char";<br />
case "cursor":<br />
return string.Empty;<br />
case "datetime":<br />
return "DateTime";<br />
case "decimal":<br />
return "Decimal";<br />
case "float":<br />
return "Double";<br />
case "int":<br />
return "int";<br />
case "money":<br />
return "Decimal";<br />
case "nchar":<br />
return "string";<br />
case "numeric":<br />
return "Decimal";<br />
case "nvarchar":<br />
return "string";<br />
case "real":<br />
return "single";<br />
case "smallint":<br />
return "Int16";<br />
case "text":<br />
return "string";<br />
case "tinyint":<br />
return "Byte";<br />
case "varbinary":<br />
return "Byte[]";<br />
case "xml":<br />
return "string";<br />
case "varchar":<br />
return "string";<br />
case "smalldatetime":<br />
return "DateTime";<br />
case "image":<br />
return "byte[]";<br />
<br />
default:<br />
return string.Empty;<br />
}<br />
<br />
<br />
<br />
}<br />
#></div>
Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-15000509124671404092013-01-17T02:58:00.000-08:002013-05-24T01:15:05.218-07:00Retrieving all values from POST in asp.netHere is the code:<br/><blockquote><%@ Page Language="C#" CodeFile="~/listen.aspx.cs" Inherits="listenerTest.listen" %><br/><%<br/>Response.ClearContent();<br/>Response.ClearHeaders();<br/>Response.Clear();<br/>Response.AddHeader("Content-Type", "text/plain");<br/><br/>if (Request.Form.Count != 0)<br/>{<br/>string all = "";<br/>foreach (string name in Request.Form.AllKeys)<br/>{<br/>string value = Request.Form[name];<br/>// Do something with (name, value).<br/>all += "key:" + name + "value:" + value;<br/>}<br/>}<br/><br/>Response.End();<br/>%></blockquote>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-78396599982972098122013-01-03T22:58:00.000-08:002013-05-24T01:15:05.215-07:00Simple Form post from Codebehind C#Here is the sample code:<br/><blockquote>private void PostToUrl(string url, string parameters)<br/>{<br/>string URI = url;<br/>string myParameters = parameters;//"param1=value1&param2=value2&param3=value3";<br/><br/>using (WebClient wc = new WebClient())<br/>{<br/>wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";<br/>string HtmlResult = wc.UploadString(URI, myParameters);<br/>}<br/>}</blockquote>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-5157799998845847752013-01-03T21:33:00.000-08:002013-05-24T01:15:05.211-07:00Select an element from xml file using where clauseHere is the sample xml file<br/><blockquote><?xml version="1.0" encoding="utf-8" ?><br/><urls><br/><url keyword="RA">http://google.com </url><br/><url keyword="NC">http://google.com </url><br/></urls></blockquote><br/>Here is the sample code<br/><blockquote>XDocument doc=XDocument.Load(Server.MapPath("~/urllist.xml"));<br/>var url = (from ur in doc.Descendants("url")<br/>where ur.Attribute("keyword").Value=="RA"<br/>select ur.Value).ToList();</blockquote>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-90088244671213381912012-12-27T01:10:00.000-08:002013-05-24T01:15:05.207-07:00Upload file using JSPI found a good article to upload a file using jsp <a href="http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml">here </a>. I just modified it little so that it can upload file to the root directory of the webapp.<br/><br/><em><strong>fileindex.jsp</strong></em><br/><br/><%@ page language="java" %><br/><HTml><br/><HEAD><TITLE>Display file upload form to the user</TITLE></HEAD><br/><% // for uploading the file we used Encrypt type of multipart/form-data and input of file type to browse and submit the file %><br/><BODY> <FORM ENCTYPE="multipart/form-data" ACTION="single_upload_page.jsp" METHOD=POST><br/><br><br><br><br/><center><table border="2" ><br/><tr><center><td colspan="2"><p align="center"><B>PROGRAM FOR UPLOADING THE FILE</B><center></td></tr><br/><tr><td><b>Choose the file To Upload:</b></td><br/><td><INPUT NAME="F1" TYPE="file"></td></tr><br/><tr><td colspan="2"><p align="right"><INPUT TYPE="submit" VALUE="Send File" ></p></td></tr><br/><table><br/></center><br/></FORM><br/></BODY><br/></HTML><a name='more'></a><br/><br/><strong><em>single_upload_page.jsp</em></strong><br/><br/><%@ page import="java.io.*" %><br/><%<br/>//to get the content type information from JSP Request Header<br/>String contentType = request.getContentType();<br/>//here we are checking the content type is not equal to Null and as well as the passed data from mulitpart/form-data is greater than or equal to 0<br/>if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {<br/>DataInputStream in = new DataInputStream(request.getInputStream());<br/>//we are taking the length of Content type data<br/>int formDataLength = request.getContentLength();<br/>byte dataBytes[] = new byte[formDataLength];<br/>int byteRead = 0;<br/>int totalBytesRead = 0;<br/>//this loop converting the uploaded file into byte code<br/>while (totalBytesRead < formDataLength) {<br/>byteRead = in.read(dataBytes, totalBytesRead, formDataLength);<br/>totalBytesRead += byteRead;<br/>}<br/><br/>String file = new String(dataBytes);<br/>//for saving the file name<br/>String saveFile = file.substring(file.indexOf("filename=\"") + 10);<br/>saveFile = saveFile.substring(0, saveFile.indexOf("\n"));<br/>saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));<br/>int lastIndex = contentType.lastIndexOf("=");<br/>String boundary = contentType.substring(lastIndex + 1,contentType.length());<br/>int pos;<br/>//extracting the index of file<br/>pos = file.indexOf("filename=\"");<br/>pos = file.indexOf("\n", pos) + 1;<br/>pos = file.indexOf("\n", pos) + 1;<br/>pos = file.indexOf("\n", pos) + 1;<br/>int boundaryLocation = file.indexOf(boundary, pos) - 4;<br/>int startPos = ((file.substring(0, pos)).getBytes()).length;<br/>int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;<br/><br/>// creating a new file with the same name and writing the content in new file<br/>FileOutputStream fileOut = new FileOutputStream(getServletContext().getRealPath("") +saveFile);<br/>fileOut.write(dataBytes, startPos, (endPos - startPos));<br/>fileOut.flush();<br/>fileOut.close();<br/><br/>%><Br><table border="2"><tr><td><b>You have successfully upload the file by the name of:</b><br/><% out.println(saveFile); %></td></tr></table> <%<br/>}<br/>%>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-89923405040053612252012-12-25T21:35:00.000-08:002013-05-24T01:15:05.203-07:00jsp with beans exampleHere is an example :<br/><br/>index.jsp<br/>---------------------<br/><br/><%@page contentType="text/html" pageEncoding="UTF-8"%><br/><jsp:useBean id="us" scope="request" class="msgbean.User"></jsp:useBean><br/><%<br/>if (request.getParameter("Name") != null) {<br/>//out.write(request.getParameter("Name"));<br/>us.setName(request.getParameter("Name"));<br/>us.setEmail(request.getParameter("Email"));<br/>}<br/>%><br/><!DOCTYPE html><br/><html><br/><head><br/><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><br/><title>JSP Page</title><br/></head><br/><body><br/><form method="post"><br/><table><br/><tr><td>Name:</td><td><input type="text" name="Name"/></td></tr><br/><tr><td>Email:</td><td><input type="text" name="Email"/></td></tr><br/><tr><td><input type="submit" value="Submit"/></td></tr><br/></table><br/></form><br/><br/>You entered:<br /><br/><br/>Name: <%= us.getName()%></br><br/>Email: <%= us.getEmail()%></br><br/></body><br/></html><br/>----------------------------------<a name='more'></a><br/><br/>User.java<br/>------------------<br/><br/>package mypak;<br/><br/>public class User {<br/><br/>private String name;<br/>private String email;<br/><br/>/**<br/>* @return the name<br/>*/<br/>public String getName() {<br/>return name;<br/>}<br/><br/>/**<br/>* @param name the name to set<br/>*/<br/>public void setName(String name) {<br/>this.name = name;<br/>}<br/><br/>/**<br/>* @return the email<br/>*/<br/>public String getEmail() {<br/>return email;<br/>}<br/><br/>/**<br/>* @param email the email to set<br/>*/<br/>public void setEmail(String email) {<br/>this.email = email;<br/>}<br/>}Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-36772456159702269432012-11-25T23:48:00.000-08:002013-05-24T01:15:05.199-07:00Get number of element of specific name in a xml fileXmlDocument xdoc = new XmlDocument();<br/>xdoc.Load(Server.MapPath("~/pp1.xml"));<br/>string PersonCount = xdoc.DocumentElement.SelectNodes("//persons/person").Count.ToString();<br/>Response.Write(PersonCount);Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-83444924502231228662012-10-16T12:40:00.000-07:002013-05-24T01:15:05.195-07:00ওয়ালটন প্রিমো (অ্যান্ড্রয়েড) রিভিউআমি নিজে অনেকদিন থেকেই সনি এরিকসন এক্সপেরিয়া এক্স এইট চালাই। এক বন্ধুর জন্য গত শনিবার গেলাম এন্ড্রয়েড ফোন কিনতে। প্রথমে ভেবেছিলাম যে সিম্ফোনি w5 নিবো কিন্তু পরে নেট ঘেটে দেখলাম যে দাম এবং কনফিগারেশনের দিক থেকে ওয়ালটন প্রিমো এগিয়ে। কিনলাম ওয়ালটন এর বিজয় সরনী এর শো রুম থেকে। কেনার পর একদিন ব্যবহার করার সুযোগ পেলাম। তাতে যা দেখলাম টাকার হিসেবে অসাধারন জিনিস (আমার মতে)।<a name='more'></a><br/><br/><a href="http://dotnetdeveloperbd.files.wordpress.com/2012/10/img_20121014_054556.jpg"><img class="alignnone size-full wp-image-65" title="IMG_20121014_054556" alt="" src="http://dotnetdeveloperbd.files.wordpress.com/2012/10/img_20121014_054556.jpg" width="480" height="640" /></a><br/><br/><a href="http://dotnetdeveloperbd.files.wordpress.com/2012/10/img_20121014_054646.jpg"><img class="alignnone size-full wp-image-67" title="IMG_20121014_054646" alt="" src="http://dotnetdeveloperbd.files.wordpress.com/2012/10/img_20121014_054646.jpg" width="604" height="453" /></a><br/><br/>ফিচার<br/><br/>প্রসেসর ১ গিগাহার্জ, র্যাম ৫১৪ এমবি (যদিও শো করছিলো ৫০০এমবি), ৩.৫ ইন্চি ক্যাপাসিটিভ টাচ ডিসপ্লে (৩২০x৪৮০ পিক্সেল), ২ মেগা পিক্সেল ক্যামেরা (যদিও কোয়ালিটি ভালো না), ডুয়াল সিম, প্রক্সিমিটি সেন্সর, জিপিএস, এফএম রেডিও<br/><br/>এন্ড্রয়েড ২.৩.৬ জিন্জারব্রেড<br/><br/>ভালো দিক:<br/>মাত্র ৭৪৯০ টাকা দাম। সেই হিসেবে ১গিগাহার্জ প্রসেসর এবং ৫১২এমবি র্যাম। স্মুথ অপারেশন। আমি এ্যাংরি বার্ডস গেম খেলে দেখলাম একদম স্মুথ চলে কোনরকম আটকে যাওয়া ছাড়াই। স্কাইপি কাজ করে, এবং গুগল টক দিয়ে ভিডিও চ্যাটিং করা যায়। ভাইবার দিয়ে কল করলে কোন ঝামেলা ছাড়াই স্পষ্ট কথা বলা যায়।<br/><br/>খারাপ দিক:<br/>ক্যামেরা ভালো না। সাউন্ড খারাপ। যারা গান শোনার জন্য মোবাইল ব্যবহার করেন তারা হতাশ হবেন। সাউন্ড কোয়ালিটি খুবই খারাপ। ব্যাটারী ব্যাকআপ তেমন ভালোনা (অবশ্য এটা সব এন্ড্রয়েড এর কমন সমস্যা)। আরেকটা জিনিস দেখলাম বক্সের গায়ে লেখা 3.5” capacitive touch lens. (হা হা হা হা)<br/><br/>শেষকথা: কেউ অ্যান্ড্রয়েড ব্যবহার করতে চাইলে কিনতে পারেন। যদি না আপনার গান শোনার ইচ্ছে থাকে এই সেট দিয়ে।Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0tag:blogger.com,1999:blog-4792550003666456283.post-55819844230341086372012-09-24T02:50:00.000-07:002013-05-24T01:15:05.191-07:00Make your windows 7 laptop into wifi hotspotMake sure you have installed <strong><span style="text-decoration:underline;">Microsoft Virtual Wifi miniport adapter</span></strong><br/><br/> <br/><br/>Then make command as follows:<br/><pre>C:\Windows\system32><span style="color:#0000ff;">netsh wlan set hostednetwork mode=allow ssid=<span style="color:#0000ff;">MyWifi</span> key=password keyUsage=persistent</span><br/><br/>To start your network<br/>C:\Windows\system32><span style="color:#0000ff;">netsh wlan start hostednetwork</span><br/><br/>To Stop your network<br/>C:\><span style="color:#0000ff;">netsh wlan show hostednetwork</span><br/><br/>Share your internet connection by going to network sharing center<br/><br/><br/><br/><br/><br/></pre>Tonmoyhttp://www.blogger.com/profile/18433408053993744810noreply@blogger.com0