<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coding Friends &#187; hello world</title>
	<atom:link href="http://www.codingfriends.com/index.php/tag/hello-world/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingfriends.com</link>
	<description>Coding Friends, place for developers.</description>
	<lastBuildDate>Sun, 04 Dec 2011 21:11:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Hello world</title>
		<link>http://www.codingfriends.com/index.php/2011/04/28/hello-world-9/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=hello-world-9</link>
		<comments>http://www.codingfriends.com/index.php/2011/04/28/hello-world-9/#comments</comments>
		<pubDate>Thu, 28 Apr 2011 20:23:56 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[hello world]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=1599</guid>
		<description><![CDATA[Python is one of those languages that are used by allot of different companies but probably does not get the credit that how much it is used. Google uses it, allot of the Ubuntu backend is python. Python is able to do object orientated programming, but does not include the full essence of objects like [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.python.org/">Python</a> is one of those languages that are used by allot of different companies but probably does not get the credit that how much it is used. Google uses it, allot of the <a href="http://www.ubuntu.com">Ubuntu</a> backend is python.  Python is able to do object orientated programming, but does not include the full essence of objects like other languages like C++/Java/C# where you have a private/public/protected but use a &#8220;__&#8221; before the variable as a &#8220;hidden&#8221; variable within the class.</p>
<p>So going to do some posts of how cool Python can be, but to start with the classic &#8220;hello world&#8221; program, like most languages (C++/PHP/C#/Java) most of the functions/methods are actually english words that should mean something to the writer/reader of the program, so to display a message to the screen you can use the &#8220;print&#8221; command and here is the example program</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;hello world&quot;</span></pre></div></div>

<p>and this will output, if you save out that program as helloworld.py</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">hello world</pre></div></div>

<p>to call the saved program via the command line you need to call the interpreter (the python program).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python helloworld.py</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2011/04/28/hello-world-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>kernel &#8211; hello world</title>
		<link>http://www.codingfriends.com/index.php/2010/03/01/kernel-hello-world/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=kernel-hello-world</link>
		<comments>http://www.codingfriends.com/index.php/2010/03/01/kernel-hello-world/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 10:25:39 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[C / C++]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[Kernel]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=761</guid>
		<description><![CDATA[To compile up this module you will need to have the linux header files, which should be installed but if not you just need to either use apt-get, rpm, pacman etc to install the linux header files. With kubuntu I use the aptitude command to install applications and updates etc, but to get the linux-headers [...]]]></description>
			<content:encoded><![CDATA[<p>To compile up this module you will need to have the linux header files, which should be installed but if not you just need to either use apt-get, rpm, pacman etc to install the linux header files.</p>
<p>With <a href="http://www.kubuntu.org/">kubuntu</a> I use the aptitude command to install applications and updates etc, but to get the linux-headers I used</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> linux-headers</pre></div></div>

<p>that is normally linked to the latest version of the linux kernel that you are using.</p>
<p>The main part of the program is outputting a potential parameter being passed (passing parameters to a nvidia kernel module <a href="http://www.codingfriends.com/index.php/2010/02/27/kernel-passing-module-parameters/">here</a>) and also saying hello world, kinder two for the price of one as such tutorial. </p>
<p>As in c language there is the <a href="http://en.wikipedia.org/wiki/Printf">printf</a>, but in the kernel there is a printk which is the same similar thing but more for outputting errors/messages to the user.</p>
<p>So for example</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">printk<span style="color: #008000;">&#40;</span>KERN_INFO <span style="color: #FF0000;">&quot;hi there<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>the KERN_INFO is a kernel information marco that sends the details to a information level of output, e.g. /var/log/messages or you could use dmesg</p>
<p>here is the code on how to pull in parameters from a kernel module being loaded, the parameter_int is my parameter to be checked against and the S_IRUSR is the access rights (IR = read permission, IW = write permission, USR = user, GRP = group, OTH = others)</p>
<p>The module_param takes 3 parameters, the first is the variable to place the value into, second is the variable type and the third is the access rights, with the MODULE_PARM_DESC is the description of the parameter to pass, in this case it is just a integer value.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> parameter_int <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
module_param<span style="color: #008000;">&#40;</span>parameter_int, <span style="color: #0000ff;">int</span>, S_IRUSR <span style="color: #000040;">|</span> S_IWUSR <span style="color: #000040;">|</span> S_IRGRP <span style="color: #000040;">|</span> S_IROTH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
MODULE_PARM_DESC<span style="color: #008000;">&#40;</span>parameter_int, <span style="color: #FF0000;">&quot;An integer value&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Within a normal c/c++ program there is a main function where the program is run from, but in the kernel space since the main program is already running you can define what functions to call when the module is inserted and also removed,</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">module_init<span style="color: #008000;">&#40;</span>hello_init<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
module_exit<span style="color: #008000;">&#40;</span>hello_exit<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>the module_init parameter is the function to call when the module is loaded and the module_exit parameter is the function to call when module is removed from the kernel space.</p>
<p>Here is the full code, if you save this as helloworld_parameter.c</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* hello world with passing some parameters in the kernel module */</span>
&nbsp;
<span style="color: #339900;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339900;">#include &lt;linux/moduleparam.h&gt;</span>
<span style="color: #339900;">#include &lt;linux/kernel.h&gt;</span>
<span style="color: #339900;">#include &lt;linux/init.h&gt;</span>
<span style="color: #339900;">#include &lt;linux/stat.h&gt;</span>
&nbsp;
MODULE_LICENSE<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;GPL&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
MODULE_AUTHOR<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;genux&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* need to setup a setup a static variable to hold the parameter value and
   set it to a default value is none is passed */</span>
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> parameter_int <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #ff0000; font-style: italic;">/* the linux/stat.h has the S_IRUSR definitions etc.. */</span>
<span style="color: #ff0000; font-style: italic;">/* S_IRUSR = read permission, owner
   S_IWUSR = write permission, owner
   S_IRGRP = read permission, group
   S_IROTH = read permission, others
   */</span>
&nbsp;
module_param<span style="color: #008000;">&#40;</span>parameter_int, <span style="color: #0000ff;">int</span>, S_IRUSR <span style="color: #000040;">|</span> S_IWUSR <span style="color: #000040;">|</span> S_IRGRP <span style="color: #000040;">|</span> S_IROTH<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
MODULE_PARM_DESC<span style="color: #008000;">&#40;</span>parameter_int, <span style="color: #FF0000;">&quot;An integer value&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> __init hello_init<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	printk<span style="color: #008000;">&#40;</span>KERN_INFO <span style="color: #FF0000;">&quot;Hello world<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	printk<span style="color: #008000;">&#40;</span>KERN_INFO <span style="color: #FF0000;">&quot;my parameter int value is : %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, parameter_int<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
	<span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> __exit hello_exit<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">void</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
	printk<span style="color: #008000;">&#40;</span>KERN_INFO <span style="color: #FF0000;">&quot;Goodbye from hello world parameter<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
module_init<span style="color: #008000;">&#40;</span>hello_init<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
module_exit<span style="color: #008000;">&#40;</span>hello_exit<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>since we are compiling a kernel module we need to link to the loaded kernel modules, here is a Makefile to compile up the program, so save this as &#8220;Makefile&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">obj-m += helloworld_parameter.o
&nbsp;
all:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> modules
&nbsp;
clean:
	<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #660033;">-C</span> <span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span>shell <span style="color: #c20cb9; font-weight: bold;">uname</span> -r<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">/</span>build <span style="color: #007800;">M</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>PWD<span style="color: #7a0874; font-weight: bold;">&#41;</span> clean</pre></div></div>

<p>the first is the obj-m += which means compile a object module and you could have more than one file to compile up so use the += to add more files to it, the -C means change directory for the build environment for the kernel space, the M is a parameter passed to the build environment to use this current directory for where the source files are, and the modules means to create kernel modules e.g. filename.ko.</p>
<p>once you have run the</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>there should be a file called helloworld_parameter.ko, to find out details about your new module you can use the modinfo</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">modinfo helloworld_parameter.ko
filename:       helloworld_parameter.ko
author:         genux
license:        GPL
srcversion:     A81F18D40DA3C5FAB1C71FF
depends:
vermagic:       2.6.31-<span style="color: #000000;">17</span>-generic SMP mod_unload modversions
parm:           parameter_int:An interger value <span style="color: #7a0874; font-weight: bold;">&#40;</span>int<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>and the parm: is the important part here, it is what the parameter is called to pass a value to for example to watch the module being inserted if you open up two consoles and on one put</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>messages</pre></div></div>

<p>in the second console do</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">insmod helloworld_parameter.ko
rmmod helloworld_parameter.ko
insmod helloworld_parameter.ko <span style="color: #007800;">parameter_int</span>=<span style="color: #000000;">3</span>
rmmod helloworld_parameter.ko</pre></div></div>

<p>and the output should be in the first console</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Hello world
&nbsp;
my parameter int value is : <span style="color: #000000;">0</span>
Goodbye from hello world parameter
&nbsp;
Hello world
&nbsp;
my parameter int value is : <span style="color: #000000;">3</span>
Goodbye from hello world parameter</pre></div></div>

<p>hope that helps with kernel modules, I am planning on doing a kernel module for a custom built USB device.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/03/01/kernel-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress &#8211; plugin &#8211; hello world</title>
		<link>http://www.codingfriends.com/index.php/2010/02/15/wordpress-plugin-hello-world/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-plugin-hello-world</link>
		<comments>http://www.codingfriends.com/index.php/2010/02/15/wordpress-plugin-hello-world/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 11:18:12 +0000</pubDate>
		<dc:creator>genux</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[hello world]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.codingfriends.com/?p=711</guid>
		<description><![CDATA[WordPress is a blogging software that runs on a webserver, the great thing about wordpress is that you are able to extend the functions to create the pages/comments/archives etc on the blogging site. You are also able to create your own themes that will use the functions that you can create within that theme So [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is a blogging software that runs on a webserver, the great thing about wordpress is that you are able to extend the functions to create the pages/comments/archives etc on the blogging site.  You are also able to create your own themes that will use the functions that you can create within that theme  So lets it straight, a plugin for the wordpress is the way that you can extend the functional aspects of the whole site that is not dependent on the theme that you using (a theme is what you view on the web page the &#8220;style&#8221; (css) of the site for example).</p>
<p>There is two main directories within the wordpress directory structure to add in new themes (wp-content/themes) and the plugins (wp-content/plugins) this is where you place the code to extend the basic wordpress install.</p>
<p>In this example I going to extend the action get_header, if you save the code below into the directory wp-content/plugins/codingfriends_helloworld as codingfriends_helloworld.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin Name: Coding friends hello world
Plugin URI: http://www.codingfriends.com/
Description: Outputs hello world
Version: 0.1
Author: Genux
Author URI: http://www.codingfriends.com
License: GPL2
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> codingfriends_helloworld<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hello world&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'get_header'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'codingfriends_helloworld'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>once you have saved that file, then goto your wordpress admin page, on the left is the Plugins link, click on that and within there will be the &#8220;new&#8221; plugin called coding friends hello world, you just need to activate it and then hey presto it works. There will be &#8220;hello world&#8221; at the top of the wordpress installed pages within the main site (not the wp-admin part of the site).</p>
<p>What is happening is that you have created a function called codingfriends_hellworld, which outputs &#8220;hello world&#8221;, but the main part is the</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action</pre></div></div>

<p>this will add this function to a defined plugin action (to get a list of all of the actions (these happen within the core site), and filters (alter text within the site, e.g. pages that you add to the site, comments etc) you can use look <a href="http://codex.wordpress.org/Plugin_API">here</a>).</p>
<p>So when the action get_header is called within the main wordpress application, it will call your new function (codingfriends_helloworld).</p>
<p>There is tons of things that you can do with these, alter the comments when posted back to the site, pages etc, just look at the API list.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingfriends.com/index.php/2010/02/15/wordpress-plugin-hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

