<?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 Himalee on Medium]]></title>
        <description><![CDATA[Stories by Himalee on Medium]]></description>
        <link>https://medium.com/@himalee.tailor?source=rss-b988df2f3113------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*N0v1xWGkjoaXLz_wjMCFOQ.jpeg</url>
            <title>Stories by Himalee on Medium</title>
            <link>https://medium.com/@himalee.tailor?source=rss-b988df2f3113------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 15:57:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@himalee.tailor/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[Managing Mutable State in JavaScript]]></title>
            <link>https://medium.com/@himalee.tailor/managing-mutable-state-in-javascript-7b4e5af13e89?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/7b4e5af13e89</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mutability]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Mon, 05 Aug 2019 16:11:13 GMT</pubDate>
            <atom:updated>2019-08-05T16:11:13.776Z</atom:updated>
            <content:encoded><![CDATA[<h4>Mutable vs Immutable Objects</h4><p>Having moved from working in Elixir to JavaScript, one of the differences was managing mutable state. Elixir is a functional language which embraces immutability. This means that once data such as variables or objects are created, their state cannot be changed. If you want to change or transform data, for example being able to place a mark on a tic tac toe board, the original board data will still exist, and a new board will be created after being passed to a function to be transformed. This has the advantage of being able to freely pass data around with the guarantee that it will not be mutated in memory.</p><p>JavaScript on the other hand allows for the ability to assign a value to a variable, and then being able to change the value of the variable during the execution of a program. Values that are mutable include objects, arrays, functions, classes, sets, and maps. In a game of tic tac toe, being able to mutate the boards state, instead of making a new copy every time it is marked, allows the game to run faster.</p><h4>The Problem</h4><p>When building an unbeatable tic tac toe computer player, each available move on a board needs to be assessed and scored depending on the outcome of the game. Using recursion, we are able to compute the available scores and associated moves by continuing to recurse and pass the newly marked board to the function until all available moves have been scored. The data structure chosen for the tic tac toe board was a JavaScript array, this means that it is mutable. I needed to ensure that during the process of scoring each available move, I wasn’t mutating the original board. If the original board state was being changed, then when the next available move was being scored, the board would not be refreshed and the move will be scored using the newly marked board (not the original board). For example, if the available positions are 1, 3 and 7, once a score for position 1 has been computed, when assessing the score for position 3, I need to assess it using the original board (not the board that has been marked during the computation of the score for position 1).</p><h4>The Solution</h4><p>In order to avoid mutating the state of my board, I needed to make a copy of the original board being passed to the unbeatable computer player function, and use that copy to score the available moves. In JavaScript, calling .slice() on an array is a way to create a new array and copy all elements to it:</p><p>let newBoard = board.slice()[move] = mark;</p><p>This means that after scoring the first available move, when we want to score the second available move, the original board is used rather than a mutated one. This means that any changes made on the cloned board will not be reflected on the original board, meaning we can use the original board when scoring all available moves.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7b4e5af13e89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DRYing tests in Elixir]]></title>
            <link>https://medium.com/@himalee.tailor/drying-tests-in-elixir-a6ce033bc300?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6ce033bc300</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[tdd]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Wed, 10 Jul 2019 10:49:05 GMT</pubDate>
            <atom:updated>2019-07-10T10:49:05.037Z</atom:updated>
            <content:encoded><![CDATA[<p>Don’t repeat yourself (DRY) is a principle of software development aimed at reducing repetition in your code. Repetition becomes a problem because, if the functionality of the duplicated code needs to change, it would need to change it in all places where the duplication exists. By reducing repetition, it allows us to better manage our code.</p><p>I have recently started building Tic Tac Toe in Elixir. In my integration tests, each time I want to run my main method which starts the app, I used the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2199ee5a92ae194d6c3612e21d660a8/href">https://medium.com/media/f2199ee5a92ae194d6c3612e21d660a8/href</a></iframe><p>Running my main method in each test caused repetition, and when the number of integration tests increases, the repetition would grow and it would become more difficult to manage the code. Elixir comes with the testing framework ExUnit, which has an ExUnit.Callbacks module. This enable us to call a unit of work separately from the primary application thread, or allows for asynchronous programming. We can use ExUnit.Callback functions such as setup/1 and setup_all/1 to reduce duplication— setup/1 is called before each test whilst setup_all/1 is called once per module before any test runs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b70d54f8eaf2ef493811bd6c7cf1f6e/href">https://medium.com/media/1b70d54f8eaf2ef493811bd6c7cf1f6e/href</a></iframe><p>Both setup/1 and setup_all/1 return a map, a key-value data structure, called context in this example. This will hold information you will want to access in your tests. To access this map, and call it in the individual tests, the tests must accept context as a single argument. To call the function that has been set up, we can access it via the key: context[:start]. This results in reduced duplication and makes our test suite easier to manage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6ce033bc300" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing a HTTP Server]]></title>
            <link>https://medium.com/@himalee.tailor/designing-a-http-server-96382d8a0507?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/96382d8a0507</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[design-patterns]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Tue, 04 Jun 2019 16:11:36 GMT</pubDate>
            <atom:updated>2019-06-05T09:04:17.816Z</atom:updated>
            <content:encoded><![CDATA[<p>Over the past few weeks, I have been working on building a HTTP server. Using the <a href="https://medium.com/@himalee.tailor/getting-to-grips-with-the-http-request-response-cycle-f68cf46de103">HTTP request — response</a> cycle, a HTTP server allows browsers to make requests for some information, such as a file, which is hosted on a server. The browser makes the request using the Hyper-Text Transfer Protocol (HTTP). The request reaches the server, it accepts the request, reads the request and tries to find the requested piece of information. If it finds it, it responds appropriately and sends it back to the browser, also via HTTP. If it doesn’t, it returns a 404 Not Found response.</p><p>One of the big learning curves, and difficulties, I faced when building the server was designing it well, so it is readable, maintainable and extendable. I was faced with 3 problems:</p><ol><li>How can I test the behaviour of the server without accepting real connections?</li><li>How can I reduce duplication when creating a new handler?</li><li>How can I build my responses in a clear, readable and simple way?</li></ol><p>I was able to solve these problems by implementing design patterns, solutions to a commonly occurring problems in software design.</p><h4>Problem 1: How can I test the behaviour of the server without accepting real connections?</h4><p>There are many reasons why you don’t want to test whether a real connection is made, demonstrated through the creation of a Socket . Not only can this increase the time of running tests, if implementation details change that your tests rely on, then your tests will fail. This is why is is important not to mock what you don’t own. A mock is an object that is pre-programmed with expectations about the calls they will receive. Also, we want to ensure that we are testing the behaviour of the server, not implementation details. For example, instead of testing whether a method returns a specific object, we instead want to check whether the method was called.</p><h4>Solution: The humble object pattern</h4><p>The humble object pattern enables us to extract the logic into a separate, easy-to-test component that is decoupled from its environment. By wrapping third party code in your own code means we can mock our own code. We can do this in Java by using interfaces. For example, by creating a SocketManager interface that is responsible for managing the creation of a ServerSocket and will also go on to creating a Socket, we can create a MockServerSocketManager that implements the SocketManager.</p><p>This means in our tests we can use the MockServerSocketManager, solving our problem, and in our real server we can pass the ServerSocketManager. When testing, we can assert on whether .listen() was called, and if it was it should return true. By doing this, we can test the behaviour of the server, and if implementation details of the Java ServerSocket change, we have wrapped our code in one place, so we should only need to change the code in that one place.</p><pre><em># SocketManager wraps &#39;third party&#39; Java code </em></pre><pre>public interface SocketManager {</pre><pre>    void listen(int port) throws IOException;<br>}</pre><pre><em># Real SocketManager used in Server</em></pre><pre>public class ServerSocketManager implements SocketManager {<br><br>    private ServerSocket serverSocket;<br><br>    public void listen(int port) throws IOException {<br>        serverSocket = new ServerSocket(port);<br>    }<br>}</pre><pre><em># Mock SocketManager used in unit tests</em></pre><pre>public class MockServerSocketManager implements SocketManager {<br><br>    private boolean listenCalled = false;<br><br>    public void listen(int port) {<br>       listenCalled = true;<br>    }<br>}</pre><h4>Problem 2: How can I reduce duplication when creating a new handler?</h4><p>A Handler is responsible for building responses given specific HTTP requests. Once a RouterHandler routes the request uri to it’s specific Handler, initially each Handler was checking the request method, or methods, using the same algorithm to build a response. This meant that every new Handler that was being created featured the same algorithm, and duplication arose in my code. This means that in the future, if the functionality of that code needed to change, it would need to change it in all places where the duplication exists. This goes against the don’t repeat yourself (DRY) principle of software development.</p><h4>Solution: Template method pattern</h4><p>The template method design pattern defines an algorithm as a skeleton of operations and leaves the details to be implemented by the child classes. We can do this in Java by using an abstract class, which is similar to interface except that it can contain default method implementation.</p><pre><em># Handler containing algorithm </em></pre><pre>public abstract class Handler {<br><br>    public final Response handle(Request request) {<br>        boolean requestContainsValidHttpMethod = httpMethods().contains(request.getHttpMethod());<br>        if (requestContainsValidHttpMethod) {<br>            return buildResponse(request);<br>        }<br>        return methodNotAllowedResponse();<br>    }<br><br>    public abstract String url();<br>    public abstract List&lt;String&gt; httpMethods();<br>    public abstract Response buildResponse(Request request);<br><br>}</pre><pre><em># New SimpleGet Handler that doesn&#39;t feature algorithm but extends Handler</em></pre><pre>public class SimpleGetHandler extends Handler {<br><br>    @Override<br>    public String url() {<br>        return &quot;/simple_get&quot;;<br>    }<br><br>    @Override<br>    public List&lt;String&gt; httpMethods() {<br>        return Arrays.<em>asList</em>(HTTPMethod.<em>GET</em>, HTTPMethod.<em>HEAD</em>);<br>    }<br><br>    @Override<br>    public Response buildResponse(Request request) {<br>        return new ResponseBuilder().setStatusLine(&quot;HTTP/1.1 200 OK\r\n\r\n&quot;).setHeaders(&quot;&quot;).setBody(&quot;&quot;).build();<br>    }<br>}</pre><p>This now means that the duplication is reduced and the algorithm only exists in one place, the abstract Handler class. We can easily add a new Handler through extending Handler and we can redefine certain steps of the algorithm by overriding the methods with specific information about the new Handler, such as the request url, HTTP methods and the response.</p><h4>Problem 3: How can I build my responses in a clear, readable and simple way?</h4><p>A HTTP response comprises of a status line, headers, which includes additional information about the response, and a response body. Before implementing the builder pattern, my responses were built by concatenating strings which was specific, unclear and hard to read:</p><pre><em># Before: building responses through string concatenation </em></pre><pre>public class ResponseBuilder { </pre><pre>    private static final String EMPTY_BODY_OUTPUT = “”; <br>    private static final String STATUS_CODE_OK = “HTTP/1.1 200 OK”; <br>    private static final String CRLF = “\r\n”; </pre><pre>    public String okayWithEmptyBody() { return STATUS_CODE_OK + CRLF       + CRLF + EMPTY_BODY_OUTPUT; }</pre><pre>}</pre><h4>Solution: Builder pattern</h4><p>The builder pattern was a solution to construct Response objects in clear and simple way, improving readability. In this new implementation of a ResponseBuilder, we can build a Response in small steps, and can easily see which part of the Response is being built, such as the headers via setHeaders().</p><pre><em># After: build Response objects using ResponseBuilder</em></pre><pre>public class ResponseBuilder {<br><br>    private String statusCode;<br>    private String headers;<br>    private String body;<br><br>    public ResponseBuilder setStatusLine(String statusCode) {<br>        this.statusCode = statusCode;<br>        return this;<br>    }<br><br>    public ResponseBuilder setHeaders(String headers) {<br>        this.headers = headers;<br>        return this;<br>    }<br><br>    public ResponseBuilder setBody(String body) {<br>        this.body = body;<br>        return this;<br>    }<br><br>    public Response build() {<br>        return new Response(statusCode, headers, body);<br>    }<br>}</pre><pre><em># Creation of a Response object: </em></pre><pre>public Response buildResponse(Request request) {<br>    return new ResponseBuilder().setStatusLine(&quot;HTTP/1.1 200 OK\r\n\r\n&quot;).setHeaders(&quot;&quot;).setBody(&quot;&quot;).build();<br>}</pre><p>Building a HTTP server has been a great way to gain an understanding of what HTTP actually is, how the HTTP request — response cycle works and how well designed code can help with readability, maintainability and extendability.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96382d8a0507" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reading a HTTP Request]]></title>
            <link>https://medium.com/@himalee.tailor/reading-a-http-request-29edd181a6c5?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/29edd181a6c5</guid>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Wed, 15 May 2019 16:33:34 GMT</pubDate>
            <atom:updated>2019-05-15T16:36:31.363Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is a HTTP request?</h4><p>A HTTP request is a request message with information that gets sent from a client to a server, using the hypertext transfer protocol (HTTP). In order for information, such as text, images, or pages to be delivered to your browser, a request needs to be made to fetch that data — a HTTP request allows this to happen. Based on this request, the server then responds. It is important to be able to read the HTTP request message so the server can respond appropriately.</p><h4>What does a HTTP request message look like?</h4><p>A HTTP request message starts with a request line. The request line includes a HTTP method, such as GET or POST. It also includes the request Uniform Resource Identifier (URI) which is used to identify a resource, allowing access to web pages. The HTTP version follows, then the request line finishes with Carriage Return Line Feed (CRLF) which are end-of-line markers for all protocol elements, except the entity-body.</p><p>Following the request line are request headers which contain further information about the request such as the Host which is the internet host and port number of the resource being requested. The final part of the request is the body. This is important when a request sends data to the server, such as via a POST request.</p><pre>GET /simple_get HTTP/1.1<br>Host: 127.0.0.1:5000<br>User-Agent: Mozilla/5.0<br>Accept: text/html<br>Accept-Language: en-GB, en;q=0.8<br>Accept-Encoding: gzip, deflate<br>Connection: keep-alive</pre><h4>Where does the HTTP request message get sent to?</h4><p>When a client wants to send a request to a server, via the browser, when the request is made, a Socket is created and anInputStream and an OutputStream are established between the client and the server, allowing for communication between the two:</p><pre>InputStream inputStream = socket.getInputStream(); <br>OutputStream outputStream = socket.getOutputStream();</pre><p>The HTTP request message is written to the InputStream.</p><h4>What is an InputStream?</h4><p>The Java InputStream class represents an ordered stream of bytes. In other words, you can read data from a Java InputStream as an ordered sequence of bytes.</p><h4>What are bytes?</h4><p>A byte is a unit of data, and is one of the primitive data types in Java.</p><h4>Reading the Request Line</h4><p>In order to read the request line, an InputStreamReader can be used as a bridge from byte streams to character streams. It reads bytes and decodes them into characters. Using a BufferedReader enables us to read the text from the character stream, buffering characters to allow the efficient reading of characters. The readLine() method means we can read a line of text, but everything after a carriage return, /r, or a line feed, /n, (CRLF) is not read. This means we only can read the request line of the request message.</p><pre>InputStreamReader inputStreamReader = new InputStreamReader(inputStream); <br>BufferedReader bufferedReader = new BufferedReader(inputStreamReader); <br>String request = bufferedReader.readLine();</pre><h4>Reading the Entire Request</h4><p>When implementing a POST request, reading the first line does not suffice as in order to read the data sent to the server, we need to access the request body. How can we do this?</p><pre>public String read(InputStream inputStream) throws IOException {<br>    StringBuilder result = new StringBuilder();<br>    do {<br>        result.append((char) inputStream.read());<br>    } while (inputStream.available() &gt; 0);<br>    return result.toString();<br>}</pre><p>By creating a new StringBuilder we are can create a String object that we can append, or add, to by using the append() method. (char) inputStream.read() reads the next byte of data from the InputStream, appending the StringBuilder character by character. Calling .available() on the InputStream means we get an estimate of the number of bytes that can be read from the InputStream, we want to continue appending characters until all the bytes have been read. We can only start to access the InputStream once we read from it, only then are we able to call .available(). Finally, calling toString() on the StringBuilder object returns a string representing of the data. This means we have the entire request message, not just the first line, but the request body where we can see data that has been sent via a POST request. Success!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29edd181a6c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Delving into Django]]></title>
            <link>https://medium.com/@himalee.tailor/delving-into-django-a571b537f737?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/a571b537f737</guid>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Wed, 01 May 2019 14:10:35 GMT</pubDate>
            <atom:updated>2019-05-01T14:10:35.152Z</atom:updated>
            <content:encoded><![CDATA[<p>Having recently finished a client tour, I was able to get some valuable experience working on code base in production including interacting with an international team, learning about the stages code goes through before going into production and ramping up on new languages and frameworks, including Django. Django is a Python back end framework that was used in this project, what is it and what are it’s capabilities?</p><h4>What is Django?</h4><p>Django is designed for the rapid development of web applications, including interacting with databases. After installing <a href="https://www.python.org/downloads/">Python</a> and <a href="https://www.djangoproject.com/download/">Django</a>, you can quickly set up a new project with the command django-admin startproject mysite which creates a directory called mysite.</p><p>Not only is it fast, it is also great when security is a priority with features such as a user authentication model, including the ability to configure different user permissions. Django is also able to handle projects of different size and capacity, including high-load web applications which can handle heavy traffic and large volumes of information.</p><h4>Model View Template Pattern</h4><p>Django uses the Model View Template pattern. The models generally represents a single database table, with the attributes of a model representing a database field, or table column. In the below example, Person is the name of the model, first_name and last_name are the attributes, or properties, of the model. Each attribute needs to be associated with a data type, so the database knows the type of data that needs to be saved. CharField(max_length=30) means a text data type with a maximum number of 30 characters. To add the newly created model to our database, you can use the command python manage.py makemigrations in the terminal, which prepares a migration file, followed by python manage.py migrate which will add it to the database.</p><pre><em>models.py</em></pre><pre><strong>from</strong> <strong>django.db</strong> <strong>import</strong> models<br><br><strong>class</strong> <strong>Person</strong>(models.Model):<br>    first_name = models.CharField(max_length=30)<br>    last_name = models.CharField(max_length=30)</pre><p>The view is responsible for describing, or controlling, the data that gets presented to the user, not how the data looks. The view is the equivalent to the controller in the model view controller pattern. The method below in a views.py file takes a request and will render the template file person_list.html.</p><pre><em>views.py</em></pre><pre><strong>from</strong> <strong>django.shortcuts</strong> <strong>import</strong> render<br><strong>from models import</strong> Person</pre><pre><strong>def person_list</strong>(request):<br>    people = Person.objects.all()<br>    return render(request, &#39;person_list.html&#39;, {&#39;people&#39;: people})</pre><p>How the data is presented is the templates responsibility. In the above example, people = Person.objects.all() reads all the data saved in the Person model and saves it to the variable people. This is a query set which is a list of objects of a given model. {&#39;people&#39;: people} allows us to use our newly created query set, people in our templates:</p><pre><em>person_list.html</em></pre><pre><strong>&lt;h1&gt;</strong>List of People<strong>&lt;/h1&gt;</strong><br> <strong> &lt;ul&gt;</strong><br>    {% for person in people %}<br>       &lt;p&gt;first name: {{ person.first_name }}&lt;/p&gt;<br>       &lt;p&gt;last name: {{ person.last_name }}&lt;/p&gt;<br>    {% endfor %}<br>  <strong>&lt;/ul&gt;</strong></pre><p>This template will loop over the list of people saved in the People model and display a list of all saved first and last names.</p><h4>What is Django admin?</h4><p>The Django admin is an interface that reads data from your models, allowing users to add, edit and delete data from specific models. Once you have created user to login with, via the createsuperuser command, and the server is running you can access the Django admin panel by visiting the URL <a href="http://127.0.0.1:8000/admin/">http://127.0.0.1:8000/admin/</a> .</p><h4>What is Django CMS?</h4><p>A content management system (CMS) allows for the creation and modification of online content. Django CMS is a tool that connects to Django admin allowing for the customisation of online content. Without touching the code, those responsible for editing websites can update images, change text, reposition content etc, without needing to directly change the code base, but by interacting with Django CMS.</p><p>Whilst Django admin is a great tool for interacting with the database, it is not intended for building out the front end of an application. On the other hand, Django CMS allows you to do exactly this, building and editing your front end through creating pages, organising layout and updating content.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a571b537f737" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is an EchoServer?]]></title>
            <link>https://medium.com/@himalee.tailor/what-is-an-echoserver-b2bfd3b8deeb?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2bfd3b8deeb</guid>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 15:03:54 GMT</pubDate>
            <atom:updated>2019-04-29T15:13:43.504Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is an Echo server?</h3><p>An EchoServer is an application that allows a client and a server to connect so a client can send a message to the server and the server can receive the message and send, or echo, it back to the client.</p><h4>Server</h4><p>A server is a computer or computer program that provides a service to another computer, or client. For example, the internet is based on web servers that respond to requests from clients via web browsers. How do you connect to a server to access it services? Often, you will connect to a server over a computer network, which is a group of computers connected together in order to share resources. To connect to a server, you need to know the port number that the server socket is listening on, which is an endpoint for communication between the client and the server. Each port number is associated with an IP address, a numerical label assigned to each device connected to a computer network, and a protocol type, preset rules and guidelines for communicating data. With the port number and IP address, you can attempt to establish a connection to a server. It is important to note that when building an echo server, it is not a requirement to be connected within a network. The server can be run locally on a computer and a client can connect to the server via the same computer.</p><h4>Client</h4><p>A client is responsible for sending a message to the server, and is also where the message is echoed back to. Once the server is running, or listening for connections, a client is able to send a request to the server. With the correct port number and IP address, and if everything goes to plan, the server accepts the connection and creates a new socket. Through the newly created socket, the client and server can now communicate by writing to or reading from the socket.</p><h4>Dealing with Input and Output</h4><p>In order to build an echo server that receives a client message and echoes it back to the client, getting the input and output streams from a connected socket is necessary for creating the communication channels between the client and server. These streams are flows of data that mean the client can now send messages to the server, and the server can echo back the message to the client. In Java, we can create this communication channel by calling .getInputStream() and .getOutputStream() on the socket. The input stream allows data to flow from the client to the server, whilst the output stream allows the server to send data back to the client.</p><p>Now we have established the communication channels, how to do we actually take some input from the client, write that to the InputStream, read from theInputStream and then send that input back to the client via the OutputStream?</p><p>To write to and read data from the input channel, we can use Java classes Scanner or BufferReader. Both allows for the ability to read user input from the command line. Whilst Scanner parses, or converts, input data (strings or primitive types) using regular expressions, BufferReader simply reads the characters.</p><pre>//Scanner<br>Scanner input = <strong>new</strong> Scanner(InputStream inputStream);<br>return input.nextLine();</pre><pre>//BufferReader</pre><pre>BufferedReader input = <strong>new</strong> BufferedReader(<strong>new</strong> InputStreamReader(InputStream inputStream));<br>return input.readLine();</pre><p>To present input back to the client, we can pass the outputStream to Java class PrintWriter , then call the println() method which converts the binary data in the outputStream to bytes. This allows for the ability to print a message back to the client in string format:</p><pre>PrintWriter output = <strong>new</strong> PrintWriter(OutputStream outputStream)<br>output.println(&quot;Hello, world&quot;)</pre><p>Now that the client has successfully sent a request, which leads to the creation of a new socket, the communication channels can be established via the input and output streams so data can flow from the client, to the server and back to the client.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2bfd3b8deeb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Databases Part 3: Building a Java CRUD app]]></title>
            <link>https://medium.com/@himalee.tailor/working-with-databases-part-3-building-a-java-crud-app-66c632e72a2b?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/66c632e72a2b</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Thu, 28 Feb 2019 11:07:55 GMT</pubDate>
            <atom:updated>2019-02-28T11:07:55.782Z</atom:updated>
            <content:encoded><![CDATA[<p>Navigating around the <a href="https://medium.com/@himalee.tailor/working-with-databases-part-2-using-the-postgres-interactive-terminal-95a5100f0b7b">Postgresql interactive terminal </a>was great way to get an idea how Postgresql works — how to create new databases and run sql commands to create new tables, rows and to select data. My task was to build a Java <strong>CRUD</strong> app with the ability to run 4 basic functions — to <strong>C</strong>reate new data that can be saved to the database, to <strong>R</strong>ead the data from the database and display it to the user, to<strong> U</strong>pdate data that has previously saved to the database and to <strong>D</strong>elete data that is no longer required. How do I do this in Java, outside the Postgresql terminal?</p><p><strong>JDBC</strong> - <strong>J</strong>ava<strong> D</strong>ata<strong>b</strong>ase <strong>C</strong>onnectivity - is a Java API that is used to make connections to a database and to create and execute SQL queries in order to create, view and modify data. This is what I needed in order build those 4 functions, and here are the steps that were taken in order to achieve this:</p><ol><li>First, I needed to <strong>import</strong> the required packages, which are a pre-written set of grouped related classes with a specific functionality, in this case to achieve database programming. Importing java.sql suffices.</li><li>In order to open a communication channel with a database so you can interact with it, <strong>registering a JDBC Driver </strong>is necessary: Class.<em>forName</em>(&quot;org.postgresql.Driver&quot;). The Driver is responsible for implementing the protocol for transferring information between the client and database.</li><li>Using the Driver, a physical <strong>connection </strong>to a specific Database can be made: Connection connection = DriverManager.<em>getConnection</em>(databaseURL). The DriverManager is a class responsible for managing the Driver. Your database URL will take the following form: &quot;jdbc:postgresql://host:port/database&quot;.</li><li>In order to execute a SQL query and submit it to the database, a <strong>Statement object </strong>needs to be created. You need a Connection object to create a Statement object: Statement statement = connection.<em>createStatement</em>(). The Statement represents a SQL statement which is ready to be executed.</li><li>When you execute a Statement object, you can generate a<strong> ResultSet </strong>object which contains the result of the executed SQL query: ResultSet resultSet = statement.executeQuery(&quot;SELECT * FROM table_name;&quot;). The ResultSet object maintains a cursor that points to the current row in the ResultSet. By calling .next() on the resultSet, the cursor moves down to the next row in the table. To create, update and delete data, you only need to execute the relevant SQL query, the <strong>resultSet</strong> object is only used when you want to read from the database.</li><li>To save database resources, close the Statement object and database connection: statement.close() and connection.close().</li></ol><p>Here is a code example of everything working together. In order to access the database, you must start the <a href="https://medium.com/@himalee.tailor/working-with-databases-part-1-what-is-postgresql-27db6d72574b">Postgresql database server</a>. If you have the <a href="https://brew.sh/">Homebrew</a> package manager installed, you can run the following in the terminal: brew services start postgresql.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3fd6f7753a37d34d9b9573adc589ff6/href">https://medium.com/media/a3fd6f7753a37d34d9b9573adc589ff6/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66c632e72a2b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Databases Part 2: Using the Postgres Interactive Terminal]]></title>
            <link>https://medium.com/@himalee.tailor/working-with-databases-part-2-using-the-postgres-interactive-terminal-95a5100f0b7b?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/95a5100f0b7b</guid>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Tue, 05 Feb 2019 17:17:40 GMT</pubDate>
            <atom:updated>2019-02-05T17:20:39.418Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to create a database</h4><p>Once you have PostgreSQL installed, you can create new databases by using the command createdb mydb. mydb will be the name of the database. You can delete a database using dropdb mydb. After creating a database, you can start interacting with it using thePostgreSQL interactive terminal program. You can access this by using the psql command followed by the database name. This will allow you to interact with the database by executing SQL commands.</p><p>SQL commands are instructions used to communicate with a database. The Postgres terminal also has internal commands that start with \ e.g. \q to quit, \h for help ,\l to list all databases, \dt to list all tables within a database or\x for expanded display mode.</p><h4>How to create a table</h4><pre>CREATE TABLE employees (<br> work_id int,<br> first_name varchar(80),<br> last_name varchar(80)<br>);</pre><p>This creates a new table called employees with columns work_id, first_name and last_name. Each column must be associated with a data type, varchar(80) is a text data type which means that columns first_name and last_name can store arbitrary character strings up to 80 characters in length. There are also number data types such as int which store digits.</p><p>The different SQL data types can be found in <a href="https://medium.com/@himalee.tailor/working-with-databases-part-1-what-is-postgresql-27db6d72574b">part 1</a> of this working with databases series.</p><p>To remove table, you can use the SQL command DROPTABLE <strong><em>tablename</em></strong>;.</p><h4>How to insert a new record into a table</h4><pre>INSERT INTO employees (work_id, first_name, last_name) <br>VALUES (1234, &quot;Himalee&quot;, &quot;Tailor&quot;);</pre><p>Using the INSERT INTO statement, you are able to add new records, or rows, to your table. You first specify the column names, then the values to be inserted into your table.</p><h4>How to delete a record</h4><pre>DELETE FROM employees <br>WHERE first_name = &quot;Himalee&quot;;</pre><p>The DELETE statement allows you to delete previously saved rows from your database based on a condition, the WHERE clause.</p><h4>How to read from a table</h4><pre><em>#to select all fields from a table<br></em>SELECT * FROM employees;</pre><pre><em>#to select specific fields from a table<br></em>SELECT first_name,<em> last_name</em><br>FROM employees;</pre><p>To query a table, or to select data from a table, you can use the SELECT statement. The data you get back from the database is stored in a result table, called the result-set.</p><h4><strong>How to alter table columns</strong></h4><pre><em>#to add a new column to a table</em><br>ALTER TABLE employees <br>ADD title varchar(200);</pre><pre><em>#to delete a column from a table<br></em>ALTER TABLE employees <br>DROP COLUMN first_name;</pre><p>If you have already created a table but you want to add new columns or delete previously added columns, you can use the ALTER TABLE statement.</p><h4>How to update previously saved rows</h4><pre>UPDATE employees<br>SET first_name = &quot;Ada&quot;, last_name = &quot;LoveLace&quot;<br>WHERE work_id = 1234;</pre><p>If you want to modify an existing record in a table, you can used the UPDATE statement.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95a5100f0b7b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Databases Part 1: What is PostgreSQL?]]></title>
            <link>https://medium.com/@himalee.tailor/working-with-databases-part-1-what-is-postgresql-27db6d72574b?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/27db6d72574b</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Thu, 24 Jan 2019 13:46:31 GMT</pubDate>
            <atom:updated>2019-01-24T13:46:31.483Z</atom:updated>
            <content:encoded><![CDATA[<p>I have recently been working on a project that requires the ability to get information from a user, store it somewhere, and be able to access, update or delete that information. I needed a system, or database, that was able to store this data, also allowing me to interact with it, enter PostgreSQL.</p><h4>What is PostgreSQL?</h4><p>PostgreSQL is a <em>object relational database management system </em>which is a system used for managing data in relations, or tables. Each table consists of a collection of <em>rows</em>. Every row of a table has the same set of named <em>columns</em>, and each column is of a specific data type. Tables are grouped into databases, so you can have multiple tables in one database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHGanu2NglBqUj7W2OlNFA.png" /><figcaption>SQL Data Types</figcaption></figure><p>SQL stands for Structured Query Language, and is the language used for communicating with a database. I will go into this in more detail in the second part of this working with databases series.</p><h4>How does it work?</h4><p>PostgreSQL works using the client/server model. The server, is in this case the database server program called postgres which provides resources or services to a client. The resources or services it provides involves managing the database files, accepting connections to the database and performing database actions on behalf of the clients.</p><p>The client would be the application, in my case the command line application, that users interacts with. The client application has the ability access the database and perform database operations, such as adding new information (rows) to a table, or reading from a table to display the saved information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27db6d72574b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why UX Research Matters]]></title>
            <link>https://medium.com/@himalee.tailor/why-ux-research-matters-78fa417caacf?source=rss-b988df2f3113------2</link>
            <guid isPermaLink="false">https://medium.com/p/78fa417caacf</guid>
            <category><![CDATA[research]]></category>
            <category><![CDATA[ux-research]]></category>
            <category><![CDATA[ux]]></category>
            <dc:creator><![CDATA[Himalee]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 14:38:38 GMT</pubDate>
            <atom:updated>2018-12-11T14:38:38.255Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is UX Research?</h4><p>UX research comes into play during the first stage of the <a href="https://medium.com/@himalee.tailor/my-introduction-to-ux-aff4c70f7a37">design process</a>, the discover stage. This stage is all about gathering as much information as you can in order to understand the true problem. Here are 2 methods you can use to conduct UX research:</p><p><em>Competitive Analysis</em></p><p>A competitive analysis looks into solutions that attempt to solve the same problem you have been presented with. This involves evaluating competition based on specific characteristics or features. For example, a feature inventory is useful when comparing various competitor features, a general summary gives a more detailed description of the characteristics of the product and listing the pros and cons of competitors is effective for weighing up the bad and the good.</p><p><em>User Interviews</em></p><p>Conducting user interviews are a great way of gaining an understanding of peoples behaviours, patterns and feelings. It ensures that the problem defined is not just based on your own experiences with it. The more people you are able to talk to, the more representative your problem will be. The information you gather from interviews should be impartial. To do this, you must ensure your questions are open ended, leading questions should be avoided and you can encourage people to further their answers by asking ‘can you tell me a bit more about that?’.</p><p>It is important during the research phase that you do not try and come up with a solution as this could impact how you conduct your research, which could influence your findings.</p><h4>Why does UX Research Matter?</h4><p>The research phase is important because it may reveal that the problem you were initially presented with is not in fact the true problem. You cannot start to attempt to solve a problem without truly understanding it first. User interviews, for example, uncover peoples true behaviours — what they do and how they use a product. At this point, your users may reveal that there is an underlying issue that is causing the problem, causing you to shift your view of the problem.</p><p>Also, by conducting this research, you spend time now understanding the problem before you start to solve it. This means you don’t waste time building a solution based on the original, potentially inaccurate, problem.</p><p>Conducting UX Research ultimately ensures that you the solution (product, application etc) you are building is as aligned as it can be with the true problem. By understand the true problem, you are able to add further value, purpose and suitability to users with the solution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*dm07r_4MyaN_BR6cWFwghg.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78fa417caacf" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>