C Programming: Square number generator
This is an example of how to square numbers using a simple function in the C programming language.
file: square.c
#include <stdio.h>
int square(int x)
{
int sq;
sq = x * x;
return sq;
}
int main()
{
int i, count = 10;
for(i = 1; i <= count; ++i)
{
printf("%d\n", square(i));
}
return(0);
}
Compile and run
$ gcc -o square square.c $ ./square 1 4 9 16 25 36 49 64 81 100
Squaring a number is, of course, as simple as multiplying a number by itself. If you ever need to do this using the C programming language, the above is a simple proof of concept.
Cisco: show running-config without more
|
|
When executing the show running-config (show run) command on Cisco ISO, the output will be paged through one screenful at a time. This is useful as Cisco configs can be very long and can have thousands of lines. It would be impractical to dump the whole config to screen and expect the admin to rely on their scroll buffer. However admins like to have freedom to choose, to execute show run with out more you can use this method. |
Disable more
# terminal length 0 # show running-config
If you are not enable you can test your terminal length setting with a command like show version.
The terminal length command is where you set the number of lines to display per screen, 0 means no limit, however you could use this setting to show, say, 5 lines at time.
Once this command has been executed it will disable paging (more) for all output in the current session. Next time you login more paging will be enabled again.
Terminal length values
terminal length ? <0-512> Number of lines on screen (0 for no pausing)
pkgng: First look at FreeBSD’s new package manager
FreeBSD has been long due a better package management system, pkg_add, pkg_info, etc just doesn’t cut it any more. For a long time GNU/linux users have always used this as a reason not to use FreeBSD and instead favour some GNU/linux combination with an all encompassing easy to use package manager, such as Debian’s apt-get. FreeBSD’s response has always been, (not actual quote), “We have the ports collection, which is cooler and more flexible than just having some easy to use package manager. You can always do it yourself by writing scripts around the pkg_* tools or using portmaster’s –packages-only option”. While this is all true, there is still a gap for a good package manager that needs filling. So here comes pkgng (pkg: (next|new) generation), this is FreeBSD’s next generation package manager and although still in beta, with a few features missing, it is very nice.
Here is a quick overview of pkgng, how to use it and some of the new features that will be available. The tests on this page are based on pkgng version 1.0 beta5 running on FreeBSD 9.0 RELEASE amd64 (now updated to include changes up to beta9). You might find the official wiki page interesting reading if you haven’t seen it already, pkgng – FreeBSD Wiki.
IPv6: Short IPv6 Regexp – PHP preg_match() example
Back in July 2011 I posted an example IPv6 regular expression using PCRE via PHP’s preg_match() function to check for a valid IPv6 address. Find it here. My example was long, and had some issues. It didn’t match short hand IPv6 addresses properly and it was not very elegant. Recently a visitor commented on this regex and suggested a much better way of doing it.
IPv6 Regexp:
'/^(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})\z/i'
If you’re interested in seeing some more IPv6 regex examples for other languages you should check this link Shortest IPv6 Validation Regular Expression (RegEx).
Here is the updated version, I have not found any bugs yet so please feel free to test it below or try it out in your own code. Let us know how you get on.
You can try out this function here, give it a go!
Example IPv6 addresses
- 2001:2d12:c4fe:5afe::1
- 2a00:1450:400c:c01::68
- ::1
Here is the source, a better way of matching IPv6 using PHP preg_match()
function valid_ipv6_address( $ipv6 )
{
$regex = '/^(((?=(?>.*?(::))(?!.+\3)))\3?|([\dA-F]{1,4}(\3|:(?!$)|$)|\2))(?4){5}((?4){2}|(25[0-5]|(2[0-4]|1\d|[1-9])?\d)(\.(?7)){3})\z/i';
if(!preg_match($regex, $ipv6))
return (false); // is not a valid IPv6 Address
return (true);
}
Cfengine3 fix FreeBSD package name regex match
Cfengine 3 is a very cool piece of software and can have many uses, one thing it’s very good for is package management. FreeBSD works pretty well with this, but the big downfall is the lack of a really good package manager on FreeBSD. Sure there is ‘pkg_add’, ‘pkg_info’, ‘pkg_delete’, etc which is fine for the most part, but compare them to some of the others around such as apt for Debian or rpm for RedHat and it becomes apparent that FreeBSD just has a collection of utilities. This means you have to script around them yourself or use something like portmaster with a package only setting. There is apparently a new package tool on the way, so stay tuned for that.
You might be wondering why I don’t mention the ports collection, well it’s not because I don’t love it, I do. What I’m talking about here is building custom packages from the ports collection and then distributing them on mass.
Word Cloud for FreeBSD 9.0 generated from Me, BSD
Here is a fun word cloud made on www.wordle.net. It highlights some of the recent subjects covered on mebsd.com this year such as the release of FreeBSD 9.0 and upgrading to it.
Wordle word cloud for FreeBSD from www.mebsd.com







