<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sajjad Salaria on Medium]]></title>
        <description><![CDATA[Stories by Sajjad Salaria on Medium]]></description>
        <link>https://medium.com/@xoraus?source=rss-2674269ff483------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZatpbeKOqkswI1VjifyWpA.jpeg</url>
            <title>Stories by Sajjad Salaria on Medium</title>
            <link>https://medium.com/@xoraus?source=rss-2674269ff483------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:22:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xoraus/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Demystifying REST: Understanding the Basics and Key Concepts]]></title>
            <link>https://xoraus.medium.com/demystifying-rest-understanding-the-basics-and-key-concepts-bd18fbb3b446?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd18fbb3b446</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Mon, 08 Apr 2024 09:14:37 GMT</pubDate>
            <atom:updated>2024-04-08T09:14:37.251Z</atom:updated>
            <content:encoded><![CDATA[<p>A Comprehensive Guide to Representational State Transfer for Web Development and APIs</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3vPfgcO_w-2iX8h4cWaZYQ.jpeg" /></figure><h3>REST Introduction and REST Architecture</h3><p><strong>Definition of REST:</strong></p><ul><li><strong>REST</strong> stands for <strong>Representational State Transfer</strong>.</li></ul><p>Understanding each term:</p><ul><li><strong>State</strong>: Represents data.</li><li><strong>Representational</strong>: Denotes a data format (e.g., XML, JSON, YAML, HTML, plain text).</li><li><strong>Transfer</strong>: Involves transferring data between consumer and provider using HTTP protocol.</li></ul><p><strong>REST Architecture Overview:</strong></p><ul><li>Involves a <strong>client-server model</strong> where a client sends HTTP requests to a server, and the server processes and responds.</li><li>Clients can be diverse (e.g., Android, iOS, desktop, web applications).</li><li><strong>Independence</strong>: Client and server should be independent; changes in one shouldn’t affect the other.</li><li><strong>Message Exchange Format</strong>: Data exchanged between client and server typically in JSON or XML.</li></ul><p><strong>Key Points about REST:</strong></p><ul><li><strong>Origin</strong>: Coined by <strong>Roy Fielding</strong>, inventor of HTTP protocol.</li><li><strong>Purpose</strong>: Facilitates communication between applications over HTTP, akin to browser-server interaction.</li><li><strong>Popularity</strong>: Rapid adoption due to increased mobile device usage, allowing web and mobile clients to consume the same APIs.</li></ul><p><strong>REST Architectural Constraints:</strong></p><ul><li><strong>Client-Server Architecture</strong>: Client and server are distinct, independent components.</li><li><strong>Statelessness</strong>: No session data stored on the server; each request is stateless.</li><li><strong>Cacheability</strong>: Clients can cache responses for improved performance.</li><li><strong>Uniform Interface</strong>: Provides a consistent, generic interface for interactions, simplifying architecture.</li><li><strong>Layered System</strong>: Servers can have multiple layers for scalability and load balancing.</li><li><strong>Code on Demand (Optional)</strong>: Allows clients to download and execute code from the server, though rarely used.</li></ul><p><strong>Conclusion:</strong></p><ul><li>RESTful APIs follow these architectural constraints to ensure effective communication between clients and servers.</li></ul><h3>Resource, URI and Sub-resource</h3><p><strong>Resource in REST:</strong></p><ul><li>In a REST-based system, <strong>everything</strong> is a <strong>resource</strong>.</li><li>A <strong>resource</strong> is anything exposed to the outside world through the application.</li><li>Examples of resources in various systems: Employee, Department, Address, Project, Task (Employee Management System); Student, Teacher, Class, Subject, School (Student Management System); Post, Comment, User, Tags, Category (Blog Application).</li><li>CRUD (Create, Read, Update, Delete) REST APIs are typically created for each resource.</li><li>Clients consume these REST APIs to perform actions on resources.</li></ul><p><strong>Uniform Resource Identifier (URI):</strong></p><ul><li><strong>URI</strong> is used to <strong>identify</strong> resources.</li><li>Each URI should be <strong>unique</strong>.</li></ul><p>Examples of URIs for CRUD operations on a Post resource:</p><ul><li>URL to list posts</li><li>URL to retrieve a post by ID</li><li>URL to create a new post</li><li>URL to update a post</li><li>URL to delete a post</li></ul><p><strong>Sub-resource:</strong></p><ul><li><strong>Sub-resources</strong> are used to model relationships in REST APIs.</li><li>Relationships are modeled by placing a sub-resource after a resource.</li><li>Pattern: resource/resource-id/sub-resource/sub-resource-id.</li><li>Example: In a blog application, posts can have comments as sub-resources. To retrieve comments for a particular post, the URI would be post/post-id/comments.</li><li>Sub-resources are used when child objects cannot exist without their parent (e.g., comments cannot exist without a post, drivers cannot exist without a car).</li><li>Deleting the parent resource may also delete the associated sub-resources.</li></ul><h3>Http Methods</h3><ul><li><strong>GET</strong>: Used to retrieve or get a collection or a single resource. Not for modifying or creating resources.</li><li><strong>POST</strong>: Utilized to create a new resource. Typically used for adding new entities like employees, students, or users.</li><li><strong>PUT</strong>: Employed to update an existing resource. Used when modifying existing entities such as updating employee details or student information.</li><li><strong>DELETE</strong>: Used to delete a collection or a single resource. Enables removal of entities like students or specific records identified by their unique identifiers.</li><li><strong>PATCH</strong>: Optionally used to partially update an existing resource.</li></ul><p><strong>Usage Examples:</strong></p><ul><li><strong>GET Method</strong>: Retrieve a list of posts or a single post by ID.</li><li><strong>POST Method</strong>: Create a new post in a blog application.</li><li><strong>PUT Method</strong>: Update an existing post by specifying its ID.</li><li><strong>DELETE Method</strong>: Delete a post or other resources by their IDs.</li></ul><p><strong>Additional Note:</strong></p><ul><li><strong>PATCH Method</strong>: Used for partial updates to existing resources, updating specific fields without modifying the entire resource.</li></ul><h3>HTTP Status Codes</h3><p><strong>Overview:</strong></p><ul><li><strong>HTTP status codes</strong> indicate the outcome of a request made by a client to a server.</li><li>These status codes help in understanding the status of the request and guide further actions.</li></ul><p><strong>200 OK:</strong></p><ul><li><strong>Indicates</strong>: Request is successful, and response content is returned to the client as appropriate.</li><li><strong>Example</strong>: Retrieving a collection of blog posts or a single post.</li></ul><p><strong>201 CREATED:</strong></p><ul><li><strong>Indicates</strong>: Request is successful, and a new resource is created.</li><li><strong>Example</strong>: Creating a new blog post; server responds with the newly created resource.</li></ul><p><strong>400 Bad Request:</strong></p><ul><li><strong>Indicates</strong>: Server failed to process the request due to malformed syntax in the request.</li><li><strong>Example</strong>: Client passed invalid parameters; server responds with a bad request status code.</li></ul><p><strong>401 Unauthorized:</strong></p><ul><li><strong>Indicates</strong>: Authentication is required for the resource, and the client needs to provide appropriate credentials.</li><li><strong>Example</strong>: Accessing a protected resource without valid authentication; server responds with an unauthorized status code.</li></ul><p><strong>403 Forbidden:</strong></p><ul><li><strong>Indicates</strong>: Server refuses to respond to the request, even if the request is valid.</li><li><strong>Example</strong>: Attempting to access unauthorized resources; server responds with a forbidden status code.</li></ul><p><strong>404 Not Found:</strong></p><ul><li><strong>Indicates</strong>: Requested resource is not found at the specified location.</li><li><strong>Example</strong>: Attempting to delete a blog post that does not exist; server responds with a not found status code.</li></ul><p><strong>500 Internal Server Error:</strong></p><ul><li><strong>Indicates</strong>: An unexpected error occurred on the server, and the request cannot be fulfilled.</li><li><strong>Example</strong>: Server-side error during user authentication or other processing; server responds with an internal server error status code.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd18fbb3b446" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[No More Zero Days: Embrace Consistent Progress]]></title>
            <link>https://xoraus.medium.com/no-more-zero-days-embrace-consistent-progress-ecc742e7e3d8?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/ecc742e7e3d8</guid>
            <category><![CDATA[motivation]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[consistency]]></category>
            <category><![CDATA[challenge]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Thu, 05 Oct 2023 13:23:03 GMT</pubDate>
            <atom:updated>2023-10-05T13:23:03.387Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In a world filled with distractions and demands, it’s easy to fall into the trap of procrastination and inaction. Many of us have experienced those days when we promise ourselves that we’ll get a lot done, but as the clock ticks away, we find ourselves doing nothing. It’s time to say goodbye to those “zero work days” and embrace the concept of “No More Zero Days.”</p><figure><img alt="https://imgur.com/Eqf9wO1" src="https://cdn-images-1.medium.com/max/1024/0*zBMDZQM-UKZXdpAS.png" /></figure><h3>What Are Zero Work Days?</h3><p>Zero work days are those days when you don’t make any progress toward your goals or tasks. You go to bed feeling unproductive and disappointed in yourself. It’s a cycle that can be demotivating and detrimental to your personal and professional growth.</p><blockquote><em>The “No More Zero Days” Philosophy</em></blockquote><p>The “No More Zero Days” philosophy is a simple yet powerful concept that encourages you to do something, no matter how small, every day to avoid zero work days. As stated in the original quote, “If you didn’t do anything till 11:58 PM, do something. Do one pushup, write one sentence, read something, but NO ZERO WORK DAYS.”</p><p>Here’s why this philosophy can be a game-changer for your life:</p><ol><li><strong>Consistency is Key</strong>: Consistent effort, no matter how small, adds up over time. By committing to do something every day, you build momentum and make progress towards your goals.</li><li><strong>Overcoming Procrastination</strong>: Zero work days often result from procrastination. The “No More Zero Days” philosophy helps you break the cycle by taking that initial step, no matter how small, to start a task.</li><li><strong>Developing Habits</strong>: By consistently doing something every day, you can form positive habits. Whether it’s exercise, writing, reading, or any other skill, regular practice leads to improvement.</li><li><strong>Boosting Motivation</strong>: Achieving even a small task on a tough day can be incredibly motivating. It reminds you that you are making progress, no matter how slow it may seem.</li><li><strong>Eliminating Regret</strong>: When you commit to “No More Zero Days,” you’ll no longer go to bed with the regret of not accomplishing anything. Instead, you’ll feel a sense of accomplishment and satisfaction.</li></ol><p>Examples of “No More Zero Days”</p><ol><li><strong>Fitness</strong>: Even on your busiest days, you can do a quick set of push-ups, squats, or a short yoga routine to keep yourself active.</li><li><strong>Writing</strong>: Write a single sentence, a paragraph, or even just jot down a few ideas for your writing project.</li><li><strong>Reading</strong>: Read a page or a chapter of a book, an article, or an educational resource.</li><li><strong>Learning</strong>: Spend a few minutes learning a new language, a skill, or studying for a course.</li><li><strong>Cleaning</strong>: Tackle a small cleaning task in your home or workspace.</li></ol><h3>Conclusion</h3><p>“No More Zero Days” is a powerful philosophy that can transform your life by promoting consistent progress and helping you overcome procrastination. Remember, even the smallest effort can lead to significant results over time. Embrace this philosophy, and you’ll find yourself on a path to success, one non-zero day at a time. Say goodbye to zero work days and welcome a future filled with growth, accomplishment, and motivation.</p><p><strong>Reference:</strong></p><ol><li>I first came across the idea of “No Zero Days” on <a href="https://www.reddit.com/r/getdisciplined/comments/1q96b5/comment/cdah4af/">reddit</a> by /u/ryans01</li><li><a href="https://imgur.com/Eqf9wO1">https://imgur.com/Eqf9wO1</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ecc742e7e3d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Nature of Human Violence]]></title>
            <link>https://xoraus.medium.com/exploring-the-nature-of-human-violence-e73b0a8169c9?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/e73b0a8169c9</guid>
            <category><![CDATA[war]]></category>
            <category><![CDATA[psychology]]></category>
            <category><![CDATA[violence]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Mon, 28 Aug 2023 16:27:47 GMT</pubDate>
            <atom:updated>2023-08-28T16:27:47.215Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>Unveiling Instincts, Authority, and Manipulation</blockquote><p>In the quest to understand human behavior, a fundamental question arises: are humans inherently violent creatures? This intricate inquiry is the focal point of a captivating section within a thought-provoking video that delves into the depths of human nature. Through careful analysis and insightful discussion, the video brings to light the complex interplay between our instincts, social dynamics, and external influences that shape our perception of violence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l_OYrXYceMqakxKV" /><figcaption>Photo by <a href="https://unsplash.com/@we_the_royal?utm_source=medium&amp;utm_medium=referral">Duncan Kidd</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Evolutionary Roots and Social Constraints</h3><p>At the core of this exploration lies the concept of the fight or flight response — an instinctual mechanism developed through millennia of evolution. Anthropologists posit that this response, deeply ingrained within our genetic makeup, hints at a primal inclination toward violence as a means of self-preservation. However, the video contends that the evolution of human society has woven a complex tapestry of social interactions that have tempered these instincts. The emergence of the neocortex, responsible for steering our social behaviors and cognitive abilities, is highlighted as a significant factor in mitigating our instinctual tendencies towards violence. Thus, while violence might have once been a survival necessity, the video proposes that it is not an innate trait but rather a malleable aspect of human nature.</p><h3>The Milgram Experiment: Probing the Shadows of Obedience</h3><p>Venturing further into the intricacies of human behavior, the video takes a deep dive into the infamous Milgram experiment — a psychological study conducted by Stanley Milgram to explore how ordinary individuals could commit horrendous acts under the influence of authority figures. This experiment, which demanded participants to administer electric shocks to others, revealed a shocking finding: 65% of participants were willing to inflict severe harm under authoritative instructions. The video elucidates that this experiment is not a testament to an inevitable violent fate but rather a reflection of the power dynamics at play. It emphasizes the coexistence of love and compassion as intrinsic to human nature, challenging the notion that violence is our sole inclination.</p><h3>Doubts, Manipulation, and Perceived Threats</h3><p>As the video proceeds, it casts a critical eye on the Milgram experiment’s authenticity and the broader implications of its findings. Recent research has unveiled doubts and controversies surrounding the experiment, revealing that many participants perceived the situation as contrived and were merely aiding the researchers in achieving their intended outcomes. This discovery raises questions about the validity of the experiment’s conclusions and the broader implications it holds for our understanding of human behavior. The video provokes thought by questioning why this experiment’s contested findings continue to occupy our discourse. It hints at the possibility of manipulation by external forces, manipulating our perceptions to foster a sense of constant threat and fear.</p><h3><strong>Embracing Compassion, Rejecting Violence</strong></h3><p>Ultimately, the video concludes by reiterating that while human hands may possess the physical capability for violence, they are also vessels of connection and compassion. It underscores the power of choice — a choice to perceive each other as equals and to shun violence in favor of empathy. In doing so, the video argues, humans can rise above their apprehensions and thwart the attempts of those who seek to control through fear and suspicion. It challenges the need for hierarchical authority and raises the question of whether it is a genuine means of protection or merely a mechanism for societal control.</p><p>In a world often marred by violence and discord, the exploration within this video segment offers a glimmer of hope — a reminder that within the complexities of our nature, we possess the agency to transcend our primal instincts. By embracing our capacity for compassion and equality, humanity can navigate the currents of manipulation and control, ultimately steering toward a future defined by cooperation, understanding, and harmony.</p><p>Refrence: <a href="https://youtu.be/jGJEy9Bk6Ts">Are humans inherently violent?</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e73b0a8169c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Export Your Twitter Following List to a CSV File]]></title>
            <link>https://xoraus.medium.com/how-to-export-your-twitter-following-list-to-a-csv-file-d3228d7d5650?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3228d7d5650</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[twitter]]></category>
            <category><![CDATA[scraping]]></category>
            <category><![CDATA[hacks]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 15:32:59 GMT</pubDate>
            <atom:updated>2023-03-15T15:32:59.448Z</atom:updated>
            <content:encoded><![CDATA[<p>Are you looking for a way to export your Twitter following list to a CSV file? In this article, we’ll show you how to do it using Node.js and the Twitter API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*grkcoMUfet033FE8" /><figcaption>Photo by <a href="https://unsplash.com/@alexbemore?utm_source=medium&amp;utm_medium=referral">Alexander Shatov</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>First, you’ll need to install the twitter and csv-writer packages. You can do this by running npm install twitter csv-writer in your terminal.</p><pre>const Twitter = require(&#39;twitter&#39;);<br>const createCsvWriter = require(&#39;csv-writer&#39;).createObjectCsvWriter;<br>const fs = require(&#39;fs&#39;);</pre><p>Next, set up a Twitter API client by creating a new instance of the Twitter class from the twitter package. You’ll need to provide your consumer key, consumer secret, access token key, and access token secret as options when creating the client.</p><pre>/ set up Twitter API client<br>const client = new Twitter({<br>  // consumer_key: &#39;your_consumer_key&#39;,<br>  // consumer_secret: &#39;your_consumer_secret&#39;,<br>  // access_token_key: &#39;your_access_token_key&#39;,<br>  // access_token_secret: &#39;your_access_token_secret&#39;<br>});</pre><p>After setting up the Twitter API client, set up a CSV writer using the createObjectCsvWriter method from the csv-writer package. Specify the path where you want to save the CSV file and define the headers for each column in the CSV file.</p><pre>// set up CSV writer<br>const csvWriter = createCsvWriter({<br>  path: &#39;following.csv&#39;,<br>  header: [<br>    {id: &#39;name&#39;, title: &#39;Name&#39;},<br>    {id: &#39;screen_name&#39;, title: &#39;Screen Name&#39;},<br>    {id: &#39;description&#39;, title: &#39;Description&#39;},<br>    {id: &#39;location&#39;, title: &#39;Location&#39;},<br>    {id: &#39;url&#39;, title: &#39;URL&#39;},<br>    {id: &#39;followers_count&#39;, title: &#39;Followers&#39;},<br>    {id: &#39;friends_count&#39;, title: &#39;Following&#39;},<br>    {id: &#39;created_at&#39;, title: &#39;Joined&#39;},<br>    {id: &#39;verified&#39;, title: &#39;Verified&#39;}<br>  ]<br>});</pre><p>Now that everything is set up, it’s time to retrieve your following list from Twitter. The code snippet uses a recursive function called getFollowing that retrieves 200 users at a time (the maximum allowed by the Twitter API) until all pages of results have been retrieved.</p><p>The function uses the client.get method from the Twitter API client to send a GET request to the &#39;friends/list&#39; endpoint with parameters specifying that 200 users should be returned per page and providing a cursor value for pagination. The cursor is initially set to -1 (the first page) and is updated with each subsequent call to retrieve more pages of results.</p><pre>// get following list and write to CSV<br>let cursor = -1; // initialize cursor to first page<br>let followingData = [];</pre><p>The data returned by each call is added to an array called followingData, which stores objects representing each user in your following list. Each object contains properties such as name, screen name, description, location, URL, followers count, friends count (i.e., following count), created at date/time (i.e., when they joined Twitter), and whether or not they are verified.</p><pre>function getFollowing() {<br>  client.get(&#39;friends/list&#39;, { count: 200, cursor: cursor }, function(error, following, response) {<br>    if (error) throw error;<br>    followingData = followingData.concat(following.users.map(user =&gt; ({<br>      name: user.name,<br>      screen_name: user.screen_name,<br>      description: user.description,<br>      location: user.location,<br>      url: user.url,<br>      followers_count: user.followers_count,<br>      friends_count: user.friends_count,<br>      created_at: user.created_at,<br>      verified: user.verified<br>    })));<br>    // check if there are more pages to retrieve<br>    if (following.next_cursor_str != &#39;0&#39;) {<br>      cursor = following.next_cursor_str;<br>      getFollowing();<br>    } else {<br>      // write following data to CSV<br>      csvWriter.writeRecords(followingData)<br>        .then(() =&gt; console.log(&#39;Following list downloaded as following.csv&#39;))<br>        .catch(error =&gt; console.error(error));<br>    }<br>  });<br>}</pre><p>Once all pages of results have been retrieved (indicated by when following.next_cursor_str == &#39;0&#39;, meaning there are no more pages), then write all data stored in followingData array into csv file using csvWriter.writeRecords(followingData).</p><pre>getFollowing();</pre><p>And that’s it! Run this script using node command in terminal and you should see message “Following list downloaded as following.csv” indicating successful download of your twitter following list into csv file.</p><p>Here the link for complete script:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11da2a3b6049d1c7fc1e77842489375a/href">https://medium.com/media/11da2a3b6049d1c7fc1e77842489375a/href</a></iframe><p>Follow for more tricks and tips:</p><p><a href="https://github.com/xoraus">xoraus - Overview</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3228d7d5650" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What Top Product-Based Companies Look for in Candidates.]]></title>
            <link>https://xoraus.medium.com/breaking-into-the-big-leagues-what-top-product-based-companies-look-for-in-candidates-70e0c4a49e74?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/70e0c4a49e74</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[jobs]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 14:38:42 GMT</pubDate>
            <atom:updated>2023-01-20T10:01:20.799Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Top Product-Based Companies Look for in Candidates. Tips from Senior Software Engineer at Microsoft (16 YOE)</h3><blockquote>“Lessons Learned: Insights from a Seasoned Software Engineer”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g6Ebw_iGh5L8GlDl2cHHZg.jpeg" /></figure><p><strong>Question 1</strong> — What patterns have you observed among the students you have assisted in the past? Can you distinguish between those who have succeeded and those who have not?</p><p><strong>Answers</strong> — From my experience, I have found that students who succeed in their careers as software developers tend to be those who are consistently curious and willing to learn new things, who can work well in teams, and who can effectively communicate their ideas. On the other hand, students who struggle tend to be those who are not willing to put in the necessary effort to learn and grow, who are not able to work well with others, or who struggle to communicate their ideas effectively.</p><p><strong>Question 2</strong> — What extra effort should I put apart from Scaler?</p><p><strong>Answers</strong> -In addition to the Scaler program, I would recommend putting in extra effort to practice your coding skills by working on personal projects or contributing to open-source projects. It’s also important to keep learning and staying up to date with the latest technologies and industry trends.</p><p><strong>Question 3</strong> — Things that are expected from the candidates appearing for the top product-based company. (Person with 0 Experience)</p><p><strong>Answers</strong> — Companies like the ones you mentioned (FAANG) typically look for candidates who have strong technical skills, the ability to learn and adapt quickly, and the ability to work well in a team. It’s important to be able to demonstrate these skills through your projects and experiences, even if you don’t have any professional experience yet.</p><p><strong>Question 4</strong> — What is expected from an entry-level Software Developer? (How to be a really useful asset for the company)</p><p><strong>Answers</strong> — As an entry-level software developer, it’s important to be willing to learn and be open to feedback. You should also be able to work well in a team, communicate effectively, and be able to take on responsibilities and complete tasks independently.</p><p><strong>Question 5</strong> — Can you share any experiences or lessons learned from your career that you think would be helpful for a student to know?</p><p><strong>Answers</strong> — One lesson I learned early on in my career is the importance of continuous learning. Technology and the industry are always evolving, and it’s important to stay up to date and continually improve your skills in order to be a valuable asset to your company.</p><p><strong>Question 6</strong> — How important is mathematics/core Computer Science for an Engineer?</p><p><strong>Answers</strong> — Math and core computer science concepts are important for software engineering, but the specific level of expertise required can vary depending on the role and the company. It’s important to have a strong foundation in these subjects, but it’s also important to be able to apply your knowledge and skills to solve real-world problems.</p><p><strong>Question 7</strong> — Advice on Open Source.</p><p><strong>Answers</strong> — Participating in open-source projects can be a great way to gain experience, build your portfolio, and contribute to the developer community. I would recommend finding a project that aligns with your interests and skills, and contributing in whatever way you can, whether it be through code, documentation, or testing.</p><p><strong>Question 8 </strong>— How to develop Problem-Solving Skills</p><p><strong>Answers</strong> — Developing problem-solving skills can be achieved through practice, whether it be through working on personal projects or participating in online coding challenges. It’s also important to seek out diverse experiences and perspectives, as this can help you approach problems from different angles.</p><p><strong>Question 9</strong> — If everything were to happen according to the plan? What package should I expect from the company?</p><p><strong>Answers</strong> — It’s difficult to predict exactly what package you might expect from a company, as it can vary based on factors such as the company, the location, and the specific role. That being said, I would recommend focusing on building your skills and gaining relevant experience rather than worrying too much about the specific package you might receive.</p><p><strong>Question 10</strong> — Is Scaler Backend/FullStack Curriculum enough to get a job?</p><p><strong>Answers</strong> — The Scaler program is designed to prepare you for a career as a software developer, but ultimately it’s up to you to put in the necessary effort and use the skills you’ve learned to land a job. It’s possible that completing the program and gaining some real-world experience through internships or personal projects could make you a more competitive candidate.</p><p><strong>Question 11</strong> — What skills should I focus on in the Future Job Market (in 10 years)?</p><p><strong>Answers</strong> — It’s hard to predict exactly what skills will be in demand in the job market 10 years from now, as technology and the industry are constantly evolving. That being said, I would recommend focusing on building a strong foundation in computer science and software engineering principles and staying up to date with the latest technologies and trends. It’s also important to develop soft skills such as communication, collaboration, and problem-solving.</p><p><strong>Question 12</strong> — How to work on different tech stacks? (How to learn/switch fast).</p><p><strong>Answer</strong> — To work on different tech stacks, it’s important To work on different tech stacks, it’s important to have a strong foundation in computer science and software engineering principles, as these concepts can be applied to any technology. It’s also important to be proactive about learning and staying up to date with new technologies and languages. One way to do this is by working on personal projects or contributing to open-source projects that use different tech stacks. You can also learn from online resources or take courses to gain a deeper understanding of the technologies you’re interested in.</p><p><strong>Question 13</strong> — If I were an Intern under your guidance, What would you expect me do on my own?</p><p><strong>Answer</strong> — As an intern, I would expect you to take on responsibilities and tasks independently, and to be proactive about learning and asking for help when needed. I would also expect you to be a team player and to contribute to the team in any way you can.</p><p><strong>Question 14</strong> — Java VS Python VS Javascript</p><p><strong>Answer</strong> — It’s difficult to compare programming languages directly, as the “best” language for a given task can depend on the specific requirements and constraints of that task. That being said, all three languages you mentioned (Java, Python, and JavaScript) are popular and widely used in the industry, and each has its own strengths and weaknesses. It’s important to have a strong foundation in at least one language and to be open to learning and working with new languages as needed.</p><p><strong>Question 15</strong> — Can you recommend any resources (books, online courses, etc.) that have helped you in your career development?</p><p><strong>Answer</strong> — Focus on Scaler for the first month then read books on software development and computer science (such as “Cracking the Coding Interview” and “Clean Code”) Blogs and articles from industry experts (such as the Google Developers Blog and the Microsoft Developer Blog) Participating in open source projects and attending meetups and conferences related to my areas of interest.</p><p>I hope you like this post :)</p><p>Let’s connect :)</p><p><a href="https://www.linkedin.com/in/sajjadsalaria/">https://www.linkedin.com/in/sajjadsalaria/</a></p><p><a href="https://twitter.com/xoraus">https://twitter.com/xoraus</a></p><p><a href="https://github.com/xoraus/CrackingTheSQLInterview">GitHub - xoraus/CrackingTheSQLInterview: &quot;Cracking the SQL Interview&quot; is a comprehensive guide for individuals who are preparing for a job interview related to SQL.</a></p><p>🔴 Disclaimer — I asked these question to my mentor who’s working in Microsoft. I have extrapolated certain things from his answers based on my readings of the trends in the Software industry from various talks, blogs, videos &amp; seminars etc. <a href="https://xoraus.hashnode.dev/breaking-into-the-big-leagues-tips-from-senior-software-engineer-at-microsoft-16-yoe">https://xoraus.hashnode.dev/breaking-into-the-big-leagues-tips-from-senior-software-engineer-at-microsoft-16-yoe</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70e0c4a49e74" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cracking the SQL Interview]]></title>
            <link>https://medium.com/swlh/cracking-the-sql-interview-eaa0dd82ad3e?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa0dd82ad3e</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[interview-questions]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Sun, 01 Sep 2019 06:53:03 GMT</pubDate>
            <atom:updated>2023-03-15T15:45:50.303Z</atom:updated>
            <content:encoded><![CDATA[<h3>A comprehensive guide before your next interview</h3><ol><li><strong>SQL was developed as an integral part of</strong></li></ol><p>SQL — Structured Query Language is a domain-specific language used in programming and designed for managing data held in a relational database management system (RDBMS), or for stream processing in a relational data stream management system (RDSMS).</p><p>Although SQL is an ANSI (American National Standards Institute) standard, there are different versions of the SQL language.</p><p>However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar manner.</p><p>Note: Most of the SQL database programs also have their own proprietary extensions in addition to the SQL standard!</p><p>What Can SQL do?</p><ul><li>SQL can execute queries against a database</li><li>SQL can retrieve data from a database</li><li>SQL can insert records in a database</li><li>SQL can update records in a database</li><li>SQL can delete records from a database</li><li>SQL can create new databases</li><li>SQL can create new tables in a database</li><li>SQL can create stored procedures in a database</li><li>SQL can create views in a database</li><li>SQL can set permissions on tables, procedures, and views</li></ul><p><strong>2. What does SQL stand for?</strong></p><p>SQL stands for Structured Query Language.<br>SQL lets you access and manipulate databases.<br>SQL is an ANSI (American National Standards Institute) standard.</p><p><strong>3. SQL is (referring to it as a Programming Language)</strong></p><p><strong>SQL is a declarative language in which the expected result or operation is given without the specific details about how to accomplish the task.</strong> The steps required to execute SQL statements are handled transparently by the SQL database. Sometimes <strong>SQL is characterized as non-procedural</strong> because procedural languages generally require the details of the operations to be specified, such as opening and closing tables, loading and searching indexes, or flushing buffers and writing data to filesystems. Therefore, SQL is considered to be designed at a higher conceptual level of operation than procedural languages because the lower level logical and physical operations aren’t specified and are determined by the SQL engine or server process that executes it.</p><p><strong>4. Which of the following is NOT a SQL command? (SELECT, REMOVE, UPDATE, INSERT)</strong></p><p>REMOVE is not a valid SQL command.</p><p><strong>Some of The Most Important SQL Commands</strong></p><pre>SELECT - extracts data from a database<br>UPDATE - updates data in a database<br>DELETE - deletes data from a database<br>INSERT INTO - inserts new data into a database<br>CREATE DATABASE - creates a new database<br>ALTER DATABASE - modifies a database<br>CREATE TABLE - creates a new table<br>ALTER TABLE - modifies a table<br>DROP TABLE - deletes a table<br>CREATE INDEX - creates an index (search key)<br>DROP INDEX - deletes an index</pre><p><strong>5. What is MySQL?</strong></p><p>MySQL is the most popular Open Source SQL database management system developed, distributed, and supported by Oracle Corporation.</p><p><strong>Another common SQL interview question regarding MySQL may come in a different form</strong></p><p>“<strong>What is the difference between SQL and MySQL?</strong>” or <strong>Difference between SQL and MySQL:</strong></p><p>SQL is a structured query language that is used for manipulating and accessing the relational database, on the other hand, MySQL itself is a relational database that uses SQL as the standard database language.</p><p><strong>6. What are some properties of PL/SQL?</strong></p><p>PL/SQL is a combination of SQL along with the procedural features of programming languages. It was developed by Oracle Corporation in the early 90’s to enhance the capabilities of SQL. PL/SQL is one of three key programming languages embedded in the Oracle Database, along with SQL itself and Java.</p><p>Another common SQL interview question regarding PL/SQL may come in a different form:</p><p>“What is the difference between SQL and PL/SQL? or Difference between SQL and PL/SQL:</p><p>SQL is a Structured Query Language used to issue a single query or execute a single insert/update/delete.</p><ul><li>PL-SQL is a programming language SQL, used to write full programs using variables, loops,operators etc. to carry out multiple selects/inserts/updates/deletes.</li><li>SQL may be considered as the source of data for our reports, web pages and screens.</li><li>PL/SQL can be considered as the application language similar to Java or PHP. It might be the language used to build, format and display those reports, web pages and screens.</li><li>SQL is a data oriented language used to select and manipulate sets of data.</li><li>PL/SQL is a procedural language used to create applications.</li></ul><h4>SQL vs. PL-SQL</h4><ul><li>SQL is used to write queries, DDL and DML statements.</li><li>PL/SQL is used to write program blocks, functions, procedures triggers,and packages.</li><li>SQL is executed one statement at a time.</li><li>PL/SQL is executed as a block of code.</li><li>SQL is declarative, i.e., it tells the database what to do but not how to do it. Whereas, PL/SQL is procedural, i.e., it tells the database how to do things.</li><li>SQL can be embedded within a PL/SQL program. But PL/SQL cant be embedded within a SQL statement.</li></ul><p><strong>7. What are the possible values for the BOOLEAN data field in MySQL?</strong></p><p>MySQL uses TINYINT(1) data type to represent boolean values. A value of zero is considered false . Non-zero values are considered true .</p><p><strong>8. What data type would you choose if you wanted to store the distance (rounded to the nearest mile)?</strong></p><pre>INTEGER (or INT )</pre><p><strong>9. Which are valid SQL keywords (statements &amp; clauses)</strong></p><ul><li>SELECT — extracts data from a database</li><li>FROM — clause is used to specify the tables to extract data from</li><li>WHERE — clause is used to extract only those records that fulfill a specified condition.</li><li>GROUP BY — is often used with aggregate functions (COUNT , MAX , MIN , SUM , AVG ) to group the result-set by one or more columns.</li><li>HAVING — clause was added to SQL because the WHERE keyword could not be used with aggregate functions.</li><li>ORDER BY — keyword is used to sort the result-set in ascending or descending order.</li><li>UPDATE — updates data in a database</li><li>DELETE — deletes data from a database</li><li>INSERT INTO — inserts new data into a database</li><li>CREATE DATABASE — creates a new database</li><li>ALTER DATABASE — modifies a database</li><li>CREATE TABLE — creates a new table</li><li>ALTER TABLE — modifies a table</li><li>DROP TABLE — deletes a table</li><li>CREATE INDEX — creates an index (search key)</li><li>DROP INDEX — deletes an index</li></ul><p><strong>10. Which of the following are valid SQL comments?</strong></p><p>Comments are used to explain sections of SQL statements, or to prevent execution of SQL statements.</p><p>Single line comments start with — .</p><p>Any text between — and the end of the line will be ignored (will not be executed).</p><p>The following example uses a single-line comment as an explanation:</p><pre>--Select all:<br>SELECT * FROM Customers;</pre><p>Multi-line comments start with /* and end with */ .</p><p>Any text between /* and */ will be ignored.</p><p>The following example uses a multi-line comment as an explanation:</p><pre>/*Select all the columns<br>of all the records<br>in the Customers table:*/<br>SELECT * FROM Customers;</pre><p>The following example uses a multi-line comment to ignore many statements:</p><pre>/*SELECT * FROM Customers;<br>SELECT * FROM Products;*/<br>SELECT * FROM Suppliers;</pre><p><strong>11. Which SQL statement is used to extract data from a database?</strong></p><p>A SELECT statement retrieves zero or more rows from one or more database tables or database views.</p><p>As SQL is a declarative programming language, SELECT queries specify a result set, but do not specify how to calculate it.</p><p>The SELECT statement has many optional clauses:</p><ul><li><strong>WHERE</strong> specifies which rows to retrieve.</li><li><strong>GROUP BY</strong> groups rows sharing a property so that an aggregate function can be applied to each group.</li><li><strong>HAVING</strong> selects among the groups defined by the GROUP BY clause.</li><li><strong>ORDER BY</strong> specifies an order in which to return the rows.</li><li><strong>AS</strong> provides an alias which can be used to temporarily rename tables or columns.</li></ul><p><strong>12. How to select all records from the table ‘Products’?</strong></p><p>SELECT * FROM Products;</p><p>If you want to select all the fields available in the table, use the * syntax as this:</p><p>SELECT * FROM Products;</p><p><strong>13. Can we rename a column in the output of SQL query?</strong></p><p>Yes, using AS .</p><p>SQL aliases are used to give a column in a table, a temporary name.</p><p>Aliases are often used to make column names more readable.</p><p>An alias only exists for the duration of the query.</p><p>Alias Column Syntax:</p><ul><li>SELECT column_name AS alias_name</li><li>FROM table_name;</li></ul><p><strong>14. With SQL, how do you select a column named “FirstName” from a table named “Customers”?</strong></p><p>SELECT FirstName FROM Customers;</p><p>The SELECT statement is used to select data from a database.</p><p>The data returned is stored in a result table, called the result-set.</p><p><strong>SELECT Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name;</pre><p>Here, column1, column2, … are the field names of the table you want to select data from. If you want to select all the fields available in the table, use the following syntax:</p><p>SELECT * FROM table_name;</p><p><strong>15. What does the SQL FROM clause do?</strong></p><p>The SQL FROM clause is used to list the tables and any joins required for the SQL statement.</p><p><strong>16. Which SQL statement is used to return only different values?</strong></p><p>The SELECT DISTINCT statement is used to return only distinct (different) values.</p><p>Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.</p><p><strong>SELECT DISTINCT Syntax</strong></p><pre>SELECT DISTINCT column1, column2, ...<br>FROM table_name;</pre><p><strong>17. Consider the following schema ADDRESSES (id, street_name, number, city, state) Which of the following query would display the distinct cities in the ADDRESSES table?</strong></p><p>SELECT DISTINCT city FROM addresses;</p><p>(same theory applies as for the previous question)</p><p><strong>18. With SQL, how do you select all the records from a table named “Customers” where the value of the column “FirstName” is “John”?</strong></p><p>SELECT * FROM Customers WHERE FirstName=‘John’;</p><p>The WHERE clause is used to filter records.</p><p>The WHERE clause is used to extract only those records that fulfill a specified condition.</p><p>SQL requires single quotes around text values (most database systems will also allow double quotes).</p><p><strong>19. The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true.</strong></p><p>The WHERE clause can be combined with AND , OR , and NOT operators.</p><p>The AND and OR operators are used to filter records based on more than one condition:</p><p>The AND operator displays a record if all the conditions separated by AND are TRUE .</p><p>The OR operator displays a record if any of the conditions separated by OR are TRUE .</p><p>The NOT operator displays a record if the condition(s) is NOT TRUE .</p><p><strong>AND Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name<br>WHERE condition1 AND condition2 AND condition3 …;</pre><p><strong>OR Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name<br>WHERE condition1 OR condition2 OR condition3 ...;</pre><p><strong>NOT Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name<br>WHERE NOT condition;</pre><p><strong>20. Which of the following SQL statements has correct syntax?</strong></p><p>SELECT * FROM Table1 WHERE Column1 &gt;= 100</p><p>SQL Comparison Operators</p><ul><li>‘=’ Equal to</li><li>‘&gt;’ Greater than</li><li>‘&lt;’ Less than</li><li>‘&gt;=’ Greater than or equal to</li><li>‘&lt;=’ Less than or equal to</li><li>‘≠’ Not equal to</li></ul><p><strong>21. With SQL, how do you select all the records from a table named “Customers” where the “FirstName” is “John” and the “LastName” is “Jackson”?</strong></p><pre>SELECT * FROM Customers WHERE FirstName=&#39;John&#39; AND LastName=&#39;Jackson&#39;</pre><p>Same answers as for the previous 2 questions.</p><p>You must use the AND operator that displays a record if all the conditions separated by AND are TRUE and the = (‘equal’) comparison operator.</p><p><strong>22. How to select random 10 rows from a table?</strong></p><p>The easiest way to generate random rows in MySQL is to use the ORDER BY RAND() clause.</p><pre>SELECT * FROM tbl ORDER BY RAND() LIMIT 10;</pre><p>This can work fine for small tables. However, for big table, it will have a serious performance problem as in order to generate the list of random rows, MySQL need to assign random number to each row and then sort them.</p><p>Even if you want only 10 random rows from a set of 100k rows, MySQL need to sort all the 100k rows and then, extract only 10 of them.</p><p><strong>23. Examine the following code. What will the value of price be if the statement finds a NULL value? SELECT name, ISNULL(price, 50) FROM PRODUCTS</strong></p><p>What is a NULL Value?</p><p>A field with a NULL value is a field with no value.</p><p>If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.</p><p>Note: It is very important to understand that a NULL value is different from a zero value or a field that contains spaces. A field with a NULL value is one that has been left blank during record creation!</p><p><strong>How can you return a default value for a NULL?</strong></p><p><strong>MySQL</strong></p><p>The MySQL IFNULL() function lets you return an alternative value if an expression is NULL:</p><pre>SELECT ProductName, UnitPrice * (UnitsInStock + IFNULL(UnitsOnOrder, 0))<br>FROM Products</pre><p>or we can use the COALESCE() function, like this:</p><pre>SELECT ProductName, UnitPrice * (UnitsInStock + COALESCE(UnitsOnOrder, 0))<br>FROM Products</pre><p><strong>SQL Server</strong></p><p>The <strong>SQL Server</strong> ISNULL() function lets you return an alternative value when an expression is NULL :</p><ul><li>SELECT ProductName, UnitPrice * (UnitsInStock + ISNULL(UnitsOnOrder, 0))</li><li>FROM Products</li></ul><p><strong>MS Access</strong></p><p>The MS Access IsNull() function returns TRUE (-1) if the expression is a null value, otherwise FALSE (0) :</p><ul><li>SELECT ProductName, UnitPrice * (UnitsInStock + IIF(IsNull(UnitsOnOrder), 0, UnitsOnOrder))</li><li>FROM Products</li></ul><p><strong>Oracle</strong></p><p>The Oracle NVL() function achieves the same result:</p><ul><li>SELECT ProductName, UnitPrice * (UnitsInStock + NVL(UnitsOnOrder, 0))</li><li>FROM Products</li></ul><p><strong>24. Which operator is used to search for a specified text pattern in a column?</strong></p><p>The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.</p><p>There are two wildcards used in conjunction with the LIKE operator:</p><p>% — The percent sign represents zero, one, or multiple characters</p><p>_ — The underscore represents a single character</p><p>Examples:</p><ul><li>WHERE CustomerName LIKE ‘a%’ — Finds any values that starts with “a”</li><li>WHERE CustomerName LIKE ‘%a’ — Finds any values that ends with “a”</li><li>WHERE CustomerName LIKE ‘%or%’ — Finds any values that have “or” in any position</li><li>WHERE CustomerName LIKE ‘_r%’ — Finds any values that have “r” in the second position</li><li>WHERE CustomerName LIKE ‘a_%_%’ — Finds any values that starts with “a” and are at least 3 characters in length</li><li>WHERE ContactName LIKE ‘a%o’ — Finds any values that starts with “a” and ends with “o”</li></ul><p><strong>25. How to write a query to show the details of a student from Students table whose FirstName starts with ‘K’?</strong></p><p>SELECT * FROM Students WHERE FirstName LIKE ‘K%’.</p><p>Explanation from previous question applies.</p><p><strong>26. Which operator is used to select values within a range?</strong></p><p>The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.</p><p>The BETWEEN operator is inclusive: begin and end values are included.</p><p><strong>BETWEEN Syntax</strong></p><pre>SELECT column_name(s)<br>FROM table_name<br>WHERE column_name BETWEEN value1 AND value2;</pre><p><strong>27. Which of the following SQL statements is correct?</strong></p><p>SELECT * FROM Sales WHERE Date BETWEEN ‘01/12/2017’ AND ‘01/01/2018’</p><p>Explanation from previous question applies.</p><p><strong>28. With SQL, how do you select all the records from a table named “Customers” where the “LastName” is alphabetically between (and including) “Brooks” and “Gray”?</strong></p><pre>SELECT * FROM Customers WHERE LastName BETWEEN &#39;Brooks&#39; AND &#39;Gray&#39;</pre><p>Explanation from previous question applies.</p><p><strong>29. The ‘IN’ SQL keyword…</strong></p><p>The IN operator allows you to specify multiple values in a WHERE clause.</p><p>The IN operator is a shorthand for multiple OR conditions.</p><p><strong>IN Syntax</strong></p><pre>SELECT column_name(s)<br>FROM table_name<br>WHERE column_name IN (value1, value2, ...);</pre><p>or:</p><pre>SELECT column_name(s)<br>FROM table_name<br>WHERE column_name IN (SELECT STATEMENT); --subquery</pre><p><strong>30. What does UPPER function do?</strong></p><p>The UPPER() function converts a string to upper-case.</p><p><strong>31. What function to use to round a number to the smallest integer value that is greater than or equal to a number?</strong></p><p>The CEILING() function returns the smallest integer value that is greater than or equal to the specified number.</p><p>The CEIL() function is a synonym for the CEILING() function and also returns the smallest integer value that is greater than or equal to a number.</p><p>Example:</p><p>SELECT CEILING(25.50); — returns 26</p><p><strong>32. How to get current date in MySQL (without time)?</strong></p><p>The CURDATE() function returns the current date. This function returns the current date as a YYYY-MM-DD format if used in a string context, and as a YYYYMMDD format if used in a numeric context.</p><p>The CURRENT_DATE() function is a synonym for the CURDATE() function.</p><p><strong>33. Which SQL keyword is used to retrieve a maximum value?</strong></p><p>The MAX() function returns the largest value of the selected column.</p><p><strong>MAX() Syntax</strong></p><pre>SELECT MAX(column_name)<br>FROM table_name<br>WHERE condition;</pre><p><strong>34. Which SQL functions is used to count the number of results?</strong></p><p>The COUNT() function returns the number of rows that matches a specified criteria.</p><p><strong>COUNT() Syntax</strong></p><pre>SELECT COUNT(column_name)<br>FROM table_name<br>WHERE condition;</pre><p><strong>35. Which of the following are Aggregate Functions?</strong></p><p>SQL Aggregate functions are:</p><ul><li><strong>COUNT</strong> counts how many rows are in a particular column.</li><li><strong>SUM</strong> adds together all the values in a particular column.</li><li><strong>MIN</strong> and <strong>MAX</strong> return the lowest and highest values in a particular column, respectively.</li><li><strong>AVG</strong> calculates the average of a group of selected values.</li></ul><p><strong>36. With SQL, how can you return the number of records in the “Customers” table?</strong></p><p><em>SELECT COUNT() FROM Customers</em>*</p><p>Same answer as for the previous question.</p><p><strong>37. Which 2 SQL keywords specify the sorting direction of the result set retrieved with ORDER BY clause?</strong></p><p><strong>ASC | DESC</strong></p><p>The ORDER BY keyword is used to sort the result-set in ascending or descending order.</p><p><strong>ORDER BY Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name<br>ORDER BY column1, column2, ... ASC|DESC;</pre><p><strong>38. If you don’t specify ASC or DESC for an ORDER BY clause, the following is used by default:</strong></p><p>The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.</p><p><strong>39. Suppose a Students table has two columns, name and mark. How to get name and mark of top three students?</strong></p><p>SELECT name, mark FROM Students ORDER BY mark DESC LIMIT 3;</p><p>You have to use ORDER BY to order students by their marks and then select just the first 3 records.</p><p>The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.</p><p><strong>The SQL SELECT TOP Clause</strong></p><p>The <strong>SELECT TOP</strong> clause is used to specify the number of records to return.</p><p>The SELECT TOP clause is useful on large tables with thousands of records. Returning a large number of records can impact on performance.</p><p>Not all database systems support the SELECT TOP clause.<strong>MySQL supports the</strong> LIMIT clause to select a limited number of records, while <strong>Oracle uses</strong> ROWNUM .</p><p><strong>40. With SQL, how can you return all the records from a table named “Customers” sorted descending by “FirstName”?</strong></p><pre>SELECT * FROM Customers ORDER BY FirstName DESC;</pre><p>Same answers as for the previous 2 questions apply.</p><p><strong>41. Which of the following SQL statements is correct?</strong></p><p><em>SELECT name, COUNT(name) FROM customers GROUP BY name</em></p><p>SQL aggregate functions like COUNT , AVG , and SUM have something in common: they all aggregate across the entire table. But what if you want to aggregate only part of a table? For example, you might want to count the customers having the same name. In situations like this, you’d need to use the GROUP BY clause. GROUP BY allows you to separate data into groups, which can be aggregated independently of one another.</p><p><strong>42. What is the difference between HAVING clause and WHERE clause?</strong></p><p>Both specify a search condition but HAVING clause is used only with the SELECT statement and typically used with GROUP BY clause.</p><p>If GROUP BY clause is not used then HAVING behaves like WHERE clause only.</p><p>Here are some other differences:</p><ul><li>HAVING filters records that work on summarized GROUP BY results.</li><li>HAVING applies to summarized group records, whereas WHERE applies to individual records.</li><li>Only the groups that meet the HAVING criteria will be returned.</li><li>HAVING requires that a GROUP BY clause is present.</li><li>WHERE and HAVING can be in the same query.</li></ul><p><strong>43. What is JOIN used for?</strong></p><p>A JOIN clause is used to combine rows from two or more tables, based on a related column between them.</p><p><strong>44. What is the most common type of join?</strong></p><p>The most common type of join used in day to day queries is INNER JOIN .</p><p><strong>45. What are different JOINS used in SQL?</strong></p><p>There are several types of joins:</p><p><strong>SQL INNER JOIN Keyword</strong></p><p>The INNER JOIN keyword selects records that have matching values in both tables.</p><p><strong>SQL LEFT JOIN Keyword</strong></p><p>The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.</p><p><strong>SQL RIGHT JOIN Keyword</strong></p><p>The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.</p><p><strong>SQL FULL OUTER JOIN Keyword</strong></p><p>The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.</p><p>Note: FULL OUTER JOIN can potentially return very large result-sets!</p><p><strong>SQL Self JOIN</strong></p><p>A self JOIN is a regular join, but the table is joined with itself.</p><p><strong>SQL CROSS JOIN</strong></p><p>The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table if no WHERE clause is used along with CROSS JOIN .This kind of result is called as Cartesian Product.</p><p>If WHERE clause is used with CROSS JOIN , it functions like an INNER JOIN .</p><p><strong>46. Which of the following is NOT TRUE about the ON clause?</strong></p><p>ON clause is used to specify conditions or specify columns to JOIN . ON clause makes the query easy to understand. ON clause allows 3 way (or more) joins.</p><p><strong>47. Assume that Table A is joined to Table B. An inner join:</strong></p><p><strong>Displays rows (records) only when the values of the Key in table A and the foreign key in table B are equal.</strong></p><p>The INNER JOIN keyword selects records that have matching values in both tables.</p><p><strong>48. Can you join 3 tables together with inner join:</strong></p><p>Yes. You can join multiple tables with inner join.</p><p>For example, for a Faculty table the lookup tables might be Division, with DivisionID as the PK, Country, with CountryID as the PK, and Nationality, with NationalityID as the PK. To join Faculty to the Division, Country, and Nationality tables, the fields DivisionID, CountryID and NationalityID would need to be foreign keys in the Faculty table.</p><p>The SQL to join them would then be:</p><pre>SELECT &lt;fieldlist&gt; FROM Faculty AS f<br>INNER JOIN Division AS d ON d.FacultyID = f.FacultyID<br>INNER JOIN Country AS c ON c.FacultyID = f.FacultyID<br>INNER JOIN Nationality AS n ON n.FacultyID = f.FacultyID</pre><p><strong>49. Can you join a table to itself?</strong></p><p>Yes. The operation is called self join.</p><p><strong>Self JOIN Syntax</strong></p><pre>SELECT column_name(s)<br>FROM table1 T1, table1 T2<br>WHERE condition;</pre><p><strong>50. Which of the following is true about Cartesian Products?</strong></p><p><strong>A Cartesian product is formed when a join condition is omitted.</strong></p><p>The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table if no WHERE clause is used along with CROSS JOIN .This kind of result is called as Cartesian Product.</p><p>If WHERE clause is used with CROSS JOIN , it functions like an INNER JOIN .</p><p><strong>CROSS JOIN Syntax</strong></p><pre>SELECT *<br>FROM table1<br>CROSS JOIN table2;</pre><p><strong>51. In relational algebra the INTERSECTION of two sets (set A and Set B) corresponds to</strong></p><p><strong>A AND B</strong></p><p>The SQL INTERSECT clause/operator is used to combine two SELECT statements, but returns rows only from the first SELECT statement that are identical to a row in the second SELECT statement. This means INTERSECT returns only common rows returned by the two SELECT statements.</p><p><strong>INTERSECT Syntax</strong></p><pre>SELECT column1 [, column2 ]<br>FROM table1 [, table2 ]<br>[WHERE condition]<br>INTERSECT<br>SELECT column1 [, column2 ]<br>FROM table1 [, table2 ]<br>[WHERE condition]</pre><p><strong>52. In relational algebra the UNION of two sets (set A and Set B) corresponds to</strong></p><p><strong>A OR B</strong></p><p>The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning any duplicate rows.</p><p>To use this UNION clause, each SELECT statement must have</p><p>The same number of columns selected</p><p>The same number of column expressions</p><p>The same data type and</p><p>Have them in the same order</p><p>But they need not have to be in the same length.</p><p><strong>Union Syntax</strong></p><pre>SELECT column1 [, column2 ]<br>FROM table1 [, table2 ]<br>[WHERE condition]<br>UNION<br>SELECT column1 [, column2 ]<br>FROM table1 [, table2 ]<br>[WHERE condition]</pre><p><strong>53. What is the difference between UNION and UNION ALL?</strong></p><p><strong>UNION</strong> — returns all distinct rows selected by either query</p><p><strong>UNION ALL</strong> — returns all rows selected by either query, including all duplicates.</p><p><strong>54. Having a list of Customer Names that searched for product ‘X’ and a list of customer Names that bought the product ‘X’. What set operator would you use to get only those who are interested but did not bought product ‘X’ yet?</strong></p><p><strong>MINUS</strong></p><p>The <strong>SQL</strong> MINUS operator is used to return all rows in the first SELECT statement that are not returned by the second SELECT statement. Each SELECT statement will define a dataset. The MINUS operator will retrieve all records from the first dataset and then remove from the results all records from the second dataset.</p><p><strong>MINUS Syntax</strong></p><pre>SELECT expression1, expression2, ... expression_n<br>FROM tables<br>[WHERE conditions]<br>MINUS<br>SELECT expression1, expression2, ... expression_n<br>FROM tables<br>[WHERE conditions];</pre><p><strong>55. One (or more) select statement whose return values are used in filtering conditions of the main query is called</strong></p><p><strong>Subquery.</strong></p><p>A subquery is a SQL query nested inside a main query.</p><p>A subquery may occur in :</p><pre>A SELECT clause<br>A FROM clause<br>A WHERE clause</pre><p>A subquery is usually added within the WHERE clause of another SQL SELECT statement.</p><p>You can use the comparison operators, such as &gt; , &lt; , or = . The comparison operator can also be a multiple-row operator, such as IN , ANY , or ALL .</p><p>A subquery is also called an inner query or inner select, while the statement containing a subquery is also called an outer query or outer select.</p><p>The inner query executes first before its parent query so that the results of an inner query can be passed to the outer query.</p><p><strong>56. Subqueries can be nested in…</strong></p><p>The subquery can be nested inside a SELECT , INSERT , UPDATE , or DELETE statement or inside another subquery.</p><p><strong>57. What row comparison operators can be used with a subquery?</strong></p><p>You can use the comparison operators, such as &gt; , &lt; , or = . The comparison operator can also be a multiple-row operator, such as IN , ANY , or ALL .</p><p><strong>58. A subquery that is used inside a subquery is called a</strong></p><p>Subquery within another subquery is called as <strong>Nested Subquery</strong>.</p><p><strong>59. A subquery that uses a correlation name from the outer query is called a</strong></p><p>If the output of a subquery is depending on column values of the parent query table then the query is called <strong>Correlated Subquery</strong>.</p><p><strong>60. What is Case Function?</strong></p><p>The CASE function lets you evaluate conditions and return a value when the first condition is met (like an IF-THEN-ELSE statement).</p><p><strong>CASE Syntax</strong></p><pre>CASE expression<br>WHEN condition1 THEN result1<br>WHEN condition2 THEN result2<br>...<br>WHEN conditionN THEN resultN<br>ELSE result<br>END</pre><p><strong>61. What are different types of statements supported by SQL?</strong></p><p><strong>DDL</strong> (Data Definition Language): It is used to define the database structure such as tables. It includes three statements such as Create, Alter, and Drop.</p><p><strong>DML</strong> (Data Manipulation Language): These statements are used to manipulate the data in records. Commonly used DML statements are Select, Insert, Update, and Delete.</p><p>Note: Some people prefer to assign the SELECT statement to a category of its own called: DQL. Data Query Language.</p><p><strong>DCL</strong> (Data Control Language): These statements are used to set privileges such as Grant and Revoke database access permission to the specific user.</p><p><strong>62. Which of the following SQL statements are DDL</strong></p><p><strong>DDL statements include:</strong></p><ul><li>ALTER Statements</li><li>CREATE Statements</li><li>DROP Statements</li><li>TRUNCATE TABLE</li></ul><p><strong>63. DML includes the following SQL statements</strong></p><p><strong>DML statements are:</strong></p><pre>SELECT<br>INSERT<br>UPDATE<br>DELETE</pre><p><strong>64. Grant and Revoke commands are under</strong></p><p><strong>DCL (Data Control Language)</strong></p><p>GRANT : Used to provide any user access privileges or other privileges for the database.</p><p>REVOKE : Used to take back permissions from any user.</p><p><strong>65. Which of the following is not a DML statement?</strong></p><p>Same answer as for the previous questions.</p><p>COMMIT is used to persist changes performed during a TRANSACTION.</p><p><strong>66. Which SQL statement is used to insert new data in a database?</strong></p><p>The INSERT INTO statement is used to insert new records in a table.</p><p><strong>67. When inserting data in a table do you have to specify the list of columns you are inserting values for?</strong></p><p><strong>INSERT INTO Syntax</strong></p><p>It is possible to write the INSERT INTO statement in two ways.</p><p>The first way specifies both the column names and the values to be inserted:</p><pre>INSERT INTO table_name (column1, column2, column3, ...)<br>VALUES (value1, value2, value3, ...);</pre><p>If you are adding values for all the columns of the table, you do not need to specify the column names in the SQL query. However, make sure the order of the values is in the same order as the columns in the table. The INSERT INTO syntax would be as follows:</p><pre>INSERT INTO table_name<br>VALUES (value1, value2, value3, ...);</pre><p><strong>68. With SQL, how can you insert a new record into the “Customers” table?</strong></p><p>Same answer as for the previous question.</p><p><strong>69. With SQL, how can you insert “Hawkins” as the “LastName” in the “Customers” table?</strong></p><p>Same answer as for the previous question.</p><p><strong>70. How do you create a temporary table in MySQL?</strong></p><p>To create a temporary table, you just need to add the TEMPORARY keyword to the CREATE TABLE statement.</p><p>Example:</p><pre>CREATE TEMPORARY TABLE top10customers<br>SELECT customer.fname, customer.lname<br>FROM customers</pre><ul><li>/* all the conditions to fecth the top 10 customers */</li></ul><p><strong>71. Which SQL statement is used to update data in a database?</strong></p><p>The UPDATE statement is used to modify the existing records in a table.</p><p><strong>UPDATE Syntax</strong></p><pre>-   UPDATE table_name<br>-   SET column1 = value1, column2 = value2, ...<br>-   WHERE condition;</pre><p><strong>72. What is the keyword is used in an UPDATE query to modify the existing value?</strong></p><p>The answer is SET .</p><p><strong>UPDATE Syntax</strong></p><pre>UPDATE table_name<br>SET column1 = value1, column2 = value2, ...<br>WHERE condition;</pre><p><strong>73. How can you change “Jackson” into “Hawkins” in the “LastName” column in the Customer table?</strong></p><pre>UPDATE Customers SET LastName=&#39;Hawkins&#39; WHERE LastName=&#39;Jackson&#39;</pre><p>Same explanation as for the previous question.</p><p><strong>74. Which SQL statement is used to delete data from a database?</strong></p><p>The DELETE statement is used to delete existing records in a table.</p><p><strong>DELETE Syntax</strong></p><pre>DELETE FROM table_name<br>WHERE condition;</pre><p><strong>75. With SQL, how can you delete the records where the “FirstName” is “John” in the Customers Table?</strong></p><p>DELETE FROM Customers WHERE FirstName = ‘John’</p><p><strong>76. The FROM SQL keyword is used to</strong></p><p>Specify the table we are are selecting or deleting from.</p><p><strong>DELETE Syntax</strong></p><pre>DELETE FROM table_name<br>WHERE condition;</pre><p><strong>UPDATE Syntax</strong></p><pre>UPDATE table_name<br>SET column1 = value1, column2 = value2, ...<br>WHERE condition;</pre><p><strong>INSERT Syntax</strong></p><pre>INSERT INTO table_name (column1, column2, column3, ...)<br>VALUES (value1, value2, value3, ...);</pre><p><strong>SELECT Syntax</strong></p><pre>SELECT column1, column2, ...<br>FROM table_name;</pre><p><strong>77. What is the difference between DELETE and TRUNCATE?</strong></p><p>The basic difference in both is DELETE is DML command and TRUNCATE is DDL.</p><p>DELETE is used to delete a specific row from the table whereas TRUNCATE is used to remove all rows from the table</p><p>We can use DELETE with WHERE clause but cannot use TRUNCATE with it.</p><p><strong>78. Which SQL statement is used to create a table in a database?</strong></p><p>The CREATE TABLE statement is used to create a new table in a database.</p><p><strong>Syntax</strong></p><pre>CREATE TABLE table_name (<br>column1 datatype,<br>column2 datatype,<br>column3 datatype,<br>....<br>);</pre><p><strong>79. What is Collation in SQL?</strong></p><p>A collation is a set of rules that defines how to compare and sort character strings.</p><p><strong>Detailed Explanation:</strong></p><p>A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set. Let’s make the distinction clear with an example of an imaginary character set.</p><p>Suppose that we have an alphabet with four letters: A, B, a, b. We give each letter a number: A = 0, B = 1, a = 2, b = 3. The letter A is a symbol, the number 0 is the encoding for A, and the combination of all four letters and their encodings is a character set.</p><p>Suppose that we want to compare two string values, A and B. The simplest way to do this is to look at the encodings: 0 for A and 1 for B. Because 0 is less than 1, we say A is less than B. What we’ve just done is apply a collation to our character set. The collation is a set of rules (only one rule in this case): “compare the encodings.” We call this simplest of all possible collations a binary collation.</p><p>But what if we want to say that the lowercase and uppercase letters are equivalent? Then we would have at least two rules: (1) treat the lowercase letters a and b as equivalent to A and B; (2) then compare the encodings. We call this a case-insensitive collation. It is a little more complex than a binary collation.</p><p>In real life, most character sets have many characters: not just A and B but whole alphabets, sometimes multiple alphabets or eastern writing systems with thousands of characters, along with many special symbols and punctuation marks. Also in real life, most collations have many rules, not just for whether to distinguish lettercase, but also for whether to distinguish accents (an “accent” is a mark attached to a character as in German Ö), and for multiple-character mappings (such as the rule that Ö = OE in one of the two German collations).</p><p><em>Source: </em><a href="http://dev.myslq.com/"><em>dev.myslq.com</em></a></p><p><strong>80. What is true about an AUTO_INCREMENT column in SQL?</strong></p><p>AUTO_INCREMENT allows a unique number to be generated automatically when a new record is inserted into a table. Often this is the primary key field that we would like to be created automatically every time a new record is inserted.</p><p><strong>Syntax for MySQL</strong></p><p>The following SQL statement defines the “ID” column to be an auto-increment primary key field in the “Persons” table:</p><pre>CREATE TABLE Persons (<br>ID int NOT NULL AUTO_INCREMENT,<br>LastName varchar(255) NOT NULL,<br>FirstName varchar(255),<br>Age int,<br>PRIMARY KEY (ID)<br>);</pre><p><strong>Syntax for SQL Server</strong></p><p>The following SQL statement defines the “ID” column to be an auto-increment primary key field in the “Persons” table:</p><pre>CREATE TABLE Persons (<br>ID int IDENTITY(1,1) PRIMARY KEY,<br>LastName varchar(255) NOT NULL,<br>FirstName varchar(255),<br>Age int<br>);</pre><p><strong>Syntax for Oracle</strong></p><p>In Oracle the code is a little bit more tricky.</p><p>You will have to create an auto-increment field with the sequence object (this object generates a number sequence).</p><p>Use the following <strong>CREATE SEQUENCE syntax:</strong></p><pre>CREATE SEQUENCE seq_person<br>MINVALUE 1<br>START WITH 1<br>INCREMENT BY 1<br>CACHE 10;</pre><p>The code above creates a sequence object called seq_person, that starts with 1 and will increment by 1. It will also cache up to 10 values for performance. The cache option specifies how many sequence values will be stored in memory for faster access.</p><p>To insert a new record into the “Persons” table, we will have to use the nextval function (this function retrieves the next value from seq_person sequence):</p><pre>INSERT INTO Persons (ID,FirstName,LastName)<br>VALUES (seq_person.nextval,&#39;Lars&#39;,&#39;Monsen&#39;);</pre><p>The SQL statement above would insert a new record into the “Persons” table. The “ID” column would be assigned the next number from the seq_person sequence. The “FirstName” column would be set to “Lars” and the “LastName” column would be set to “Monsen”.</p><p><strong>81. What are valid constraints in MySQL?</strong></p><p>SQL constraints are used to specify rules for the data in a table.</p><p>Constraints are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the table. If there is any violation between the constraint and the data action, the action is aborted.</p><p>Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table.</p><p>The following constraints are commonly used in SQL:</p><ul><li>NOT NULL — Ensures that a column cannot have a NULL value</li><li>UNIQUE — Ensures that all values in a column are different</li><li>PRIMARY KEY — A combination of a NOT NULL and UNIQUE . Uniquely identifies each row in a table</li><li>FOREIGN KEY — Uniquely identifies a row/record in another table</li><li>CHECK — Ensures that all values in a column satisfies a specific condition</li><li>DEFAULT — Sets a default value for a column when no value is specified</li><li>INDEX — Used to create and retrieve data from the database very quickly</li></ul><p><strong>82. Which of the following is NOT TRUE about constraints?</strong></p><p>NOT NULL — Ensures that a column cannot have a NULL value</p><p>UNIQUE — Ensures that all values in a column are different</p><p>PRIMARY KEY — A combination of a NOT NULL and UNIQUE . Uniquely identifies each row in a table</p><p>FOREIGN KEY — Uniquely identifies a row/record in another table</p><p><strong>83. The NOT NULL constraint enforces a column to not accept null values.</strong></p><p>NOT NULL — Ensures that a column cannot have a NULL value.</p><p><strong>84. An unique (non-key) field</strong></p><p>The UNIQUE constraint ensures that all values in a column are different.</p><p><strong>85. What is CHECK Constraint?</strong></p><p>The CHECK constraint is used to limit the value range that can be placed in a column.</p><p>If you define a CHECK constraint on a single column it allows only certain values for this column.</p><p>If you define a CHECK constraint on a table it can limit the values in certain columns based on values in other columns in the row.</p><p><strong>SQL CHECK on CREATE TABLE</strong></p><p>The following SQL creates a CHECK constraint on the “Age” column when the “Persons” table is created. The CHECK constraint ensures that you can not have any person below 18 years:</p><p><strong>MySQL:</strong></p><pre>CREATE TABLE Persons (<br>ID int NOT NULL,<br>LastName varchar(255) NOT NULL,<br>FirstName varchar(255),<br>Age int,<br>CHECK (Age&gt;=18)<br>);</pre><p><strong>SQL Server / Oracle / MS Access:</strong></p><ul><li>CREATE TABLE Persons (</li><li>ID int NOT NULL,</li><li>LastName varchar(255) NOT NULL,</li><li>FirstName varchar(255),</li><li>Age int CHECK (Age&gt;=18)</li><li>);</li></ul><p><strong>86. What is the difference between UNIQUE and PRIMARY KEY constraints?</strong></p><p>UNIQUE vs PRIMARY KEY</p><p>Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns.</p><p>A PRIMARY KEY constraint automatically has a UNIQUE constraint.</p><p>However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.</p><p><strong>87. What does SQL DROP TABLE clause do?</strong></p><p>The DROP TABLE statement is used to drop an existing table in a database.</p><p><strong>Syntax</strong></p><pre>DROP TABLE table_name;</pre><p><strong>88. What is the difference between DROP and TRUNCATE?</strong></p><p>TRUNCATE removes all rows from the table which cannot be retrieved back, DROP removes the entire table from the database and it cannot be retrieved back.</p><p><strong>89. How do you add a ‘order_date’ column to a table called ‘order’?</strong></p><p>ALTER TABLE order ADD order_date DATE</p><p>The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.</p><p>The ALTER TABLE statement is also used to add and drop various constraints on an existing table.</p><p><strong>ALTER TABLE — ADD Column</strong></p><p>To add a column in a table, use the following syntax:</p><pre>ALTER TABLE table_name<br>ADD column_name datatype;</pre><p><strong>90. What the correct syntax to rename column ‘Address’ to ‘Addr’ in ‘Customer’ table?</strong></p><p>ALTER TABLE Customer CHANGE Address Addr varchar(50);</p><p>ALTER TABLE — CHANGE</p><p>You rename a column using the ALTER TABLE and CHANGE commands together to change an existing column.</p><p><strong>Syntax</strong></p><pre>ALTER TABLE table_name<br>CHANGE oldname newname datatype</pre><p><strong>91. Consider the following schema ADDRESSES (id, street_name, number, city, state) Which code snippet will alter the table ADDRESSES and delete the column named CITY?</strong></p><p>ALTER TABLE addresses DROP COLUMN city;</p><p>ALTER TABLE — DROP COLUMN</p><p>To delete a column in a table, use the following syntax (notice that some database systems don’t allow deleting a column):</p><pre>ALTER TABLE table_name<br>DROP COLUMN column_name;</pre><p><strong>92. What are Indexes in SQL?</strong></p><p>Indexes are used to retrieve data from the database very fast. The users cannot see the indexes, they are just used to speed up searches/queries.</p><p>Note: Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So, only create indexes on columns that will be frequently searched against.</p><p><strong>CREATE INDEX Syntax</strong></p><p>Creates an index on a table. Duplicate values are allowed:</p><pre>CREATE INDEX index_name<br>ON table_name (column1, column2, ...)</pre><p><strong>93. What is the difference between clustered and non-clustered indexes? Which of the following statements are true?</strong></p><p>One table can have only one clustered index but multiple nonclustered indexes.</p><p>Clustered indexes can be read rapidly rather than non-clustered indexes.</p><p>Clustered indexes store data physically in the table or view and non-clustered indexes do not store data in table as it has separate structure from data row.</p><p><strong>94. The statement for assigning access privileges is</strong></p><p>SQL GRANT and REVOKE commands are used to implement privileges in SQL multiple user environments. The administrator of the database can grant or revoke privileges to or from users of database object like SELECT , INSERT , UPDATE , DELETE , ALL etc.</p><p>GRANT Command: This command is used provide database access to user apart from an administrator.</p><p><strong>Syntax</strong></p><pre>GRANT privilege_name<br>ON object_name<br>TO {user_name|PUBLIC|role_name}<br>[WITH GRANT OPTION];</pre><p>In above syntax WITH GRANT OPTIONS indicates that the user can grant the access to another user too.</p><p>REVOKE Command: This command is used provide database deny or remove access to database objects.</p><p><strong>Syntax</strong></p><pre>REVOKE privilege_name<br>ON object_name<br>FROM {user_name|PUBLIC|role_name}</pre><p><strong>95. How many types of Privileges are available in SQL?</strong></p><p>There are two types of privileges used in SQL, such as</p><p><strong>System Privilege</strong>: System privileges deal with an object of a particular type and specifies the right to perform one or more actions on it which include Admin allows a user to perform administrative tasks, ALTER ANY INDEX, ALTER ANY CACHE GROUP CREATE/ALTER/DELETE TABLE, CREATE/ALTER/DELETE VIEW etc.</p><p><strong>Object Privilege</strong>: This allows to perform actions on an object or object of another user(s) viz. table, view, indexes etc. Some of the object privileges are EXECUTE, INSERT, UPDATE, DELETE, SELECT, FLUSH, LOAD, INDEX, REFERENCES etc.</p><p><strong>96. List the various privileges that a user can grant to another user?</strong></p><p>Same answers as for the previous question</p><p><strong>97. What does the term ‘locking’ refer to?</strong></p><p>Locking is a process preventing users from reading data being changed by other users, and prevents concurrent users from changing the same data at the same time.</p><p><strong>98. What are a transaction’s main controls?</strong></p><p>COMMIT command is used to permanently save any transaction into the database.</p><p>When we use any DML command like INSERT , UPDATE or DELETE , the changes made by these commands are not permanent, until the current session is closed, the changes made by these commands can be rolled back.</p><p>To avoid that, we use the COMMIT command to mark the changes as permanent.</p><p>Following is commit command syntax:</p><pre>COMMIT;</pre><p>ROLLBACK command</p><p>This command restores the database to last committed state. It is also used with SAVEPOINT command to jump to a savepoint in an ongoing transaction.</p><p>If we have used the UPDATE command to make some changes into the database, and realise that those changes were not required, then we can use the ROLLBACK command to rollback those changes, if they were not committed using the COMMIT command.</p><p>Following is rollback command syntax:</p><ul><li><em>ROLLBACK TO savepoint_name;</em></li><li>SAVEPOINT command</li><li>SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that point whenever required.</li></ul><p>Following is savepoint command syntax:</p><p><em>SAVEPOINT savepoint_name;</em></p><p>In short, using this command we can name the different states of our data in any table and then rollback to that state using the ROLLBACK command whenever required.</p><p><strong>99. A transaction completes its execution is said to be</strong></p><p>Committed**.**</p><p><strong>100. Consider the following code: START TRANSACTION /<em>transaction body</em>/ COMMIT; ROLLBACK; What does Rollback do?</strong></p><p>It does nothing. Once a transaction has executed commit, its effects can no longer be undone by rollback.</p><p><strong>101. What are valid properties of the transaction?</strong></p><p>The characteristics of these four properties as defined by Reuter and Härder are as follows:</p><p><strong>Atomicity</strong></p><p>​ Atomicity requires that each transaction be “all or nothing”: if one part of the transaction fails, then the entire transaction fails, and the database state is left unchanged. An atomic system must guarantee atomicity in each and every situation, including power failures, errors and crashes. To the outside world, a committed transaction appears (by its effects on the database) to be indivisible (“atomic”), and an aborted transaction does not happen.</p><p><strong>Consistency</strong></p><p>​ The consistency property ensures that any transaction will bring the database from one valid state to another. Any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers, and any combination thereof. This does not guarantee correctness of the transaction in all ways the application programmer might have wanted (that is the responsibility of application-level code), but merely that any programming errors cannot result in the violation of any defined rules.</p><p><strong>Isolation</strong></p><p>​ The isolation property ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed sequentially, i.e., one after the other. Providing isolation is the main goal of concurrency control. Depending on the concurrency control method (i.e., if it uses strict — as opposed to relaxed — serializability), the effects of an incomplete transaction might not even be visible to another transaction.</p><p><strong>Durability</strong></p><p>​ The durability property ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors. In a relational database, for instance, once a group of SQL statements execute, the results need to be stored permanently (even if the database crashes immediately thereafter). To defend against power loss, transactions (or their effects) must be recorded in a non-volatile memory.</p><p><strong>102. What happens if autocommit is enabled?</strong></p><p>If autocommit mode is enabled, each SQL statement forms a single transaction on its own. By default, most of DBMS start the session for each new connection with autocommit enabled, so they do a commit after each SQL statement if that statement did not return an error. If a statement returns an error, the commit or rollback behavior depends on the error.</p><p><strong>103. What is the default isolation level used in MySQL?</strong></p><p><strong>REPEATABLE READ</strong></p><p><strong>104. In MySQL autocommit is enabled by default for each session.</strong></p><p><strong>TRUE</strong></p><p><strong>105. Which of these is also known as a virtual table in MySQL?</strong></p><p><strong>A view.</strong></p><p>In SQL, a view is a virtual table based on the result-set of an SQL statement.</p><p>A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database.</p><p>You can add SQL functions, WHERE , and JOIN statements to a view and present the data as if the data were coming from one single table.</p><p><strong>CREATE VIEW Syntax</strong></p><pre>CREATE VIEW view_name AS<br>SELECT column1, column2, ...<br>FROM table_name<br>WHERE condition;</pre><p><strong>106. Are views updatable using INSERT, DELETE or UPDATE?</strong></p><p>The SQL UPDATE VIEW command can be used to modify the data of a view.</p><p>All views are not updatable. So, UPDATE command is not applicable to all views. An updatable view is one which allows performing a UPDATE command on itself without affecting any other table.</p><p>When can a view be updated?</p><ol><li>The view is defined based on one and only one table.</li><li>The view must include the PRIMARY KEY of the table based upon which the view has been created.</li><li>The view should not have any field made out of aggregate functions.</li><li>The view must not have any DISTINCT clause in its definition.</li><li>The view must not have any GROUP BY or HAVING clause in its definition.</li><li>The view must not have any SUBQUERIES in its definitions.</li><li>If the view you want to update is based upon another view, the later should be updatable.</li><li>Any of the selected output fields (of the view) must not use constants, strings or value expressions.</li></ol><p><strong>107. What are the advantages of Views?</strong></p><p>Simplify queries: You can use database view to hide the complexity of underlying tables to the end-users and external applications</p><p>All changes performed by SQL statements are executed only after a COMMIT command.</p><p>A database view helps limit data access to specific users. You may not want a subset of sensitive data can be queryable by all users</p><p><strong>108. Does a View contain data?</strong></p><p>A view does not contain any data of its own, but is like a window through which data from other tables can be viewed and changed.</p><p>The answer depends on the type of view. In case of normal view, the answer is NO it only contains query based on a base table but in case of materialized view, YES it does contain data and for the updated data in the base table, it needs to be refreshed.</p><p><strong>109. What SQL statement do you have to use to remove a view?</strong></p><p>You can delete a view with the DROP VIEW command.</p><p><strong>SQL DROP VIEW Syntax</strong></p><p><em>DROP VIEW view_name;</em></p><p><strong>110. Can a View based on another View?</strong></p><p>Yes, A View is based on another View.</p><p><strong>111. Inside a stored procedure you to iterate over a set of rows returned by a query using a</strong></p><p>A CURSOR is a database object which is used to manipulate data in a row-to-row manner.</p><p>Cursor follows steps as given below:</p><ul><li>Declare Cursor</li><li>Open Cursor</li><li>Retrieve row from the Cursor</li><li>Process the row</li><li>Close Cursor</li><li>Deallocate Cursor</li></ul><p><strong>112. How do you call the process of finding a good strategy for processing a query?</strong></p><p>Query optimization is a function of many relational database management systems. The query optimizer attempts to determine the most efficient way to execute a given query by considering the possible query plans.</p><p><em>113. What is a trigger? or There are triggers for… or A trigger is applied to</em>*</p><p>Triggers in SQL is kind of stored procedures used to create a response to a specific action performed on the table. You can invoke triggers explicitly on the table in the database.</p><p>Triggers are, in fact, written to be executed in response to any of the following events:</p><ul><li>A database manipulation (DML) statement (DELETE , INSERT , or UPDATE )</li><li>A database definition (DDL) statement (CREATE , ALTER , or DROP ).</li><li>A database operation (SERVERERROR , LOGON , LOGOFF , STARTUP , or SHUTDOWN ).</li></ul><p>Action and Event are two main components of SQL triggers when certain actions are performed the event occurs in response to that action.</p><p><strong>Syntax</strong></p><pre>CREATE TRIGGER name {BEFORE|AFTER} (event [OR..]}<br>ON table_name [FOR [EACH] {ROW|STATEMENT}]<br>EXECUTE PROCEDURE functionname {arguments}</pre><p><strong>114. A special kind of a stored procedure that executes in response to certain action on the table like insertion, deletion or updation of data is called</strong></p><p><strong>Trigger.</strong></p><p><strong>115. What is SQL Injection?</strong></p><ul><li>SQL injection is a code injection technique that might destroy your database.</li><li>SQL injection is one of the most common web hacking techniques.</li><li>SQL injection is the placement of malicious code in SQL statements, via web page input.</li></ul><blockquote>🚀 If you found this useful consider leaving a star here :) 🚀</blockquote><p><a href="https://github.com/xoraus/CrackingTheSQLInterview">https://github.com/xoraus/CrackingTheSQLInterview</a></p><p><a href="https://github.com/xoraus/CrackingTheSQLInterview">GitHub - xoraus/CrackingTheSQLInterview: &quot;Cracking the SQL Interview&quot; is a comprehensive guide for individuals who are preparing for a job interview related to SQL.</a></p><p><strong>Let’s connect on Github &amp; LinkedIn. :)</strong></p><p><a href="https://github.com/xoraus">xoraus - Overview</a></p><p><a href="https://www.linkedin.com/in/sajjadsalaria/">https://www.linkedin.com/in/sajjadsalaria/</a></p><p><strong><em>Resources</em></strong></p><p><a href="http://www.wikipedia.org/">www.wikipedia.org</a></p><p><a href="http://www.w3schools.com/">www.w3schools.com</a></p><p><a href="http://www.freefeast.info/">www.freefeast.info</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa0dd82ad3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/cracking-the-sql-interview-eaa0dd82ad3e">Cracking the SQL Interview</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K Means Clustering for Imagery Analysis]]></title>
            <link>https://medium.datadriveninvestor.com/k-means-clustering-for-imagery-analysis-56c9976f16b6?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/56c9976f16b6</guid>
            <category><![CDATA[deeplearing]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[digits-recognition]]></category>
            <category><![CDATA[k-means-clustering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Thu, 22 Aug 2019 13:08:08 GMT</pubDate>
            <atom:updated>2022-08-25T17:13:48.444Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s learn about K-Means by doing a mini-project.</p><p>In this project, we will use a K-means algorithm to perform image classification. Clustering isn’t limited to the consumer information and population sciences, it can be used for imagery analysis as well. Leveraging Scikit-learn and the MNIST dataset, we will investigate the use of K-means clustering for computer vision.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fl0HlNBe9Z3Xz9x1Yc%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fanimation-countdown-launch-l0HlNBe9Z3Xz9x1Yc&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fl0HlNBe9Z3Xz9x1Yc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="540" frameborder="0" scrolling="no"><a href="https://medium.com/media/899f027b2a7a65ff7cd50cd2d7346a91/href">https://medium.com/media/899f027b2a7a65ff7cd50cd2d7346a91/href</a></iframe><p>In this project, we will learn how to:</p><p><a href="https://www.datadriveninvestor.com/2019/03/03/editors-pick-5-machine-learning-books/">DDI Editor&#39;s Pick: 5 Machine Learning Books That Turn You from Novice to Expert | Data Driven Investor</a></p><ul><li>Preprocess images for clustering</li><li>Deploy K-means clustering algorithms</li><li>Use common metrics to evaluate cluster performance</li><li>Visualize high-dimensional cluster centroids</li></ul><p>Let’s get started by importing a few of the libraries we will use in this project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/204bd1ba285b794546b2f555b74d54ce/href">https://medium.com/media/204bd1ba285b794546b2f555b74d54ce/href</a></iframe><h3>1. Import the MNIST dataset</h3><p>For this project, we will be using the MNIST dataset. It is available through keras, a deep learning library we have used in previous tutorials. Although we won’t be using other features of keras today, it will save us time to import mnist from this library. It is also available through the tensorflow library or for download at <a href="http://yann.lecun.com/exdb/mnist/">http://yann.lecun.com/exdb/mnist/</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6763eed1cb103eac5546f9006b32f383/href">https://medium.com/media/6763eed1cb103eac5546f9006b32f383/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/1*Bs0QHcHrM3FXzy6i_v220g.png" /></figure><h3>2. Preprocessing the MNIST images</h3><p>Images stored as NumPy arrays are 2-dimensional arrays. However, the K-means clustering algorithm provided by scikit-learn ingests 1-dimensional arrays; as a result, we will need to reshape each image.</p><p>Clustering algorithms almost always use 1-dimensional data. For example, if you were clustering a set of X, Y coordinates, each point would be passed to the clustering algorithm as a 1-dimensional array with a length of two (example: [2,4] or [-1, 4]). If you were using 3-dimensional data, the array would have a length of 3 (example: [2, 4, 1] or [-1, 4, 5]).</p><p>MNIST contains images that are 28 by 28 pixels; as a result, they will have a length of 784 once we reshape them into a 1-dimensional array.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3db0e8066cb128415df6c9e617503a64/href">https://medium.com/media/3db0e8066cb128415df6c9e617503a64/href</a></iframe><h3>3. K-Means Clustering</h3><p>Time to start clustering! Due to the size of the MNIST dataset, we will use the mini-batch implementation of k-means clustering provided by scikit-learn. This will dramatically reduce the amount of time it takes to fit the algorithm to the data.</p><p>The MNIST dataset contains images of the integers 0 to 9. Because of this, let’s start by setting the number of clusters to 10, one for each digit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/377d022c81a26a22c3e940378aab2fb7/href">https://medium.com/media/377d022c81a26a22c3e940378aab2fb7/href</a></iframe><h3>4. Assigning Cluster Labels</h3><p>K-means clustering is an unsupervised machine learning method; consequently, the labels assigned by our KMeans algorithm refer to the cluster each array was assigned to, not the actual target integer. To fix this, let’s define a few functions that will predict which integer corresponds to each cluster.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a19925fd208cbd10788867c19bfa5102/href">https://medium.com/media/a19925fd208cbd10788867c19bfa5102/href</a></iframe><h3>5. Optimizing and Evaluating the Clustering Algorithm</h3><p>With the functions defined above, we can now determine the accuracy of our algorithms. Since we are using this clustering algorithm for classification, accuracy is ultimately the most important metric; however, there are other metrics out there that can be applied directly to the clusters themselves, regardless of the associated labels. Two of these metrics that we will use are inertia and homogeneity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/270f9455e55b5d3a6cfab71d26c53e47/href">https://medium.com/media/270f9455e55b5d3a6cfab71d26c53e47/href</a></iframe><p>Furthermore, earlier we made the assumption that K = 10 was the appropriate number of clusters; however, this might not be the case. Let’s fit the K-means clustering algorithm with several different values of K, than evaluate the performance using our metrics.</p><h3>6. Visualizing Cluster Centroids</h3><p>The most representative point within each cluster is called the centroid. If we were dealing with X,Y points, the centroid would simply be a point on the graph. However, since we are using arrays of length 784, our centroid is also going to be an array of length 784. We can reshape this array back into a 28 by 28-pixel image and plot it.</p><p>These graphs will display the most representative image for each cluster.</p><blockquote>print(‘Accuracy: {}\n’.format(metrics.accuracy_score(y_test, predicted_labels)))</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MtdXc4_6e_Oy6NuO4AfaXw.png" /></figure><h3>Predictions — Accuracy: 0.9023</h3><p>For Code: refer -&gt; <a href="https://github.com/xoraus/K-Means-Clustering-for-Imagery-Analysis">https://github.com/xoraus/K-Means-Clustering-for-Imagery-Analysis</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FncK1aJlwmpHNu%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fpost-circlejerk-rhighqualitygifs-ncK1aJlwmpHNu&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FncK1aJlwmpHNu%2Fgiphy-downsized-large.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="257" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc639d8fe3b3cb8c45a6fd59e92aa5f1/href">https://medium.com/media/dc639d8fe3b3cb8c45a6fd59e92aa5f1/href</a></iframe><p><strong><em>For more programming related stuff, follow me on </em></strong><a href="https://twitter.com/xoraus"><strong><em>Twitter</em></strong></a><strong><em> &amp; </em></strong><a href="https://github.com/xoraus"><strong><em>Github</em></strong></a><strong><em>.</em></strong></p><p>References:</p><p>[1]: <a href="https://en.wikipedia.org/wiki/K-means_clustering">https://en.wikipedia.org/wiki/K-means_clustering</a></p><p>[2]: <a href="http://yann.lecun.com/exdb/mnist/">http://yann.lecun.com/exdb/mnist/</a></p><p>[3]: <a href="https://en.wikipedia.org/wiki/MNIST_database">https://en.wikipedia.org/wiki/MNIST_database</a></p><p>[4]: <a href="https://www.kaggle.com/ngbolin/mnist-dataset-digit-recognizer">https://www.kaggle.com/ngbolin/mnist-dataset-digit-recognizer</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56c9976f16b6" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/k-means-clustering-for-imagery-analysis-56c9976f16b6">K Means Clustering for Imagery Analysis</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using The Super Resolution Convolutional Neural Network for Image Restoration]]></title>
            <link>https://medium.datadriveninvestor.com/using-the-super-resolution-convolutional-neural-network-for-image-restoration-ff1e8420d846?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff1e8420d846</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[convolution-neural-net]]></category>
            <category><![CDATA[image-processing]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 20:48:39 GMT</pubDate>
            <atom:updated>2023-03-15T15:40:21.350Z</atom:updated>
            <content:encoded><![CDATA[<h3>Super-Resolution Convolutional Neural Network for Image Restoration</h3><p>Welcome to this tutorial on single-image super-resolution. The goal of super-resolution (SR) is to recover a high-resolution image from a low-resolution input, or as they might say on any modern crime show, <strong>enhance!</strong></p><p>The authors of the SRCNN describe their network, pointing out the equivalence of their method to the sparse-coding method4, which is a widely used learning method for image SR. This is an important and educational aspect of their work, because it shows how example-based learning methods can be adapted and generalized to CNN models.</p><p>The SRCNN consists of the following operations1:</p><ol><li><strong>Preprocessing</strong>: Up-scales LR image to desired HR size.</li><li><strong>Feature extraction</strong>: Extracts a set of feature maps from the up-scaled LR image.</li><li><strong>Non-linear mapping</strong>: Maps the feature maps representing LR to HR patches.</li><li><strong>Reconstruction</strong>: Produces the HR image from HR patches.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*slDQDolF8CGteF4R.png" /></figure><p>To accomplish this goal, we will be deploying the super-resolution convolution neural network (SRCNN) using Keras. This network was published in the paper, “Image Super-Resolution Using Deep Convolutional Networks” by Chao Dong, et al. in 2014. You can read the full paper at <a href="https://arxiv.org/abs/1501.00092">https://arxiv.org/abs/1501.00092</a>.</p><p><a href="https://www.datadriveninvestor.com/2019/03/03/editors-pick-5-machine-learning-books/">DDI Editor&#39;s Pick: 5 Machine Learning Books That Turn You from Novice to Expert | Data Driven Investor</a></p><p>As the title suggests, the SRCNN is a deep convolutional neural network that learns the end-to-end mapping of low-resolution to high-resolution images. As a result, we can use it to improve the image quality of low-resolution images. To evaluate the performance of this network, we will be using three image quality metrics: peak signal to noise ratio (PSNR), mean squared error (MSE), and the structural similarity (SSIM) index.</p><p>In brief, with better SR approach, we can get a better quality of a larger image even we only get a small image originally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*FzN1KFBv_q0IramC4nxHRw.png" /></figure><p>Furthermore, we will be using OpenCV, the Open Source Computer Vision Library. OpenCV was originally developed by Intel and is used for many real-time computer vision applications. In this particular project, we will be using it to pre and post process our images. As you will see later, we will frequently be converting our images back and forth between the RGB, BGR, and YCrCb color spaces. This is necessary because the SRCNN network was trained on the luminance (Y) channel in the YCrCb color space.</p><p>During this project, you will learn how to:</p><ul><li>use the PSNR, MSE, and SSIM image quality metrics,</li><li>process images using OpenCV,</li><li>convert between the RGB, BGR, and YCrCb color spaces,</li><li>build deep neural networks in Keras,</li><li>deploy and evaluate the SRCNN network</li></ul><h3>The SRCNN Network</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*mZJO-i6ImYyXHorv4H1q_Q.png" /></figure><h3>1. Importing Packages</h3><p>Let’s dive right in! In this first cell, we will import the libraries and packages we will be using in this project and print their version numbers. This is an important step to make sure we are all on the same page; furthermore, it will help others reproduce the results we obtain.</p><pre><em># check package versions</em><br><strong>import</strong> <strong>sys</strong><br><strong>import</strong> <strong>keras</strong><br><strong>import</strong> <strong>cv2</strong><br><strong>import</strong> <strong>numpy</strong><br><strong>import</strong> <strong>matplotlib</strong><br><strong>import</strong> <strong>skimage</strong><br><br>print(&#39;Python: <strong>{}</strong>&#39;.format(sys.version))<br>print(&#39;Keras: <strong>{}</strong>&#39;.format(keras.__version__))<br>print(&#39;OpenCV: <strong>{}</strong>&#39;.format(cv2.__version__))<br>print(&#39;NumPy: <strong>{}</strong>&#39;.format(numpy.__version__))<br>print(&#39;Matplotlib: <strong>{}</strong>&#39;.format(matplotlib.__version__))<br>print(&#39;Scikit-Image: <strong>{}</strong>&#39;.format(skimage.__version__))</pre><h4><em>Import the necessary packages</em></h4><pre><strong>from</strong> <strong>keras.models</strong> <strong>import</strong> Sequential<br><strong>from</strong> <strong>keras.layers</strong> <strong>import</strong> Conv2D<br><strong>from</strong> <strong>keras.optimizers</strong> <strong>import</strong> Adam<br><strong>from</strong> <strong>skimage.measure</strong> <strong>import</strong> compare_ssim <strong>as</strong> ssim<br><strong>from</strong> <strong>matplotlib</strong> <strong>import</strong> pyplot <strong>as</strong> plt<br><strong>import</strong> <strong>cv2</strong><br><strong>import</strong> <strong>numpy</strong> <strong>as</strong> <strong>np</strong><br><strong>import</strong> <strong>math</strong><br><strong>import</strong> <strong>os</strong><br><br><em># python magic function, displays pyplot figures in the notebook</em><br>%matplotlib inline</pre><h3>2. Image Quality Metrics</h3><p>To start, let&#39;s define a couple of functions that we can use to calculate the PSNR, MSE, and SSIM. The structural similarity (SSIM) index was imported directly from the scikit-image library; however, we will have to define our own functions for the PSNR and MSE. Furthermore, we will wrap all three of these metrics into a single function that we can call later.</p><pre><em># define a function for peak signal-to-noise ratio (PSNR)</em><br><strong>def</strong> psnr(target, ref):<br>         <br>    <em># assume RGB image</em><br>    target_data = target.astype(float)<br>    ref_data = ref.astype(float)<br><br>    diff = ref_data - target_data<br>    diff = diff.flatten(&#39;C&#39;)<br><br>    rmse = math.sqrt(np.mean(diff ** 2.))<br><br>    <strong>return</strong> 20 * math.log10(255. / rmse)<br><br><em># define function for mean squared error (MSE)</em><br><strong>def</strong> mse(target, ref):<br>    <em># the MSE between the two images is the sum of the squared difference between the two images</em><br>    err = np.sum((target.astype(&#39;float&#39;) - ref.astype(&#39;float&#39;)) ** 2)<br>    err /= float(target.shape[0] * target.shape[1])<br>    <br>    <strong>return</strong> err<br><br><em># define function that combines all three image quality metrics</em><br><strong>def</strong> compare_images(target, ref):<br>    scores = []<br>    scores.append(psnr(target, ref))<br>    scores.append(mse(target, ref))<br>    scores.append(ssim(target, ref, multichannel =<strong>True</strong>))<br>    <br>    <strong>return</strong> scores</pre><h3>3. Preparing Images</h3><p>For this project, we will be using the same images that were used in the original SRCNN paper. We can download these images from <a href="http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html">http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html</a>. The .zip file identified as the MATLAB code contains the images we want. Copy both the Set5 and Set14 datasets into a new folder called ‘source’.</p><p>Now that we have some images, we want to produce low-resolution versions of these same images. We can accomplish this by resizing the images, both downwards and upwards, using OpeCV. There are several interpolation methods that can be used to resize images; however, we will be using bilinear interpolation.</p><p>Once we produce these low-resolution images, we can save them in a new folder.</p><pre><em># prepare degraded images by introducing quality distortions via resizing</em><br><br><strong>def</strong> prepare_images(path, factor):<br>    <br>    <em># loop through the files in the directory</em><br>    <strong>for</strong> file <strong>in</strong> os.listdir(path):<br>        <br>        <em># open the file</em><br>        img = cv2.imread(path + &#39;/&#39; + file)<br>        <br>        <em># find old and new image dimensions</em><br>        h, w, _ = img.shape<br>        new_height = h / factor<br>        new_width = w / factor<br>        <br>        <em># resize the image - down</em><br>        img = cv2.resize(img, (new_width, new_height), interpolation = cv2.INTER_LINEAR)<br>        <br>        <em># resize the image - up</em><br>        img = cv2.resize(img, (w, h), interpolation = cv2.INTER_LINEAR)<br>        <br>        <em># save the image</em><br>        print(&#39;Saving <strong>{}</strong>&#39;.format(file))<br>        cv2.imwrite(&#39;images/<strong>{}</strong>&#39;.format(file), img)</pre><pre>prepare_images(&#39;source/&#39;, 2)</pre><h3>3. Testing Low-Resolution Images</h3><p>To ensure that our image quality metrics are being calculated correctly and that the images were effectively degraded, let&#39;s calculate the PSNR, MSE, and SSIM between our reference images and the degraded images that we just prepared.</p><pre><em># test the generated images using the image quality metrics</em><br><br><strong>for</strong> file <strong>in</strong> os.listdir(&#39;images/&#39;):<br>    <br>    <em># open target and reference images</em><br>    target = cv2.imread(&#39;images/<strong>{}</strong>&#39;.format(file))<br>    ref = cv2.imread(&#39;source/<strong>{}</strong>&#39;.format(file))<br>    <br>    <em># calculate score</em><br>    scores = compare_images(target, ref)<br><br>    <em># print all three scores with new line characters (\n) </em><br>    print(&#39;<strong>{}\n</strong>PSNR: <strong>{}\n</strong>MSE: <strong>{}\n</strong>SSIM: <strong>{}\n</strong>&#39;.format(file, scores[0], scores[1], scores[2]))</pre><h3>4. Building the SRCNN Model</h3><p>Now that we have our low-resolution images and all three image quality metrics functioning properly, we can start building the SRCNN. In Keras, it’s as simple as adding layers one after the other. The architecture and hyperparameters of the SRCNN network can be obtained from the publication referenced above.</p><pre><em># define the SRCNN model</em><br><strong>def</strong> model():<br>    <br>    <em># define model type</em><br>    SRCNN = Sequential()<br>    <br>    <em># add model layers</em><br>    SRCNN.add(Conv2D(filters=128, kernel_size = (9, 9), kernel_initializer=&#39;glorot_uniform&#39;,<br>                     activation=&#39;relu&#39;, padding=&#39;valid&#39;, use_bias=<strong>True</strong>, input_shape=(<strong>None</strong>, <strong>None</strong>, 1)))<br>    SRCNN.add(Conv2D(filters=64, kernel_size = (3, 3), kernel_initializer=&#39;glorot_uniform&#39;,<br>                     activation=&#39;relu&#39;, padding=&#39;same&#39;, use_bias=<strong>True</strong>))<br>    SRCNN.add(Conv2D(filters=1, kernel_size = (5, 5), kernel_initializer=&#39;glorot_uniform&#39;,<br>                     activation=&#39;linear&#39;, padding=&#39;valid&#39;, use_bias=<strong>True</strong>))<br>    <br>    <em># define optimizer</em><br>    adam = Adam(lr=0.0003)<br>    <br>    <em># compile model</em><br>    SRCNN.compile(optimizer=adam, loss=&#39;mean_squared_error&#39;, metrics=[&#39;mean_squared_error&#39;])<br>    <br>    <strong>return</strong> SRCNN</pre><h3>5. Deploying the SRCNN</h3><p>Now that we have defined our model, we can use it for single-image super-resolution. However, before we do this, we will need to define a couple of image processing functions. Furthermore, it will be necessary to preprocess the images extensively before using them as inputs to the network. This processing will include cropping and color space conversions.</p><p>Additionally, to save us the time it takes to train a deep neural network, we will be loading pre-trained weights for the SRCNN. These weights can be found at the following GitHub page: <a href="https://github.com/MarkPrecursor/SRCNN-keras">https://github.com/MarkPrecursor/SRCNN-keras</a></p><p>Once we have tested our network, we can perform single-image super-resolution on all of our input images. Furthermore, after processing, we can calculate the PSNR, MSE, and SSIM on the images that we produce. We can save these images directly or create subplots to conveniently display the original, low-resolution, and high-resolution images side by side.</p><pre><em># define necessary image processing functions</em><br><br><strong>def</strong> modcrop(img, scale):<br>    tmpsz = img.shape<br>    sz = tmpsz[0:2]<br>    sz = sz - np.mod(sz, scale)<br>    img = img[0:sz[0], 1:sz[1]]<br>    <strong>return</strong> img<br><br><br><strong>def</strong> shave(image, border):<br>    img = image[border: -border, border: -border]<br>    <strong>return</strong> img</pre><pre><em># define main prediction function</em><br><br><strong>def</strong> predict(image_path):<br>    <br>    <em># load the srcnn model with weights</em><br>    srcnn = model()<br>    srcnn.load_weights(&#39;3051crop_weight_200.h5&#39;)<br>    <br>    <em># load the degraded and reference images</em><br>    path, file = os.path.split(image_path)<br>    degraded = cv2.imread(image_path)<br>    ref = cv2.imread(&#39;source/<strong>{}</strong>&#39;.format(file))<br>    <br>    <em># preprocess the image with modcrop</em><br>    ref = modcrop(ref, 3)<br>    degraded = modcrop(degraded, 3)<br>    <br>    <em># convert the image to YCrCb - (srcnn trained on Y channel)</em><br>    temp = cv2.cvtColor(degraded, cv2.COLOR_BGR2YCrCb)<br>    <br>    <em># create image slice and normalize  </em><br>    Y = numpy.zeros((1, temp.shape[0], temp.shape[1], 1), dtype=float)<br>    Y[0, :, :, 0] = temp[:, :, 0].astype(float) / 255<br>    <br>    <em># perform super-resolution with srcnn</em><br>    pre = srcnn.predict(Y, batch_size=1)<br>    <br>    <em># post-process output</em><br>    pre *= 255<br>    pre[pre[:] &gt; 255] = 255<br>    pre[pre[:] &lt; 0] = 0<br>    pre = pre.astype(np.uint8)<br>    <br>    <em># copy Y channel back to image and convert to BGR</em><br>    temp = shave(temp, 6)<br>    temp[:, :, 0] = pre[0, :, :, 0]<br>    output = cv2.cvtColor(temp, cv2.COLOR_YCrCb2BGR)<br>    <br>    <em># remove border from reference and degraged image</em><br>    ref = shave(ref.astype(np.uint8), 6)<br>    degraded = shave(degraded.astype(np.uint8), 6)<br>    <br>    <em># image quality calculations</em><br>    scores = []<br>    scores.append(compare_images(degraded, ref))<br>    scores.append(compare_images(output, ref))<br>    <br>    <em># return images and scores</em><br>    <strong>return</strong> ref, degraded, output, scores</pre><pre>ref, degraded, output, scores = predict(&#39;images/flowers.bmp&#39;)<br><br><em># print all scores for all images</em><br>print(&#39;Degraded Image: <strong>\n</strong>PSNR: <strong>{}\n</strong>MSE: <strong>{}\n</strong>SSIM: <strong>{}\n</strong>&#39;.format(scores[0][0], scores[0][1], scores[0][2]))<br>print(&#39;Reconstructed Image: <strong>\n</strong>PSNR: <strong>{}\n</strong>MSE: <strong>{}\n</strong>SSIM: <strong>{}\n</strong>&#39;.format(scores[1][0], scores[1][1], scores[1][2]))<br><br><br><em># display images as subplots</em><br>fig, axs = plt.subplots(1, 3, figsize=(20, 8))<br>axs[0].imshow(cv2.cvtColor(ref, cv2.COLOR_BGR2RGB))<br>axs[0].set_title(&#39;Original&#39;)<br>axs[1].imshow(cv2.cvtColor(degraded, cv2.COLOR_BGR2RGB))<br>axs[1].set_title(&#39;Degraded&#39;)<br>axs[2].imshow(cv2.cvtColor(output, cv2.COLOR_BGR2RGB))<br>axs[2].set_title(&#39;SRCNN&#39;)<br><br><em># remove the x and y ticks</em><br><strong>for</strong> ax <strong>in</strong> axs:<br>    ax.set_xticks([])<br>    ax.set_yticks([])</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j9a0kGhWcG8lEDLf5eqcfg.png" /></figure><pre><strong>for</strong> file <strong>in</strong> os.listdir(&#39;images&#39;):<br>    <br>    <em># perform super-resolution</em><br>    ref, degraded, output, scores = predict(&#39;images/<strong>{}</strong>&#39;.format(file))<br>    <br>    <em># display images as subplots</em><br>    fig, axs = plt.subplots(1, 3, figsize=(20, 8))<br>    axs[0].imshow(cv2.cvtColor(ref, cv2.COLOR_BGR2RGB))<br>    axs[0].set_title(&#39;Original&#39;)<br>    axs[1].imshow(cv2.cvtColor(degraded, cv2.COLOR_BGR2RGB))<br>    axs[1].set_title(&#39;Degraded&#39;)<br>    axs[1].set(xlabel = &#39;PSNR: <strong>{}\n</strong>MSE: <strong>{}</strong> <strong>\n</strong>SSIM: <strong>{}</strong>&#39;.format(scores[0][0], scores[0][1], scores[0][2]))<br>    axs[2].imshow(cv2.cvtColor(output, cv2.COLOR_BGR2RGB))<br>    axs[2].set_title(&#39;SRCNN&#39;)<br>    axs[2].set(xlabel = &#39;PSNR: <strong>{}</strong> <strong>\n</strong>MSE: <strong>{}</strong> <strong>\n</strong>SSIM: <strong>{}</strong>&#39;.format(scores[1][0], scores[1][1], scores[1][2]))<br><br>    <em># remove the x and y ticks</em><br>    <strong>for</strong> ax <strong>in</strong> axs:<br>        ax.set_xticks([])<br>        ax.set_yticks([])<br>      <br>    print(&#39;Saving <strong>{}</strong>&#39;.format(file))<br>    fig.savefig(&#39;output/<strong>{}</strong>.png&#39;.format(os.path.splitext(file)[0])) <br>    plt.close()<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*8lpeTi2p_F7AhE2o_7tJ9Q.png" /></figure><p><strong><em>For more programming related stuff, follow me on </em></strong><a href="https://twitter.com/xoraus"><strong><em>Twitter</em></strong></a><strong><em> &amp; </em></strong><a href="https://github.com/xoraus"><strong><em>Github</em></strong></a><strong><em>.</em></strong></p><ul><li><a href="https://github.com/xoraus/Super-Resolution-CNN-for-Image-Restoration">GitHub - xoraus/Super-Resolution-CNN-for-Image-Restoration: The goal of super-resolution (SR) is to recover a high-resolution image from a low-resolution input,</a></li><li><a href="https://github.com/xoraus">xoraus - Overview</a></li></ul><p>References:<br>[1] <a href="https://en.wikipedia.org/wiki/Convolutional_neural_network">https://en.wikipedia.org/wiki/Convolutional_neural_network</a></p><p>[2] <a href="http://keras.io/examples/cifar10_cnn/">http://keras.io/examples/cifar10_cnn/</a></p><p>[3] <a href="http://keras.io/layers/convolutional/">http://keras.io/layers/convolutional/</a></p><p>[4] <a href="https://arxiv.org/abs/1501.00092">https://arxiv.org/abs/1501.00092</a></p><p>[5] <a href="http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html">http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html</a>.</p><p>[6] [2014 ECCV] [SRCNN]<br><a href="https://arxiv.org/pdf/1501.00092">Learning a Deep Convolutional Network for Image Super-Resolution</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fb2a0d6%3Fas_embed%3Dtrue&amp;dntp=1&amp;display_name=Upscribe&amp;url=https%3A%2F%2Fupscri.be%2Fb2a0d6%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href">https://medium.com/media/0707f5c806284d01a4a13c7b13a91ce3/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff1e8420d846" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/using-the-super-resolution-convolutional-neural-network-for-image-restoration-ff1e8420d846">Using The Super Resolution Convolutional Neural Network for Image Restoration</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Deep Learning?]]></title>
            <link>https://medium.datadriveninvestor.com/what-is-deep-learning-273e5c0c2ba2?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/273e5c0c2ba2</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Thu, 15 Aug 2019 16:16:50 GMT</pubDate>
            <atom:updated>2019-08-16T08:42:30.462Z</atom:updated>
            <content:encoded><![CDATA[<h4>the hottest technology of the 21st century</h4><p>Deep learning is a machine learning technique that teaches computers to do what comes naturally to humans: learn by example. Deep learning is a key technology behind driverless cars, enabling them to recognize a stop sign or to distinguish a pedestrian from a lamppost. It is the key to voice control in consumer devices like phones, tablets, TVs, and hands-free speakers. Deep learning is getting lots of attention lately and for good reason. It is achieving results that were not possible before.</p><blockquote>“Machine intelligence is the last invention that humanity will ever need to make.” ~Nick Bostrom</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3EjPGqkgm6GIPUcy" /><figcaption>Photo by Alex Knight from Pexels</figcaption></figure><p>In deep learning, a computer model learns to perform classification tasks directly from images, text, or sound. Deep learning models can achieve state-of-the-art accuracy, sometimes exceeding human-level performance. Models are trained by using a large set of labeled data and neural network architectures that contain many layers</p><h3>Applications of Deep Learning</h3><ol><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Automatic_speech_recognition">Automatic speech recognition</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Image_recognition">Image recognition</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Visual_art_processing">Visual art processing</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Natural_language_processing">Natural language processing</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Drug_discovery_and_toxicology">Drug discovery and toxicology</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Customer_relationship_management">Customer relationship management</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Recommendation_systems">Recommendation systems</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Bioinformatics">Bioinformatics</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Medical_Image_Analysis">Medical Image Analysis</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Mobile_advertising">Mobile advertising</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Image_restoration">Image restoration</a></li><li><a href="https://en.wikipedia.org/wiki/Deep_learning#Financial_fraud_detection">Financial fraud detection</a></li></ol><h4>How Deep Learning Works</h4><p>Deep learning has evolved hand-in-hand with the digital era, which has brought about an explosion of data in all forms and from every region of the world. This data, known simply as big data, is drawn from sources like social media, internet search engines, e-commerce platforms, and online cinemas, among others. This enormous amount of data is readily accessible and can be shared through fintech applications like cloud computing.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FghIHXYLLbIUDIT17o2%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FghIHXYLLbIUDIT17o2%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FghIHXYLLbIUDIT17o2%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/3011953f18da63391c0f66dc76381a94/href">https://medium.com/media/3011953f18da63391c0f66dc76381a94/href</a></iframe><p>However, the data, which normally is unstructured, is so vast that it could take decades for humans to comprehend it and extract relevant information. Companies realize the incredible potential that can result from unraveling this wealth of information and are increasingly adapting to AI systems for automated support.</p><p>Deep learning learns from vast amounts of unstructured data that would normally take humans decades to understand and process.</p><h4>Why Deep Learning Matters</h4><h4>How does deep learning attain such impressive results?</h4><p>In a word, accuracy. Deep learning achieves recognition accuracy at higher levels than ever before. This helps consumer electronics meet user expectations, and it is crucial for safety-critical applications like driverless cars. Recent advances in deep learning have improved to the point where deep learning outperforms humans in some tasks like classifying objects in images.</p><p>While deep learning was first theorized in the 1980s, there are two main reasons it has only recently become useful:</p><ol><li>Deep learning requires large amounts of <strong>labeled data</strong>. For example, driverless car development requires millions of images and thousands of hours of video.</li><li>Deep learning requires substantial <strong>computing power</strong>. High-performance GPUs have a parallel architecture that is efficient for deep learning. When combined with clusters or cloud computing, this enables development teams to reduce training time for a deep learning network from weeks to hours or less.</li></ol><h4>Deep Learning Versus Machine Learning</h4><p>One of the most common AI techniques used for processing big data is machine learning, a self-adaptive algorithm that gets increasingly better analysis and patterns with experience or with newly added data.</p><p>If a digital payments company wanted to detect the occurrence or potential for fraud in its system, it could employ machine learning tools for this purpose. The computational algorithm built into a computer model will process all transactions happening on the digital platform, find patterns in the data set and point out any anomaly detected by the pattern.</p><p>Deep learning, a subset of machine learning, utilizes a hierarchical level of artificial neural networks to carry out the process of machine learning. The artificial neural networks are built like the human brain, with neuron nodes connected together like a web. While traditional programs build analysis with data in a linear way, the hierarchical function of deep learning systems enables machines to process data with a nonlinear approach.</p><p>A traditional approach to detecting fraud or money laundering might rely on the amount of transaction that ensues, while a deep learning nonlinear technique would include time, geographic location, IP address, type of retailer and any other feature that is likely to point to fraudulent activity. The first layer of the neural network processes a raw data input like the amount of the transaction and passes it on to the next layer as output. The second layer processes the previous layer’s information by including additional information like the user’s <a href="https://www.investopedia.com/terms/i/ip-address.asp">IP address</a> and passes on its result.</p><p>The next layer takes the second layer’s information and includes raw data like geographic location and makes the machine’s pattern even better. This continues across all levels of the neuron network.</p><h4>An Example of Deep Learning</h4><p>Using the fraud detection system mentioned above with machine learning, one can create a deep learning example. If the machine learning system created a model with parameters built around the number of dollars a user sends or receives, the deep-learning method can start building on the results offered by machine learning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i00gW3cG6NahwTRZ" /><figcaption>Photo by <a href="https://www.pexels.com/@pixabay?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pixabay </a>from <a href="https://www.pexels.com/photo/internet-screen-security-protection-60504/?utm_content=attributionCopyText&amp;utm_medium=referral&amp;utm_source=pexels">Pexels</a></figcaption></figure><p>Each layer of its neural network builds on its previous layer with added data like a retailer, sender, user, social media event, credit score, IP address, and a host of other features that may take years to connect together if processed by a human being. Deep learning algorithms are trained to not just create patterns from all transactions, but also know when a pattern is signaling the need for a fraudulent investigation. The final layer relays a signal to an analyst who may freeze the user’s account until all pending investigations are finalized.</p><p>Deep learning is used across all industries for a number of different tasks. Commercial apps that use image recognition, <a href="https://www.investopedia.com/terms/o/open-source.asp">open-source</a> platforms with consumer recommendation apps and medical research tools that explore the possibility of reusing drugs for new ailments are a few of the examples of deep learning incorporation.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F7DzlajZNY5D0I%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F7DzlajZNY5D0I%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F7DzlajZNY5D0I%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="281" frameborder="0" scrolling="no"><a href="https://medium.com/media/b92f65138145edba4223a42f329323c9/href">https://medium.com/media/b92f65138145edba4223a42f329323c9/href</a></iframe><p>References:</p><p>[1] <a href="https://en.wikipedia.org/wiki/Deep_learning">https://en.wikipedia.org/wiki/Deep_learning</a></p><p>[2] <a href="https://www.mathworks.com/discovery/deep-learning.html">https://www.mathworks.com/discovery/deep-learning.html</a></p><p>[3] <a href="https://www.investopedia.com/terms/d/deep-learning.asp">https://www.investopedia.com/terms/d/deep-learning.asp</a></p><p>[4] <a href="https://www.queryhome.com/tech/164250/small-discussion-about-deep-learning">https://www.queryhome.com/tech/164250/small-discussion-about-deep-learning</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=273e5c0c2ba2" width="1" height="1" alt=""><hr><p><a href="https://medium.datadriveninvestor.com/what-is-deep-learning-273e5c0c2ba2">What is Deep Learning?</a> was originally published in <a href="https://medium.datadriveninvestor.com/">DataDrivenInvestor</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is DynamoDb]]></title>
            <link>https://medium.com/swlh/what-is-dynamodb-fbb3f6d14f18?source=rss-2674269ff483------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbb3f6d14f18</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[dynamodb]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[nosql]]></category>
            <dc:creator><![CDATA[Sajjad Salaria]]></dc:creator>
            <pubDate>Wed, 14 Aug 2019 13:24:08 GMT</pubDate>
            <atom:updated>2019-08-15T11:54:51.478Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s learn about an effective NoSQL database.</p><p><strong><em>DynamoDB </em></strong><em>is a fully managed, Internet scalable, easily administrated and cost-effective NoSQL database.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*V_xDsmBX5_JhGjTp.jpg" /><figcaption><a href="https://jrebel.com/wp-content/uploads/2015/04/image00.jpg">https://jrebel.com/wp-content/uploads/2015/04/image00.jpg</a></figcaption></figure><h3><strong>Benefits of DynamoDB:</strong></h3><p><strong>Scalability and Performance</strong></p><p>Using Amazon DynamoDB, Developers can combine incremental scalability and high performance with the ease of cloud administration, reliability and table data model and thus can meet the customer demand. It can scale the table assets to a large number of servers on various Availability Zones for addressing storage need. In addition, there is no specific limit to the quantity of data that a table can store. As a result, any amount of data can be stored and retrieved and Dynamo DB shared data across more servers with the increase of data stored in a table.</p><p><strong>Cross-region Replication</strong></p><p>It enables you to maintain identical copies as replicas of a DynamoDB master table in one or more AWS regions. Once you enable cross-region replication for a table, identical copies of the table are created in other AWS areas. Any mode of changes in the table will be consequently propagated to all replicas.</p><p><strong>TTL (Time to Live)</strong></p><p>TTL is a process that gives you an opportunity to set a specific timestamp to delete expired data from your tables. Once the timestamp expires, the relating item is marked as expired and is subsequently deleted from the table. By using this functionality, you don’t need to track expired data and delete it manually. TTL can help you reduce storage usage and reduce the cost of storing data that is no longer important.</p><p><strong>Fine-grained Access Control</strong></p><p>Fine-Grained Access Control gives a DynamoDB table owner a high level of control over data in the table. In particular, the table owner can specify who can access which data or attributes of the table and perform what actions such as read-write or update. Fine-Grained Access Control is used in combination with AWS Identity and Access Management, which manages the security credentials and the related permissions.</p><p><strong>Stream</strong></p><p>Using the DynamoDB Streams, developers can update and receive the item-level data before and after data are changed. DynamoDB Streams provides a time-ordered sequence of data changes made in a table in the last 24 hours. You can access a stream with a simple API call and use it to keep other data stores updated with the latest changes and take actions based on it.</p><h3><strong>Tables, Items, and Attributes</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*kabTXfx--ohJsJXc.gif" /><figcaption><a href="https://d2908q01vomqb2.cloudfront.net/887309d048beef83ad3eabf2a79a64a389ab1c9f/2018/09/10/dynamodb-partition-key-1.gif">https://d2908q01vomqb2.cloudfront.net/887309d048beef83ad3eabf2a79a64a389ab1c9f/2018/09/10/dynamodb-partition-key-1.gif</a></figcaption></figure><p>The following are the basic DynamoDB components:</p><ul><li><strong>Tables</strong> — Similar to other database systems, DynamoDB stores data in tables. A <em>table</em> is a collection of data. For example, see the example table called <em>People</em> that you could use to store personal contact information about friends, family, or anyone else of interest. You could also have a <em>Cars</em> table to store information about vehicles that people drive.</li><li><strong>Items</strong> — Each table contains zero or more items. An <em>item</em> is a group of attributes that is uniquely identifiable among all of the other items. In a <em>People</em> table, each item represents a person. For a <em>Cars</em> table, each item represents one vehicle. Items in DynamoDB are similar in many ways to rows, records, or tuples in other database systems. In DynamoDB, there is no limit to the number of items you can store in a table.</li><li><strong>Attributes</strong> — Each item is composed of one or more attributes. An <em>attribute</em> is a fundamental data element, something that does not need to be broken down any further. For example, an item in a <em>People</em> table contains attributes called <em>PersonID</em>, <em>LastName</em>, <em>FirstName</em>, and so on. For a <em>Department</em> table, an item might have attributes such as <em>DepartmentID</em>, <em>Name</em>, <em>Manager</em>, and so on. Attributes in DynamoDB are similar in many ways to fields or columns in other database systems.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/0*LLCJgDViLtl8iGiP.png" /></figure><p>Note the following about the <em>People</em> table:</p><ul><li>Each item in the table has a unique identifier, or primary key, that distinguishes the item from all of the others in the table. In the <em>People</em> table, the primary key consists of one attribute (<em>PersonID</em>).</li><li>Other than the primary key, the<strong> <em>People</em> table is schema-less, which means that neither the attributes nor their data types need to be defined beforehand. Each item can have its own distinct attributes.</strong></li><li>Most of the attributes are <em>scalar</em>, which means that they can have only one value. Strings and numbers are common examples of scalars.</li><li>Some of the items have a nested attribute (<em>Address</em>). DynamoDB supports nested attributes up to 32 levels deep.</li></ul><p>The following is another example table named <em>Music</em> that you could use to keep track of your music collection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*Xfuz6OZzjWJF3vo6.png" /></figure><p>Note the following about the <em>Music</em> table:</p><ul><li>The primary key for <em>Music</em> consists of two attributes<strong> (<em>Artist</em> and <em>SongTitle</em>).</strong> Each item in the table must have these two attributes. The combination of <em>Artist</em> and <em>SongTitle</em> distinguishes each item in the table from all of the others.</li><li>Other than the primary key, the <em>Music</em> table is schema-less, which means that neither the attributes nor their data types need to be defined beforehand. Each item can have its own distinct attributes.</li><li>One of the items has a nested attribute (<em>PromotionInfo</em>), which contains other nested attributes. DynamoDB supports nested attributes up to 32 levels deep.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/0*9s-JLVLgclSdBYfA.png" /><figcaption><a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/images/HowItWorksStreams.png">https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/images/HowItWorksStreams.png</a></figcaption></figure><p>When you create a table, in addition to the table name, you must specify the primary key of the table. The primary key uniquely identifies each item in the table, so that no two items can have the same key.</p><h4>DynamoDB supports two different kinds of primary keys:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7BcSluKirWiK5sy-" /></figure><ul><li><strong>Partition key</strong> — A simple primary key, composed of one attribute known as the <em>partition key</em>.</li><li>DynamoDB uses the partition key’s value as input to an internal hash function. The output from the hash function determines the partition (physical storage internal to DynamoDB) in which the item will be stored.</li><li>In a table that has only a partition key, no two items can have the same partition key value.</li><li>The <em>People</em> table described in <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.TablesItemsAttributes">Tables, Items, and Attributes</a> is an example of a table with a simple primary key (<em>PersonID</em>). You can access any item in the <em>People</em> table directly by providing the <em>PersonId</em> value for that item.</li><li><strong>Partition key and sort key</strong> — Referred to as a <em>composite primary key</em>, this type of key is composed of two attributes. The first attribute is the <em>partition key</em>, and the second attribute is the <em>sort key</em>.</li><li>DynamoDB uses the partition key value as input to an internal hash function. The output from the hash function determines the partition (physical storage internal to DynamoDB) in which the item will be stored. All items with the same partition key are stored together, in sorted order by sort key value.</li><li>In a table that has a partition key and a sort key, it’s possible for two items to have the same partition key value. However, those two items must have different sort of key values.</li><li>The <em>Music</em> table described in <a href="https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.TablesItemsAttributes">Tables, Items, and Attributes</a> is an example of a table with a composite primary key (<em>Artist</em> and <em>SongTitle</em>). You can access any item in the <em>Music</em> table directly if you provide the <em>Artist</em> and <em>SongTitle</em>values for that item.</li><li>A composite primary key gives you additional flexibility when querying data. For example, if you provide only the value for <em>Artist</em>, DynamoDB retrieves all of the songs by that artist. To retrieve only a subset of songs by a particular artist, you can provide a value for <em>Artist</em> along with a range of values for <em>SongTitle</em>.</li></ul><p>DynamoDB can have three data types</p><ol><li><strong>Scalar</strong></li><li><strong>Set</strong></li><li><strong>Document</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*r-2YvfII1Iin5vaI" /><figcaption><a href="https://image.slidesharecdn.com/srv404deepdiveonamazondynamodb-170731162610/95/srv404-deep-dive-on-amazon-dynamodb-14-638.jpg?cb=1501518430">https://image.slidesharecdn.com/srv404deepdiveonamazondynamodb-170731162610/95/srv404-deep-dive-on-amazon-dynamodb-14-638.jpg?cb=1501518430</a></figcaption></figure><p>A scalar can be<strong> String, Number, and Binary, Boolean, Null.</strong></p><p>A set can be:</p><ul><li>String Set : [“Jane”, “Doe”,”Kevin”],</li><li>Number Set: [42.2, -19, 7.5, 3.14]</li><li>Binary Set: [“uKASDB”, “ASDDSFFF”]</li></ul><p><strong>A set can only be of one Scalar type, Each value must be unique in the Set</strong></p><p><strong>Document:</strong></p><p>A document can be a<strong> List</strong> — [“Jane”, 122, 2.30]. There are no restriction on data type.A document can be a <strong>map</strong> — It is an unordered collection of name value pairs - {Day: ‘Monday’, Emails: 34}</p><p>These indexes allow you to query table data with an alternate key. Though DynamoDB does not force their use, they optimize querying.</p><p>DynamoDB uses two types of secondary indexes −</p><ul><li><strong>Global Secondary Index</strong> − This index possesses partition and sort keys, which can differ from table keys.</li><li><strong>Local Secondary Index</strong> − This index possesses a partition key identical to the table, however, its sort key differs.</li></ul><p>References:</p><p>[1]:<a href="https://docs.aws.amazon.com/amazondynamodb">https://docs.aws.amazon.com/amazondynamodb</a></p><p>[2]:<a href="https://aws.amazon.com/dynamodb/">https://aws.amazon.com/dynamodb/</a></p><p>[3]:<a href="https://en.wikipedia.org/wiki/Amazon_DynamoDB">https://en.wikipedia.org/wiki/Amazon_DynamoDB</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbb3f6d14f18" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/what-is-dynamodb-fbb3f6d14f18">What is DynamoDb</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>