<?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 Heindrick Cheung on Medium]]></title>
        <description><![CDATA[Stories by Heindrick Cheung on Medium]]></description>
        <link>https://medium.com/@heindrickcheung?source=rss-9b12033b420d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TCPsZ1EmkUdt6rm6.</url>
            <title>Stories by Heindrick Cheung on Medium</title>
            <link>https://medium.com/@heindrickcheung?source=rss-9b12033b420d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:34:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@heindrickcheung/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[My First Postmortem]]></title>
            <link>https://medium.com/@heindrickcheung/my-first-postmortem-915e033583b1?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/915e033583b1</guid>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Mon, 04 Mar 2019 19:41:47 GMT</pubDate>
            <atom:updated>2019-03-04T19:41:47.534Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>I am an software engineering student at Holberton School of Engineering in San Francisco. This article focuses on writing my first incident report example based on one of the recent webstack debugging encountered, debugged and fixed. Postmortem(incident report) is a tool widely used in the tech industry whenever any internal outage happen. All stages of this investigation is documented thoroughly with written communication requirements.</blockquote><h4>Service unavailability</h4><h4>Incident Report for LAMP stack powered Wordpress site was not loading</h4><h4>1. Issue Summary:<br>On March 3 at 14:45 UTC: Website is unresponsive with a returned response code status 500 when trying to access the site through the browser or CURL command with GET method to IP address. All users internal or external were unable to access the webpage, it was just not loading. At 17:35 UTC, found the root cause. 18:15 UTC, deployed automated fixed using Puppet.</h4><h4>2. Timeline</h4><h4>14:45 UTC: webpage found unresponsive after receiving email regarding this issue.</h4><h4>15:00 UTC: Verified with Chrome browser and CURL commands with GET requests.</h4><h4>The original assumption for root cause was the server down. Checked error.log, access.log, then restarted the server while checking logs again but found no related error codes.</h4><h4>Check server’s configuration files, history changes and found new uploaded PHP contents at 13:08 UTC same day.</h4><h4>15:50 UTC: successfully debugged by using strace command</h4><h4>16:15 UTC: deployed automated fix with Puppet scripty to fix spelling error. One of the PHP file’s extension was spelled “.phpp”.</h4><h4>16:30 UTC: Successfully fixed issue</h4><h4>3. Root cause and resolution:</h4><h4>New PHP files were uploaded 2 hours before the incident and WordPress configuration file was changed to include the new files. Server detected the error because it did not find the file listed in the config. Found resolution by using strace command with -p flag to track the child process(PID) of the Apache2 server when listening to requests while sending curl GET requests on a different terminal. strace returned -1 on missing PHP and HTML files. Determined fixed using a Docker container and deployed the automated fix using Puppet.</h4><h4>4. Corrective and preventative measures:</h4><h4>Going forward, please make sure to double check all filename spelling before deployment.</h4><h4>Test all servers are running properly on container first with no errors.</h4><h4>Send requests to the server to make sure the contents are returned with status code 200 and content is correct.</h4><p>Hope this helps, thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=915e033583b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type something in your browser and hit enter?]]></title>
            <link>https://medium.com/@heindrickcheung/what-happens-when-you-type-something-in-your-browser-and-hit-enter-e049d86e3501?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e049d86e3501</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Mon, 21 Jan 2019 05:58:25 GMT</pubDate>
            <atom:updated>2019-01-21T05:58:25.695Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-js4RWLv7wSJgmBoGCJqQ.png" /></figure><p>Whether you are a developer, engineer or regular internet user, who is curious about how does the internet work and how devices are interconnected, this might help.</p><h3>The Internet:</h3><p>A global network of computers/devices with each connected to the Internet following multiple standard protocols. We will cover a couple of concepts and major protocols to understand how they talk to each other. For example, when you enter a <a href="https://www.webopedia.com/TERM/U/URL.html">URL</a> in your browser, this actually sends an HTTP command to the Web server directing it to fetch and transmit the requested <a href="https://www.webopedia.com/TERM/W/web_page.html">Web page</a> or files.</p><h3>The internet address to IP address(DNS request):</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*DCpSuZyq0VmoNb4hnyzeFQ.jpeg" /></figure><p>Each interconnected device has a unique IP address to communicate with other devices. Internet addresses are in the form <strong>###.###.###.##</strong> where ### must be a number from 0–255. This address is known as an IP address which is retrieved from the DNS(Domain Name System), usually provided by your local ISP. Think of the DNS as database or phonebook full of Internet addresses mapped to IP address and always listening to requests. Since IP address is much more complicated to remember versus “https://www.holbertonschool.com”, DNS will make it easier. The IP address can be thought of a destinations address. For instance, when we need to post a letter, we need the recipient’s address.</p><h3>TCP/IP:</h3><p>Once the browser retrieves the IP address, it will start connecting to the server with matching IP address for GET request a data transfer. In order for devices to communicate with each other without conflict, all devices adhere to the Internet Protocol Suites a combination of TCP/IP, which stands for — Transmission Control Protocol/Internet Protocol.</p><p><strong>Transmission Control Protocol:</strong> TCP directs packets to a specific application on a computer using a port number.</p><p><strong>Application Layer: </strong>IP directs packets to a specific computer using an IP address.</p><h3>HTTP/HTTPS</h3><p>HTTP means Hypertext Transfer Protocol. HTTP is the underlying protocol used by the World Wide Web and this protocol defines how data are formatted and transmitted, and what actions web servers and browsers should take in response to various commands. HTTP is called a <a href="https://www.webopedia.com/TERM/S/stateless.html"><em>stateless</em></a> protocol because each command is executed independently, without any knowledge of the commands that came before it.</p><p>S means secure, so HTTPS is a secured version of HTTP. It means all communication and data are encrypted and mostly used toward examples like creating personal accounts, transmitting credit card information or connecting to an online bank account. HTTPS pages typically use one of two secure protocols to encrypt communications — SSL or TLS. Both the TLS and SSL protocols use Public Key Infrastructure system. This system uses two keys for encryption communications, with a public and a private key. The client should store a copy of the public and private key while a server with a copy of the public key. This way when both user and client is talking, the server will know if a client has the matching public key and authenticate with the private key. Please, never lose your private key, this is me speaking from experience when setting up my dual web servers. Let&#39;s talk about the two different protocols.</p><h4>TLS-Transport Layer Security:</h4><p>The TLS is the successor to SSL and uses stronger encryption algorithms.</p><p>Unlike SSL, TLS has the ability to work on different ports.</p><p>Commonly used as a setting in email programs, like SSL, TLS can have a role in any client-server transactions.</p><h4>SSL-Secure Sockets Layer:</h4><p>Transmits information privately, ensure message integrity and guarantee the server identity.</p><p>Commonly used on web browsers but can be used with email servers or any kind of client-server transaction.</p><p>Some instant messaging servers use SSL to protect conversations.</p><h3>Web Infrastructure:</h3><p>Getting back to requesting a webpage from a server after retrieving the IP address. Most likely before your request reaches where the exact server is located in a network, the request might have to pass through a couple of components first. Let&#39;s cover the basics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dEomO6bMhFX6g6S87l0dTw.jpeg" /></figure><h4>Load Balancer:</h4><p>A load balancer is a device that acts as a reverse proxy and distributes network or application traffic across a number of servers. Think about the traffic lights. Load balancers are used to increase capacity and reliability of applications. They improve the overall performance of applications by decreasing the burden on servers associated with managing and maintaining application and network sessions, as well as by performing application-specific tasks.</p><h4>Web server:</h4><p>A web server or as an internet server is a system that delivers content or services to users over the internet, my website request for contents from <a href="https://www.holbertonschool.com./">https://www.holbertonschool.com.</a> A web server is a combination or a physical server, server operating system and software used to facilitate HTTP communications.</p><h4>Application server:</h4><p>An application server is a mixed framework of software that allows both the creation of web applications and a server environment to run them. They are designed to install, operate and host applications while facilitating the hosting and delivery of consumer or business applications, locally or remotely.</p><h4>Database:</h4><p>A database management system is usually located in a separate database server for storing an organized collection of data. It is primarily used as a method of storing, managing and retrieving information.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e049d86e3501" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Recursion and Stack]]></title>
            <link>https://medium.com/@heindrickcheung/recursion-and-stack-d0c6c47aa393?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0c6c47aa393</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Mon, 24 Dec 2018 01:37:02 GMT</pubDate>
            <atom:updated>2018-12-24T01:37:02.283Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yweiFhzv6QXWRM-7RqlkBw.gif" /><figcaption>www.penjee.com</figcaption></figure><p>This article will introduce basic concepts of stack and recursion and what is happening behind the scene to solve this interesting algorithm below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuFdz-1tvoW52iMNNLcm0w.png" /></figure><p>Before diving into what is happening let’s cover two concepts starting with….</p><h3>Stack</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*L4DWVi8mAYOmv30TrBpWbg.gif" /></figure><p>A stack is a conceptual structure consisting of a set of homogeneous elements and is based on the principle of last in first out (LIFO) or first in last out (FILO). It is a commonly used abstract data type with two major operations, namely push and pop. Push and pop are carried out on the topmost element, which is the item most recently added to the stack. The push operation adds an element to the stack while the pop operation removes an element from the top position. The stack concept is used in programming and memory organization in computers.</p><h3>Recursion</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*yweiFhzv6QXWRM-7RqlkBw.gif" /></figure><p>The best way to explain it is that a recursive function is a function which should return either:</p><p><em>- A ‘base case’ value</em></p><p><em>- The result of a call to itself (could be multiple calls to itself also)</em></p><p>When you calling a recursive function, unless it hits the base case , it will keep calling itself (often with slightly different arguments each time) until it returns the base case.</p><p>Once the function returns the base case, the recursion will start to unwinding. In the unwind phase, the return values of the previous recursive calls to do more interesting stuff.</p><p>The best way to visualize recursion is to imagine that you have a stack of function calls with each time a function calls itself, it creates another copy of itself with new arguments and puts that copy on top of the stack. Usually there is a designated pointer to where each call is at. The program pointer moves to the copy (but it keeps a reference of were it was in the previous call). And it keeps building up the stack with new copies of the function until it reaches the base case (when the function finally returns its value).</p><p>The ‘unwinding’ phase is just when the functions start returning (after one of the base case(s) has been reached) and all the function ‘copies’ just get popped off from the top of the stack one by one following FILO/LIFO. Each time the program will continue running from wherever it was in each call stack.</p><p>Alright lets go back to the algorithm:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuFdz-1tvoW52iMNNLcm0w.png" /></figure><p>The algorithm is simple implementation of following recurrence relation used to calculate ‘x’ to the power ‘y’ where ‘x’ and ‘y’ are integers.</p><p>Lets say the generated recursion input value is implemented with recusion(2,5).</p><blockquote>x = 2 and y = 5 and below is what I simulated with my computer to display value of y with each successive function call.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QfmHFaf-x2JrCf7w-l_LFQ.png" /></figure><p>The algorithm, recursion(2,2,), recursion(2,1) are being computed multiple times. To avoid the same computations, we store the result in a temporary variable while making the recursive call and use this variable value repeatedly in order.</p><p>Each function call will be pushed on the stack mainframe following first in first out(FILO) order with each time y will be subtracted by 1. Once y is equal to 0, return (1) or if stack is full (y = -1) and unload the functions starting from top and multiplying the return value with x until return back to main function. The final value is 32 = 2 * 2 * 2 * 2 * 2 = 2 ^ 5.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0c6c47aa393" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Internet of Things(IoT)]]></title>
            <link>https://medium.com/@heindrickcheung/the-internet-of-things-iot-9afc641d07f1?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9afc641d07f1</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Sat, 24 Nov 2018 00:20:55 GMT</pubDate>
            <atom:updated>2018-11-24T00:20:55.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*ezCWQi35gnCBpxZxx0mucg.png" /></figure><blockquote>The Internet of Things definition: “Sensors and actuators embedded in physical objects are linked through wired and wireless networks”</blockquote><h4>What is IoT and how does it work?</h4><p>The “things” in Internet of Things are everyday objects/machines in your living space with the capability of connecting to the internet. In essence, the Internet of Things is one huge cloud. The picture above displays some of the most common types of IoT devices. Traditionally, common connected home things is computers, laptops, tablets, smartphone, streaming boxes, television sets because they all have the same common components: processor; memory/ram; network card(NIC); software. What we are doing is integrating those basic computer components into your everyday machines while adding internet for self evolvement and update. IoT is all about improving smarter connected objects with a purpose to evolve. By allowing these machines to co-exist within your home, they can interconnect with each other and automate your daily needs, receive assistants from a super AI brain through Cloud, so that way you can focus on other important things.</p><p>Think of a thermostat that can be controlled from a smartphone/tablet app or over the web on computer, anywhere. You can control automated features like, preheating, your temperature ranges, auto turn on/off, who is at home and which range to choose. Maybe that home thermostat can connect to your shower thermostat and also set your prefer shower temperature settings</p><p>I am a coffee drinker, it is the first daily consumption when starting the day. To save money, I mostly brew coffee at home which require either waking up earlier or prepping the night before. I have a machine(thing) to grind coffee beans, another to brew the coffee, but both process requires manually inputted settings. I usually wait by them to make sure both process is finish because occasionally I will fall back to sleep. But if they are internet connected, they can be controlled from an app on your smartphone to auto grind or brew on x amount of cups, alert when done, auto on and off, what to do when waking up, what to do when within preset time range and senses your at home, auto software updates for new features. The possibilities is endless since devices with internet capabilities will have a NIC(network internet controller), memory, a low powered processor which mean they can be preprogrammed with software update capabilities. What if both my machines is from the same brand? Chances are they can connect, collaborate and update each other. Though the tiny chip in that coffeemaker is dumb as a rock, it’s as smart as any supercomputer, allowing it to do its thinking other than in its own brain, through Cloud.</p><p>More advanced examples that you may end up seeing in your household within the next couple of years are fridges that remind you to reload eggs when you’re out or expired, possibly by scanning the <a href="http://www.technovelgy.com/ct/technology-article.asp">RFID chips</a> in products. Another example is garage doors that can open when it detects your vehicle’s GPS location is nearby or from the inside, if your smart car can signal to open from inside once your car starts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*hviEgdjySH-y7-q429oayw.png" /></figure><p>Some other well-known examples for Internet of Things applications today are:</p><blockquote><strong>Wearable devices/fitness trackers</strong> (e.g., Jawbone Up, Fitbit, Pebble)</blockquote><blockquote><strong>Home Automation</strong> (Examples: Nest, 4Control, Lifx)</blockquote><blockquote><strong>Industrial asset monitoring</strong> (GE, AGT Intl.)</blockquote><blockquote><strong>Smart energy meters</strong></blockquote><h4>Birth of IoT</h4><p>The term Internet of Things is about 20 years old. But the actual idea of connected devices had been around much longer, at least since the 70s. Back then, the idea was often called “embedded internet” or “pervasive computing”. But the actual term “Internet of Things” was coined by Kevin Ashton in 1999 during his work at Procter &amp; Gamble. He was working in supply chain optimization and wanted to attract senior management’s attention to a new exciting technology called RFID. Because the internet was the hottest new trend in 1999 and it somehow made sense, so he called his presentation “Internet of Things”.</p><p>The first considered IoT device was a toaster created by John Romkey that could be turned on and off over the internet for the October ’89 INTEROP conference. The device was connected to a computer with TCP/IP networking. It then used an information base(SNMP MIB) to turn the power on. Even though it was a very simple feature, today’s modern toasters still do not have this feature. This was meant to showcase what was possible with upcoming connected devices. Keep in mind the first web page was created in 1991.</p><h4>The Rise of Robots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*tkhIp66quF6w2AUY7Baszw.jpeg" /></figure><p>The concept of IoT started gaining popularity during the summer of 2010 when Google’s StreetView service had not only made 360 degree pictures but had also stored tons of data of people’s Wifi networks. People started wondering and debated whether this was the start of a new Google strategy to not only index the internet but also index the physical world.</p><p>That same year, the Chinese government announced a Five-Year-Plan to make the Internet of Things a strategic priority.</p><p>In 2012, the theme of Europe’s biggest internet conference <a href="https://thenextweb.com/event/leweb/">LeWeb</a> was the “Internet of Things” and at the same time majority of tech-focused magazines started using IoT as their vocabulary.</p><p>In October of 2013, IDC published a report stating that the Internet of Things would be a $8.9 trillion market in 2020.</p><p>In 2014, Google purchased Nest for $3.2 billion, a manufacturer of smart home thermostats while one of the biggest tech expo, Consumer Electronics Show(CES) in Las Vegas was held under the theme of IoT.</p><h4>The Rise of Robots in manufacturing industry</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zKfXeiW2q-w1O1NfB_ELw.jpeg" /></figure><p>Preprogram robots to perform specific tasks is more efficient with less error, so they are replacing humans in the manufacturing industry. Since machines started talking to each other directly than through humans has brought about a serious increase in production across the board. Because of that some factories basically can run themselves with little to no guidance and with machines telling each other what they need and when.</p><p>They don’t need a salary, health insurance, union, food but electricity and can continue churning out consistent products non stop except for maintenance. Because of this, it’s been positively great for the business owners to offer products at a lower costs. <a href="https://www.theguardian.com/books/2015/oct/01/the-rise-of-robots-humans-need-not-apply-review">The rise of robots</a> will influence the labor market very strongly over the next few decades.</p><h4>What technologies in IoT?</h4><p>Whenever talking about IoT, couple of technologies serves as the backbone. IoT primarily exploits standard protocols and networking technologies. Below is a couple of the most important ones:</p><blockquote><strong>RFID</strong> is a radio-frequency identification system that uses tags, or labels attached to the objects to be identified. Two- way radio transmitters-receivers called interrogators or readers send a signal to the tag and read its response. The readers generally is included to transmit their observations to a computer system by running RFID software or RFID middleware.</blockquote><blockquote><strong>NFC</strong> consists of communication protocols for electronic devices, typically a mobile device and a standard device. Similar applications uses for example is when paying for items at a retailer by placing your phone or what smartwatch next to the payment machine.</blockquote><blockquote><strong>Low-Energy Bluetooth </strong>supports the low power, long-use need of IoT function while exploiting a standard technology with native support across systems</blockquote><blockquote><strong>Radio Protocols</strong> for creating low-rate private area networks. These technologies are low-power, but offer high throughput unlike many similar options. This increases the power of small local device networks without the typical costs.</blockquote><blockquote><strong>LTE-A(Advanced)</strong> gives IoT tremendous power through expanding its range through 4g wireless technology, same as in your smartphone cellular network. Example for IoT with LTE-A is self driving vehicles and UAV.</blockquote><blockquote><strong>WiFi-Direct</strong> eliminates the need for an access point and allows P2P(peer-to-peer) connections with the speed of WiFi, but with lower latency. Wifi-Direct eliminates an element of a network that often bogs it down, and it does not compromise on speed or throughput.</blockquote><h4>How smart are they?</h4><p>An IoT brain can decide what it needs to know and what it doesn’t. This process is often guided by human programmers, but more and more devices is deep learning. Instead of individually programming any new IoT machines. Most companies is applying Machine Learning through cloud which is a type of artificial intelligence that can learn from its data fed environment and attach consequences to its choices in a limited manner. One important thing to mention is our chip industry is still keeping up with Moore’s Laws, processor speed will double every 18 months. Which means, they are getting smaller, more power efficient while faster. Meaning, we can pack more transistors which equate to more power with same amount of physical space or lower energy usage.</p><h4>Securities &amp; Concerns</h4><p>One drawback to applying machine learning as the source of smart machines is they require massive amount of data to work or make smart choices. Currently most data privacy concern is about our phones, tablets and computers only. Imagine a house surrounded by machine(things) co-existing with each other and your family without knowing what data they are all collecting. If you watched “Terminator” series when growing up, the main event in the movie is a tone down version of our reality.</p><p>By letting an IoT device in your home, you are basically allowing a bot, that can gather data from other digital devices, maybe even listen and observe you. Certain IoT supporters have touted data gathering as a major plus to the Internet of Things for marketers, improving your habits by knowing and easier to target ads at you.</p><p>Bottom line is we all want to keep certain things private and it’s going to easier to find by having having all our data floating around.</p><h4>Final Thoughts</h4><p>I think overall IoT will change our lives for the better. Even with changing labor landscape in manufacturing, new generation of workers will have to adapt to learn how to communicate with machines by receiving higher form of education, programming. We also need to have set laws governing what features, capabilities is allow to exist in consumer products. We also need more public transparency with data collection and what will happen to it. Besides that, I am very excited to be a Star Trek style living headquarters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9afc641d07f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lite Machine Learning Introduction]]></title>
            <link>https://medium.com/@heindrickcheung/lite-machine-learning-introduction-391650965568?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/391650965568</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Thu, 25 Oct 2018 05:34:53 GMT</pubDate>
            <atom:updated>2018-10-25T05:34:53.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*mEq-Ab_H8maHLEx48D6N0Q.jpeg" /></figure><blockquote><a href="https://news.sophos.com/en-us/2017/07/24/5-questions-to-ask-about-machine-learning/">https://news.sophos.com/en-us/2017/07/24/5-questions-to-ask-about-machine-learning/</a></blockquote><p>Machine learning is a field of artificial intelligence with near unlimited ability to automatically learn and improve from experience without being explicitly programmed using primarily statistical and other math techniques. Machine learning is a focus on development of computer programs that can access, learn/analyze data for users and itself. Its official, our world is connected to super smart AI bots(machine learners) hidden behind the digital wall absorbing insane amount of data to analyze while providing recommendations to improve our daily lives. The primary aim is to allow computer bots to automatically learn without human assistants and adjust accordingly. Sometimes even deleting an old copy of itself to create a combination of multiple bots into one smarter bot. Machine learning explores the study of construction of algorithms that can learn and make data driven predictions and decisions. All levels of society, all cultures, techies or not, newborn to senior, every country is using some form of machine learning. Have you ever watched an online video and for some reason the next set of recommend videos was automatically curated? How come certain emails is in the spam folder? Why does the news reporter always have the weather report ready for the next couple of days? How does Tesla cars drive on its own without crashing? These are just some of the examples of why companies and governments collect so much of our data. The more data it receives, the smarter it becomes and the more machine learning can enrich our lives. With that said, this article is a gentle introductory to machine learning to give you an easy abstract understanding of what machine learning is all about.</p><h3>Origin:</h3><p>Arthur Samuel was an American pioneer in the the field of computer gaming and artificial intelligence. He wrote the first computer program capable of learning and demonstrated the power of AI with fundamental concepts by developing the Checkers-play Program which was one of the first self-learning program. In 1959, he coined the term “machine learning”.</p><p><a href="https://en.wikipedia.org/wiki/Arthur_Samuel">Arthur Samuel</a></p><h3>The Two Primary techniques of Machine Learning computational statistics</h3><blockquote>Correlation — a measure of association between two variables neither designated as dependent or independent.</blockquote><blockquote>Regression — a examined relationship between a single designated dependent variable to another independent variable. Because one independent variable is known, regression can predict capabilities.</blockquote><h3>The five broad methods of Machine Learing classifications:</h3><blockquote><strong>Supervised Learning</strong> — The computer is presented with example input and desired outputs given by the “teacher” to learn a general rule that can map input to output. The learning algorithm produces a function to make predictions about the output values and is capable of comparing output values with intended values.</blockquote><blockquote><strong>Semi-supervised Learning</strong> — The computer is given typically small amounts of labeled and large amount of unlabeled data and with a-lot of target outputs missing. Systems that use this method are able to improve learning accuracy.</blockquote><blockquote><strong>Active Learning</strong> — The computer can only obtain training labels for a limited set of instances while requiring to optimize its choice for objects to acquire labels for data.</blockquote><blockquote><strong>Unsupervised learning</strong> — The computer receives no labels for the learning algorithm, leaving it on its own to find hidden structure in its own input without finding the correct output. Unsupervised learning is very popular currently since it’s goals can be discovering hidden pattern or feature learning.</blockquote><blockquote><strong>Reinforcement Learning</strong> — A learning method that can interact dynamically with its environment while producing actions and discovering errors for rewards. Data are given as feedback to the program’s actions in a dynamic environment. Think Tesla’s self driving cars or NPC AIs in video games. Data is in form of rewards and punishments.</blockquote><h3>Common learning algorithms and keypoints:</h3><blockquote>Machine Learning is still infancy and continuously evolving.</blockquote><h4>Linear Regression: Supervised</h4><p>This learning algorithm focuses on finding a line by assigning optimal weights to variables in order to create a line(ax + b) that will predict output. The regression line can be negative or positive relation mapped with data points on 2-d plane with x, y axis representing dependent or independent variables which leads to the result of the slope of line. Based on data point inputs this will try to find a straight or curve line with minimal errors and predicts an outcome based on continuous features. This is very versatile with the ability to run on a single variable and can be single or multiple linear regression with independent variables(x) that we change or adjust to dependent variable(y) is the outcome</p><h4>Logistic Regression — Supervised</h4><p>This is a generalized linear model(GLM) for response variables where regular multiple regression does not work well but useful for estimating discrete values or modeling probability of an event such as email spam filters. The outcome value is binary, modeled on an x, y axis with maximum value between 0 and 1 probability. Logistic Regression model is very common in neural networks and spam emails.</p><p><strong><em>Two key conditions for successfully building a logistic regression model</em></strong></p><blockquote>Model relating the parameters to the values of the predictors must closely resemble the true relationship between the parameter and the predictors</blockquote><blockquote>Outcome for each case must be independent of the other outcomes for other cases</blockquote><h4>Decision Trees — Supervised, Regression</h4><p>This is probably the most interesting from my perspective. This model takes in an instance then divide and conquer by extracting attributes to micmic a tree starting from branch to leaves. If your not sure about what trees are in programming, a link is provided below for those interested. A tree represent attributes of the instance/object and each branch represent one significant feature/category/attribute. The broader the feature, the closer to the root. Each branch can span out into more branches for subsets until finally the leaves which returns a simple classification. Some cool predicting techniques include random forests, boosting and bagging.</p><h4>Support Vector Machines— Supervised</h4><p>Let say you have two types of data categories separated left and right. In between them, you want to find the dividing line furthest away from both variables. The closest point in each of the groups will be farthest away from each other while there is a dividing line between the differing groups of data. The purpose of this learing algorithm is to optimize line so that the closest point in each group of data will be the furthest away from each other. Finally vectors can be visually linear or nonlinear base on kernel type; “<em>guassian”</em> or “<em>linear</em>”</p><h4>K-Nearest Neighbors— Supervised</h4><p>Unlike SVM which searches for a line furthest away from the related classification, KNN searches for the closest point to variables in between data types by…Comparing distance using some sort of function(usually <strong>Euclidean</strong>) then analyze those results and assigns individual points to the data group so that it is optimized to be placed with all the closest groups to it. Function will include a parameter for the count of closest neighbor points to search for.</p><h4>Random Forests- Supervised/Regression Ensemble</h4><blockquote>“Ensemble learning algorithm takes an army of simple workers to form one smart worker by following the divide and conquer approach”</blockquote><p>I want to go a little more detail with this one because learning algorithm applies to so much technology. In Random Forest, each worker is a decision <strong>tree</strong> and when combined together will form a random <strong>forest</strong>(strong/smart predictor). Because of this, numbers really matter, with more trees equates to more robust forests(predictor) and increase accuracy. Final prediction is an aggregation of trees by <strong>majority vote</strong> of <strong>classification</strong> and total average votes for <strong>regression</strong>. This is great to handle missing values and maintains accuracy for missing data. This machine learning algorithm can also handle larger datasets which is good for <strong>classification</strong> but not as good for <strong>regression</strong>. Due to the nature of this, you have very little control on what each model does.</p><h4>Two awesome ensemble learning algorithms feature in Random Forests:</h4><blockquote>Bagging — Improve the stability, reduce variance and accuracy</blockquote><blockquote>Boosting — Reducing bias, and also variance in supervised learning</blockquote><p>Some of the common applications using this includes banking, medicine identifying, disease and medical records, stock behaviors and market predictions, e-commerce with recommendation engines, image classification, voice classification</p><h4>Here is a quick simple pseudo code since this is so common:</h4><blockquote>Assume number of cases in the training set is N. Then take a random sample of N cases but with replacements.</blockquote><blockquote>If there are M input variables or features, a number m&lt;M is specified such that each node, m variables are selected at random out of the M. The best split on theses m is used to split the node. The value of m is held constant while we grow the forest.</blockquote><blockquote>Each tree is grown to the largest extent possible and there is no pruning.</blockquote><h4>K-Means Clustering — Unsupervised</h4><p>This learning algorithm is commonly used to address clustering problems, used when you have unlabeled data and is very fast. The goal of this algorithm is to find groups in the data, with the groups represeted by the variable ’K’, which refers to user inputted number of clusters. This algorithm works iteratively to assign each data poit to one of K groups based on features provided. All data points are then clusters based on feature similiarity and finally the results(covergence) of K-means clustering are:</p><blockquote>1. The centroids of the <em>K</em> clusters, which can be used to label new data</blockquote><blockquote>2. Labels for the training data (each data point is assigned to a single cluster)</blockquote><h4>Principal Components Analysis — Unsupervised</h4><p>Principal components analysis is mostly used for exploratory data analysis and predictive models. Specifically, often used to visualize genetic distance, strong patterns and relatedness between populations. It is capable of finding directions of maximal variances of data on a 2-d plane or higher that is orthogonal to convert a set of correlated variables into a set of values of linearly uncorrelated variables(principle components).</p><h4>Deep Learning</h4><p>This is probably the hottest topic in machine learning because it is smart enough to beat humans in some cognitive task. It was with using this algorithm approach that a program beat the top chess player in the world while dominating top video game players after training it by inputting data and rules for a very short amount of time. Not months or days, we’re talking just a couple of hours. Of all the algorithms, deep learning is the most similiar to how humans learn and process information. It is inspired by how we process sight and sound with our biological network but is capable of absorbing a-lot more data. Deep learning can be either supervised and serve to classify data, or unsupervised and perform pattern analysis.</p><h3>Programming Languages:</h3><p><strong>Python:</strong> most popular programming language for machine learning because of its easy syntax readability, great library support and deep learning proven frameworks. Python is very powerful for preprocessing data and work with data directly.</p><p><strong>Java:</strong> Prefer machine learning language for enterprise level, mobile and front end. Very popular use case for networking security including cyber attack, fraud detection.</p><p><strong>R: </strong>This language is popular with statistical computing focusing on creating predictive models, randomForest for classification and regression.</p><p><strong>C++:</strong> Language of choice for AI and machine learning in games, robotic applications, embedded hardwares and electronics engineers.</p><h3>What I personally think about Machine Learning:</h3><p>Personally, I am very excited with the rapid development on these machine learning algorithms and bots. I think machine learning will become increasingly valuable and as this technology matures, more businesses will start using the cloud to offer this as a service. I think this technology will also be so easy and common to use that wider smaller organizations will be able to take advantage without making large hardware investments or training their own algorithms. I think machine learners itself will build new machine learners with data inputted or related to the requested organization. Our lives will be fully automated and what we saw in futuristic movies about 10 years ago is becoming a reality. Some might be scared to think they might take over the world, but me as a software engineer, exciting….</p><p>This is a fun little video about how machines learn:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FR9OHn5ZF4Uo%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DR9OHn5ZF4Uo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FR9OHn5ZF4Uo%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/db4a18c4f6fde1af2ffd33656a352f59/href">https://medium.com/media/db4a18c4f6fde1af2ffd33656a352f59/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=391650965568" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python3: Mutable, Immutable… everything is object!]]></title>
            <link>https://medium.com/@heindrickcheung/python3-mutable-immutable-everything-is-object-cfdc52c7fe0c?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfdc52c7fe0c</guid>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Wed, 10 Oct 2018 05:02:40 GMT</pubDate>
            <atom:updated>2018-10-10T05:02:40.281Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3GmUh7dqAMJLM5KwGBKYQ.png" /></figure><blockquote><strong>Object</strong>-<strong>oriented programming</strong> (<strong>OOP</strong>) is a <strong>programming</strong> language model organized around <strong>objects</strong> rather than “actions” and data rather than logic</blockquote><p>Almost everything in Python is objects. Understanding this concept is highly important if you want to learn this language. All objects are mutable or immutable. An object is a block of memory with its properties and methods. A declared variable points or refer to that block of memory by storing the address of the object.</p><pre>&gt;&gt;&gt; varName1 = 100<br>&gt;&gt;&gt; varName2 = &quot;I am string data&quot;<br>&gt;&gt;&gt; print(varName1)<br>100<br>&gt;&gt;&gt; print(varName2)<br>I am string data</pre><p>Each object have its own ID(identity) which is the address in memory and a type. varName2 from above is a string type object and varName1 is a integer type. Objects can hold references to other objects. Python builtin function id() returns the object’s id and type() returns object types:</p><pre>&gt;&gt;&gt; type(varName1)<br>&lt;class &#39;int&#39;&gt;<br>&gt;&gt;&gt; id(varName1)<br>10091456<br># id number may vary</pre><pre>&gt;&gt;&gt; type(varName2)<br>&lt;class &#39;str&#39;&gt;<br>&gt;&gt;&gt; id(varName2)<br>139851909742256<br># id number may vary</pre><p>Using is and is not operator can evaluate whether or not the objects have the same identity, not the same value.</p><h3>Mutable/Immutable Objects plus how are they treated differently:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*mlY6TNtXby36WGuMVPLp6w.png" /></figure><p>Looking at the example above, depending on which type of object when created will determine if it is mutable or immutable.</p><h4>Mutable Objects:</h4><p>These types of objects can be altered directly when created. Their ID will stay the same when content is added, deleted or changed. Lets create a list object and use the id() before and after adding an element to the list.</p><pre>&gt;&gt;&gt; list_var = [&#39;Heindrick&#39;, &#39;software&#39;, &#39;engineer&#39;]<br>&gt;&gt;&gt; id(list_var)<br>139851909741896<br>&gt;&gt;&gt; list_var.append(&#39;hire me&#39;)<br>&gt;&gt;&gt; list_var<br>[&#39;Heindrick&#39;, &#39;software&#39;, &#39;engineer&#39;, &#39;hire me&#39;]<br>&gt;&gt;&gt; id(list_var)<br>139851909741896</pre><pre>&gt;&gt;&gt; list_var2 = list_var<br>&gt;&gt;&gt; id(list_var2)<br>139851909741896</pre><p>Notice ID from above example is the same before and after appending a new element to list_var. Also list_var2 is the same ID as list_var. Why is that? Because both variables is pointing to the same object that is list type and mutable.</p><h4>Mutable Objects in Functions:</h4><p>Earlier, we saw that if you have two mutable objects with same ID it means they are the same object. If one is change, so is the other. This also applies to functions that take mutable objects as arguments which are passed by reference. Example below consist of a function that takes a list as argument, divides all of its element by 2 and return the average.</p><pre><strong>def</strong> divide_and_average(var):<br>    <strong>for</strong> i <strong>in</strong> range(len(var)):<br>        var[i] /= 2<br>    avg = sum(var)/len(var)<br>    <strong>return</strong> avg</pre><p>Okay, lets call this function</p><pre>my_list = [1, 2, 3]<br><strong>print</strong>(divide_and_average(my_list))<br><strong>print</strong>(my_list)</pre><p>And the output is….</p><pre>1.0<br>[0.5, 1.0, 1.5]</pre><p>When executing this function, the values of my_list is changed <em>in-place </em>while returning a different element. One solution to not altering my_list is to create a local object and a shallow copy of the list.</p><h4>Immutable Objects:</h4><p>These types of objects is the exact opposite. They cannot be changed after initialization and assignment. They will allocate new memory whenever their value is changed. Lets use string objects as an example since they are immutable(cannot change). Lets see another example. I will create a string and try to change one of the character. An error will raise.</p><pre>&gt;&gt;&gt; string = &quot;Heindrick&quot;<br>&gt;&gt;&gt; string[4]<br>&#39;d&#39;<br>&gt;&gt;&gt; string[4] = &#39;D&#39;<br>Traceback (most recent call last):<br>  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>TypeError: &#39;str&#39; object does not support item assignment</pre><p>Important: Even though tuple objects is immutable, what they hold might be mutable. Below is a great example for mutable lists and immutable tuples.</p><pre>&gt;&gt;&gt; tuple = (1, 2, 3, [&#39;four&#39;, &#39;five&#39;])<br>&gt;&gt;&gt; tuple[0] = &#39;ONE&#39;<br>Traceback (most recent call last):<br>  ...<br>TypeError: &#39;tuple&#39; object does not support item assignment</pre><pre>&gt;&gt;&gt; tuple.append(&#39;six&#39;)<br>Traceback (most recent call last):<br>  ...<br>AttributeError: &#39;tuple&#39; object has no attribute &#39;append&#39;</pre><pre>&gt;&gt;&gt; tuple[2].append(&#39;six&#39;)<br>&gt;&gt;&gt; tuple<br>(1, 2, 3, [&#39;four&#39;, &#39;five&#39;, &#39;six&#39;])</pre><p>Since tuple[2] is a list object, which is mutable.</p><h4>Immutable Objects in Functions:</h4><p>Python immutable objects are also passed by reference like mutable object. Due to state of immutable objects if an integer or string value is changed inside the function block then it will behaves like an object copying. A new local copy of the caller object inside the function block scope is created and manipulated. The caller object will remain unchanged. Caller block won’t notice changes made inside the function block scope to the immutable object. Let’s take a look at the following example</p><pre>def foo1(a):<br>a += 1<br>print(&#39;id of a:&#39;, id(a))<em><br></em>return a</pre><pre># main or caller block<br>x = 10<br>y = foo1(x)</pre><pre><em># value of x is unchanged<br></em>print(&#39;x:&#39;, x)</pre><pre><em># value of y is the return value of the function foo1</em></pre><pre><em># after adding 1 to argument &#39;a&#39; which is actual variable &#39;x&#39;<br></em>print(&#39;y:&#39;, y)<br>print(&#39;id of x:&#39;, id(x))    <em># id of x<br></em>print(&#39;id of y:&#39;, id(y))    <em># id of y, different from x</em></pre><pre>Result:<br>id of a: 1456621360<br>x: 10<br>y: 11<br>id of x: 1456621344<br>id of y: 1456621360</pre><h3><a href="https://www.pythonforthelab.com/blog/mutable-and-immutable-objects/#id6">Conclusions</a></h3><p>Understanding the differences between mutable and immutable types in Python is very important. What if you are developing complex applications and contemplating if you should exchange tuples for lists, or may even be altering the value of a variable inside a function without realizing it and without great consequences. What if you are weeks into a project and found bugs simply by not fully understanding how Python handle objects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfdc52c7fe0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C Static and Dynamic Libraries]]></title>
            <link>https://medium.com/@heindrickcheung/c-static-and-dynamic-libraries-7e00244e678f?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e00244e678f</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Mon, 17 Sep 2018 23:22:26 GMT</pubDate>
            <atom:updated>2018-09-17T23:22:26.000Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*chcbY6p00JNujkEBGhnjFg.jpeg" /></figure><p><strong>What is a library in C?</strong></p><p>The concept of a regular real world library and a C library is the same. Instead of books, C library store a group of functions and declarations, exposed for use by other programs. As an engineering student, I created most of the standard string and operation functions to fully understand each method. Now that the projects are getting bigger, instead of wasting time to rewrite same operations over and over again, now I understand the benefits of accessing functions in libraries to perform operations. That way my valuable development time can be more focus into overall development of my program. In programming, a lot of the same operations is require over and over again. C standard libraries provides macros, type definitions and functions for tasks such as string handling, mathematical computations, input/output processing, memory management and other operating services. But what if you want to create your own library holding all of your own functions and declarations? This article can help and show you the basics but you have to learn the two types of C libraries, each with its own pros and cons. I will break down each type in detail below starting with…</p><p><strong>Static</strong> <strong>Libraries</strong> is compiled and included with your C file, making copy of all library functions to the executable files. Static linking will created larger binary files and need more space on disk and main memory. If you change any code on your program or library, you will need to recompile since everything is packaged together. All static libraries have extension of (.a) in Linux.</p><p><strong>How to create a Static Library(Linux only)?</strong></p><p><strong>1</strong>. Create object files using -c flag from all C files with the command, you can replace filename with the wildcard (*) for all the same file type:</p><pre>gcc -Wall -c *.c</pre><p><strong>2</strong>. Create static library from all your object files(.o) using ar command. Both static or dynamic libraries have a suffix (lib) before the library name and end with (.a) extension:</p><pre>ar rcs libname.a filenames.o</pre><p><strong>Dynamic</strong> <strong>Libraries</strong> is dynamically linked at runtime or dynamically loaded/unloaded and linked during execution. Since the libraries is not compile together with your main program and instead linked symbolically, overall program size is much smaller. Benefit of this modular approach, you don’t have to recompile your program when changing source code. All dynamic libraries have extension of (.so) in Linux.</p><p><strong>How to create a Dynamic Library(Linux only)?</strong></p><ol><li>Create object code:</li></ol><pre>gcc -Wall -fPIC -c *.c</pre><p>2. Create Dynamic Library:</p><pre>gcc -shared -Wl,-soname,libctest.so.1 -o libctest.so.1.0 *.o</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e00244e678f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Libraries in C]]></title>
            <link>https://medium.com/@heindrickcheung/static-libraries-in-c-800f913acdd3?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/800f913acdd3</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[c-language]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Sun, 15 Jul 2018 23:27:40 GMT</pubDate>
            <atom:updated>2018-07-15T23:27:40.432Z</atom:updated>
            <content:encoded><![CDATA[<p>Current <em>Full Stack software engineering</em> student at <strong>Holberton</strong> <strong>School</strong> in San Francisco specializing on low-level programming, web front-end, back-end, scripting, databases, mobile development, internet of things, artificial intelligence, reverse engineering, security.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*322H6qzaFkZ1Da-hbx86Wg.jpeg" /></figure><p>Ever wonder if there is a shorter more efficient way to implement the same functions and declarations in your programs? Won’t it be wonderful to have access to libraries full of functions, macros and type definitions to handle important tasks such as input/ouput, string handling, string manipulation, mathematical computations, memory management and more. Some functions are relatively simple enough to write but doing so every time they are needed is cumbersome. The C standard libraries provide all of these and can be called anytime with your program. Each library is group together to focus on specific type of task but standard libraries does not cover every task needed, luckily you can create your own customize library. To do that you will need to understand the two types of libraries, static library and shared(dynamic) library. In this article, we will focus only on static library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_NHoiu5lEq2pWR_qhx__qQ.jpeg" /></figure><h4><strong>So what is a Static library??</strong></h4><p>Unlike standard libraries which are shared type with only one copy, all object files from the static library is linked directly into your executable. Why static? Because the library will remain the same unless recompiled even when the developer make changes to the main program. Simply put, a collection of object files combined with another object to form a final executable. Static libraries names have the prefix <strong>lib</strong> and the suffix <strong>.a </strong>— for example, <strong>libname.a</strong></p><h4><strong>Creating a Static Library</strong></h4><ol><li>Use <strong>GCC</strong> to compile our library code into object files including <strong>-c</strong> flag. <strong>*</strong> meaning wildcard or all files with .c extension.</li></ol><p><strong>$ gcc -c *.c</strong></p><p>You can select each file individually.</p><p><strong>$ gcc -c file1.c file2.c file3.c ……</strong></p><p>Command above will convert .c files selected into object files. After conversion, we can use the <strong>GNU ar</strong> command to <strong>archive </strong>(combine) into a<strong> </strong>static library.</p><p>2. Similiar to zipping files, the <strong>archiver</strong> <strong>(ar)</strong> is a <strong>Unix</strong> utility that maintains groups of files as a single <strong>archive</strong> file and is the main tool used to create static libraries, modify object files and list names of object files in it.</p><p><strong>$ ar -rc libname.a *.o</strong></p><p>The command above will <strong>archive</strong> all object files in current directory and create a static library names ‘libname.a’. The ‘<strong>c</strong>’ flag tells <strong>ar</strong> to create the library if it doesn’t exist. The ‘<strong>r</strong>’ flag tells <strong>ar</strong> to replace older object files with newer ones if found existing.</p><p>To list all object files inside this newly created library you can use the command..</p><p><strong>$ ar -t libname.a</strong></p><p>3. After <strong>archive</strong> is created you need to index it which will add symbols inside the library to speed up symbol-lookup by the compiler. <a href="https://medium.com/@hendrickcheung/what-happens-when-you-type-gcc-main-c-bea98ba4a869">(Click this to read my other article on compilation process in C)</a></p><p><strong>$ ranlib libname.a</strong></p><p>The command <strong>ranlib</strong> above will initiate indexing the <strong>archive file </strong>or library libname.a with symbols.</p><p><em>Note: if the archive file’s index generation is older than the file’s last modification date use ‘ranlib’ again to re-generate the index.</em></p><h4><strong>Using a “C” Library in a program</strong></h4><p>Add the library’s name to the list of object file names given to the linker, using a special flag -l. Here is an example:</p><p><strong>$ cc main.o -L. -lname -o prog</strong></p><p>This will create a program using object file “main.o” plus any symbols require from the ‘name’ static library. If you haven’t notice ‘libname.a’ is the same as ‘-lname’ above without the ‘lib’ and ‘.a’ but including ‘-l’ flag. The usage of the ‘-L’ flag is to tell the linker that libraries might be found in the given directory ‘.’ for current directory in addition to standard locations where the compiler looks for system libraries. The ‘-o’ flag tells the linker to final output with the name ‘prog’.</p><p>Following the steps above is how you can create a static library. Next time we will talk about shared libraries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=800f913acdd3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What happens when you type gcc main.c]]></title>
            <link>https://medium.com/@heindrickcheung/what-happens-when-you-type-gcc-main-c-bea98ba4a869?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bea98ba4a869</guid>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Thu, 21 Jun 2018 00:58:59 GMT</pubDate>
            <atom:updated>2018-06-21T00:58:59.225Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*2G1k0Av993Flm8EeKvZB2Q.png" /></figure><p>C is a programming language that need a compiler to convert machine code from source code. When your building your projects in C there is four base components that can translate the project into binary code for your computer to understand. Lets break it down in detail. I will describe each step in order to follow the compiling process.</p><p><strong>Step 1:</strong> <em>Preprocessor</em>-responsible for removing comments, expansion of Macro expressions and included files and will output <em>filename</em>.<strong>i</strong></p><p><strong>Step 2:</strong> <em>Compiler</em>-will input filename.<strong>i</strong> to compiled assembly level instructions and output <em>filename</em>.<strong>s</strong></p><p><strong>Step 3: </strong><em>Assembler</em>-will input the assembly <em>filename</em>.<strong>s</strong> to produce machine codes and will output object files (.o, .obj)</p><p><strong>Step 4:</strong> <em>Linker</em>-will input the object files(.o, .obj) from the assembly while combining with Static Library to produce executable files or library.</p><p>Lets say main.c is one of the projects your working on. To start using this compiler, in your terminal please type:</p><p>gcc main.c</p><p>gcc which stands for <strong>GNU Compilier Collection</strong> will process the main.c file following step 1 to 4.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bea98ba4a869" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is the difference between a hard link and a symbolic link on Linux?]]></title>
            <link>https://medium.com/@heindrickcheung/what-is-the-difference-between-a-hard-link-and-a-symbolic-link-on-linux-7a287e28fd2d?source=rss-9b12033b420d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a287e28fd2d</guid>
            <category><![CDATA[holberton-school]]></category>
            <dc:creator><![CDATA[Heindrick Cheung]]></dc:creator>
            <pubDate>Tue, 19 Jun 2018 04:45:14 GMT</pubDate>
            <atom:updated>2018-06-19T04:45:14.817Z</atom:updated>
            <content:encoded><![CDATA[<p>Currently an engineering student at Holberton School focusing on low level programming starting of with Bash and C language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*S37omioNIfiQk9OavDW6Yw.png" /></figure><p>Hello there. In this introduction, I will explain as simple as possible the difference between the two types of links. Imagine a map of your city as the memory data of your computer while every address of each house is at a specific location. Let’s say a random tourist asked you the directions to a house or business but you are not standing right at that exact location. Symbolic links basically resembles you standing somewhere else while your pointing the tourist to go that address. Hard links is completely opposite, meaning you are standing exactly at that location with the exact description of how it look like or can see the business name of the address. Now for more detail on this subject:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a287e28fd2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>