<?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 Christian Agha on Medium]]></title>
        <description><![CDATA[Stories by Christian Agha on Medium]]></description>
        <link>https://medium.com/@christianagha?source=rss-4a3ed5b77aaf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rtlu_6QgFGXVc8s5.</url>
            <title>Stories by Christian Agha on Medium</title>
            <link>https://medium.com/@christianagha?source=rss-4a3ed5b77aaf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 00:07:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@christianagha/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[Mutable & Immutable Python objects]]></title>
            <link>https://medium.com/@christianagha/mutable-immutable-python-objects-bbf6e9ac706c?source=rss-4a3ed5b77aaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/bbf6e9ac706c</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Christian Agha]]></dc:creator>
            <pubDate>Thu, 25 May 2017 06:56:42 GMT</pubDate>
            <atom:updated>2017-05-30T17:39:33.677Z</atom:updated>
            <content:encoded><![CDATA[<p>After 3 months of learning C at the<a href="http://www.holbertonschool.com/"> Holberton School</a> in San Francisco, we have recently started to learn Python. It has been really enjoyable and challenging in a different way than C was. This week we learned about python classes and objects and how everything in python is really an object. In the following paragraphs, I’d like to summaries some of the things I learned in the past few days.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/157/1*lfJNKCzOcGftUoGC5P4AtA.png" /></figure><p>Let’s say we start out with creating 2 identical lists a and b. We can use the builtin function id() to return the “identity” of a and b. The returned id is a number which is guaranteed to be unique and constant as long as our object exists. Fun fact, in the CPython implementation, the id number is actually the address of the object in memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*A39tlgklnmj_hOIM3O_s6A.png" /></figure><p>So every object we create in Python has an id, and it also has a type. Using the built in type function we are told the type of any of our objects.</p><p>As we see here, all those types, <em>list, int, float..</em> are actually classes. And what we find out is that each class has certain operations that it can perform on its instances. For example the append method in the list class adds an item to the end of the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/162/1*tN_zFnLXmRpLoh7DSts0fA.png" /></figure><p>When it comes to python types, some of them are mutable, or can be changed and some of them aren’t. Take a look at the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*Z_VurNWwDcI7FFS7GNefiw.png" /></figure><p>Lists it turns out are mutable. We changed the first item in list <em>a</em> and that was reflected in <em>b</em>, because <em>a</em> and <em>b</em> are both pointing to the same list in the same place in memory. But when it came to <em>c</em> and <em>d</em> which are ints, we see that when we assign 5 to <em>c</em> we are changing the memory location <em>c</em> is pointing to, but that has no effect on <em>d</em>, which still has the value 3. That’s because integers in python are immutable. Take a look at this helpful list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*uFlTNY4W3czywyU18zxl8w.png" /></figure><p>So lists, sets and dictionaries in python are mutable objects and everything else is not.</p><p>So why is mutability important? It actually has to do with memory and efficiency. Take a look at the code bellow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/1*wTNTFHaSGBcf13edX8YHxg.png" /></figure><p>Because <em>str1</em> is a string which is immutable, every time we change it we are freeing and reallocating memory, which is not very efficient. In contract, lets see what happens when we modify a list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*F_1ovuHmnPUMQBEp3miBlg.png" /></figure><p>Now that <em>str1</em> is a list, it is modified in place, and that is much more efficient than all the memory manipulations that happened when it was an immutable string.</p><p>What about passing arguments to functions? In C we could pass arguments by value or by reference, but in python it’s a little different. When a value is passed to a function and has it’s value changed inside the function, it’s value outside the function changes depending on whether it is mutable or not. Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*-PVI4j9Y0YDbWM5WQbrnKw.png" /></figure><p>We see above that a string modified inside a function remains unmodified outside of it, a list on the other hand is changed outside of the function after it’s been modified inside it. All this is because a list is mutable and a string is not.</p><p>So finally, in Python it is very important to understand object mutability. Make sure you understand how and why it works!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bbf6e9ac706c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Static C Library on Linux]]></title>
            <link>https://medium.com/@christianagha/creating-a-static-c-library-on-linux-d28c95a7f23a?source=rss-4a3ed5b77aaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/d28c95a7f23a</guid>
            <category><![CDATA[c]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[libraries]]></category>
            <dc:creator><![CDATA[Christian Agha]]></dc:creator>
            <pubDate>Mon, 06 Mar 2017 06:23:20 GMT</pubDate>
            <atom:updated>2017-03-06T06:23:20.858Z</atom:updated>
            <content:encoded><![CDATA[<p>Say you wrote some C functions and you want to package them to be used later by other programs.. what would be the best way to accomplish this? Creating a library of course! A library in C is a collection of functions and declarations which is made available to be used by other programs. There are two different kinds of libraries, Static and Dynamic. Let’s take a look at Static libraries.</p><p>Let’s start out with a few C functions that accomplish various tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*xfqPPbRugjdWJufgR72LFw.png" /></figure><p>First thing you want to do is to compile these C files using gcc, the command “gcc -c *.c” assembles the source files, but does not link them. The output of this command is in the form of an object file for each C file. By default, the object file name will be the source file name with a ‘.o’ instead of a ‘.c’ at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*QZCWti9OXWVCkqbvWlpeJQ.png" /></figure><p>The next command we need to use to create a Static library is the “ar” command. “ar” can create, modify, or extract archives. We should add the “-rc” options, the r stands for “Insert the files <em>member</em>… into <em>archive</em> (with <em>replacement</em>). Any previously existing members are deleted if their names match those being added.” , and the c stands for “<em>Create</em> the archive. The specified <em>archive</em> is always created if it did not exist, when you request an update. But a warning is issued unless you specify in advance that you expect to create it, by using this modifier.”</p><p>As we can see bellow, after we write the “ar -rc lib_my_functions.a *.o”, the system created a library files called <em>lib_my_functions.a </em>that includes all the files in the folder that end with a “.o”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*3_Gs2RyukeBYUTYJbcXmVA.png" /></figure><p>We can confirm what’s inside the library with the “<em>ar -t</em>” command, as you can see bellow, all the “<em>.o</em>” files are included in the <em>lib_my_functions.a</em> library file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*CJQnPLy8pW_AASvDmvZjhQ.png" /></figure><p>After that we should run the “<em>ranlib lib_my_functions.a</em>” command which “generates an index to the contents of an archive and stores it in the archive.” A library with such an index speeds up linking to the library and<br> allows routines in the library to call each other without regard to<br> their placement in the archive.</p><p>That’s it! We’re done. We have created a Static library from our custom functions. But now how are we able to use it? Say we have a little function that prints a statement using our _puts function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*UWAjMQQzpvDqR1CLg-6LfQ.png" /></figure><p>If we use gcc to try to compile it we get an error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*ylA22GgbQMmjOr54Q1_-9A.png" /></figure><p>This is because we never included the static library we created in the gcc command. The correct way to do it is this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*KA-y77jKE8drLFgs4rhKGg.png" /></figure><p>the “<em>-L.</em>” option looks in current directory for library files, and the “<em>-l</em>” attached to the library name (minus the “<em>lib</em>”) includes the <em>_my_functions</em> library in the linking process. So now the function <em>_puts</em> inside <em>main.c</em> can be linked to its function definition in the <em>lib_my_functions.a </em>library.</p><p>So now when we run the output file “main”, we get this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*n7vJWIhDiXsI1ns5pTrJig.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d28c95a7f23a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[gcc-ing the main!]]></title>
            <link>https://medium.com/@christianagha/gcc-ing-the-main-35cf8e31b384?source=rss-4a3ed5b77aaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/35cf8e31b384</guid>
            <dc:creator><![CDATA[Christian Agha]]></dc:creator>
            <pubDate>Thu, 09 Feb 2017 06:27:58 GMT</pubDate>
            <atom:updated>2017-02-09T06:27:58.330Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*JCTrRH6dSlojeMpz9k5nWw.png" /></figure><p>So, you opened up a text editor and wrote some C/C++ lines. There’s an <em>#include &lt;stdio.h&gt;</em> in there, a <em>main()</em> function, some calculations and finally a <em>return</em>! Now you’re ready to see what these line actually do. So what do you do? You gcc that crap!</p><p>gcc as in “gnu C compiler” is a program that compiles your C/C++ text and makes it into a functioning program. It does this in several very ordered steps, let’s take a look at them.</p><h3>1-Preprocessing</h3><p>Preprocessing is the first thing gcc does. It first looks at the extension of the file to figure out the language it contains then it removes all the comments. After that it adds the code from the included header files and it replaces all the macros with the code they point to.</p><h3>2-Compilation</h3><p>Second this gcc does is compilation, where it takes the C/C++ code and translates it to assembly code, which is a lower lever language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*X5Xqzl-U4ipbMlDOUfxttA.png" /></figure><h3>3-Assembly</h3><p>The third step is assembly, where gcc takes the assembly code and turns it into object code, which is the language a computer understands!</p><h3>4-Linking</h3><p>During the fourth and final step, the object code is linked to other libraries and files needed to run the code properly.</p><p>If everything is as it should be, gcc will create by default an executable file called <em>a.out </em>that you can run! And that’s when the fun really begins :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35cf8e31b384" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hard & Symbolic links in Linux, what is the difference?]]></title>
            <link>https://medium.com/@christianagha/hard-symbolic-links-in-linux-what-is-the-difference-6c1ee04e5bde?source=rss-4a3ed5b77aaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c1ee04e5bde</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Christian Agha]]></dc:creator>
            <pubDate>Tue, 07 Feb 2017 08:28:28 GMT</pubDate>
            <atom:updated>2017-02-07T08:28:28.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*Q77tFyicUYPNVBh-9aYfeg.jpeg" /></figure><p>We all know what a shortcut is right? Well.. in Linux, shortcuts are referred to as links and there are two very different types of them.. hard links and symbolic links. Let’s dig a little deeper to find who’s who and when to use which.</p><p>A little background first. In a Linux system every file is in reality a link to an <strong>inode</strong>. You can think of an inode as the address of a house where the house and its contents are the file itself. So when a file is first created it is assigned both a name and an inode number which is a unique integer stored in a directory that stores the inodes and the files that refer to them.</p><p>By default, Linux creates a <strong>hard</strong> link when you use the ‘ln’ command. A hard link points to the same inode that the original file points to. So it’s basically a different name to the same file. If you mistakenly erase the original file, you are still able to access its contents if a hard link to its inode still exists somewhere on the system.. all is not lost. If you make changes to either the original file or the hard link, those changes will be reflected in both of them. A hard link cannot be connected to directories, only files.</p><p>In contrast, a <strong>symbolic</strong> link (aka soft link) [ln -s] does not have the same inode number as the file it’s linked to. It merely contains the path of that file but not the contents of it. If a file gets deleted or it’s path changes, all the symbolic links to it stop working and become dangling links that point to a non-existing file. Symbolic links can be connected to a directories.</p><p><a href="http://www.thegeekstuff.com/2010/10/linux-ln-command-examples/">If you’re interested to learn more about hard and symbolic links, checkout this great post about the subject.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c1ee04e5bde" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ls *.c]]></title>
            <link>https://medium.com/@christianagha/ls-c-2c98efb738?source=rss-4a3ed5b77aaf------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c98efb738</guid>
            <category><![CDATA[command-line]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[terminal]]></category>
            <dc:creator><![CDATA[Christian Agha]]></dc:creator>
            <pubDate>Tue, 07 Feb 2017 06:12:20 GMT</pubDate>
            <atom:updated>2017-02-07T06:12:20.849Z</atom:updated>
            <content:encoded><![CDATA[<p>“ls” is a Linux command that lists information about the files &amp; folders in the current working directory and beyond! I won’t bore you with all the behind the scene details of how it technically works, so let’s stick to the basics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtZe90nCRTmpDO17sexeCA.png" /></figure><p>By default “ls” sorts the names alphabetically and can list many detailed information about the files depending on what options you set with it. For example the ‘-a’ option lists all the files including the hidden ones that don’t show up by default and the very helpful ‘-l’ option lists all the files and folders with many of their detailed properties.</p><p>What if you wanted to display only some files and folders that have a certain thing in common? That’s when the * comes in. The asterisk represents any number of characters whether they were letters or numbers. What it is essentially saying is this: list all the files and folder that end with a “.c”. If the expression was written ‘ls .c*’ it would mean list all the files that begin with a “.c” and end with any other characters.</p><p>So that’s all there is to it.. it’s a fun command that can be very useful at times. More on other Linux commands later! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c98efb738" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>