summaryrefslogtreecommitdiff
path: root/content/md
diff options
context:
space:
mode:
Diffstat (limited to 'content/md')
-rw-r--r--content/md/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md110
-rw-r--r--content/md/gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md2
-rw-r--r--content/md/gemfeed/index.md1
-rw-r--r--content/md/index.md1
4 files changed, 114 insertions, 0 deletions
diff --git a/content/md/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md b/content/md/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md
new file mode 100644
index 00000000..a422ef1e
--- /dev/null
+++ b/content/md/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md
@@ -0,0 +1,110 @@
+# The fibonacci.pl.c Polyglot
+
+> Written by Paul Buetow 2014-03-24
+
+In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it
+
+[https://en.wikipedia.org/wiki/Polyglot_(computing)](https://en.wikipedia.org/wiki/Polyglot_(computing))
+
+## The Fibonacci numbers
+
+For fun, I programmed my own Polyglot, which is both, valid Perl and C code. The interesting part about C is, that $ is a valid character to start variable names with:
+
+```
+#include <stdio.h>
+
+#define $arg function_argument
+#define my int
+#define sub int
+#define BEGIN int main(void)
+
+my $arg;
+
+sub hello() {
+ printf("Hello, welcome to Perl-C!\n");
+ printf("This program is both, valid C and Perl code!\n");
+ printf("It calculates all fibonacci numbers from 0 to 9!\n\n");
+ return 0;
+}
+
+sub fibonacci() {
+ my $n = $arg;
+
+ if ($n < 2) {
+ return $n;
+ }
+
+ $arg = $n - 1;
+ my $fib1 = fibonacci();
+ $arg = $n - 2;
+ my $fib2 = fibonacci();
+
+ return $fib1 + $fib2;
+}
+
+BEGIN {
+ hello();
+ my $i = 0;
+
+ for ($i = 0; $i <= 10; ++$i) {
+ $arg = $i;
+ printf("fib(%d) = %d\n", $i, fibonacci());
+ }
+
+ return 0;
+}
+```
+
+You can find the whole source code at GitHub:
+
+[https://github.com/snonux/perl-c-fibonacci](https://github.com/snonux/perl-c-fibonacci)
+
+### Let's run it with Perl:
+
+```
+❯ perl fibonacci.pl.c
+Hello, welcome to Perl-C!
+This program is both, valid C and Perl code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34
+fib(10) = 55
+```
+
+
+### Let's compile it as C and run the binary:
+
+```
+❯ gcc fibonacci.pl.c -o fibonacci
+❯ ./fibonacci
+Hello, welcome to Perl-C!
+This program is both, valid C and Perl code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34
+fib(10) = 55
+```
+
+It's really fun to play with :-).
+
+E-Mail me your thoughts at comments@mx.buetow.org!
+
+[Go back to the main site](../)
diff --git a/content/md/gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md b/content/md/gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md
index ad2fdaba..c6ef908a 100644
--- a/content/md/gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md
+++ b/content/md/gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md
@@ -24,6 +24,8 @@
Over the last couple of years I wrote quite a few Puppet modules in order to manage my personal server infrastructure. One of them manages FreeBSD Jails and another one ZFS file systems. I thought I would give a brief overview in how it looks and feels.
+[https://github.com/snonux/puppet-modules](https://github.com/snonux/puppet-modules)
+
## ZFS
The ZFS module is a pretty basic one. It does not manage ZFS pools yet as I am not creating them often enough which would justify implementing an automation. But let's see how we can create a ZFS file system (on an already given ZFS pool named ztank):
diff --git a/content/md/gemfeed/index.md b/content/md/gemfeed/index.md
index 624ef06d..b314429c 100644
--- a/content/md/gemfeed/index.md
+++ b/content/md/gemfeed/index.md
@@ -12,6 +12,7 @@
[2016-04-09 - Jails and ZFS with Puppet on FreeBSD](./2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md)
[2016-04-03 - Offsite backup with ZFS](./2016-04-03-offsite-backup-with-zfs.md)
[2015-12-05 - Run Debian on your phone with Debroid](./2015-12-05-run-debian-on-your-phone-with-debroid.md)
+[2014-03-24 - The fibonacci.pl.c Polyglot](./2014-03-24-the-fibonacci.pl.c-polyglot.md)
[2011-05-07 - Perl Daemon (Service Framework)](./2011-05-07-perl-daemon-service-framework.md)
[2010-05-09 - The Fype Programming Language](./2010-05-09-the-fype-programming-language.md)
[2010-04-09 - Standard ML and Haskell](./2010-04-09-standard-ml-and-haskell.md)
diff --git a/content/md/index.md b/content/md/index.md
index aa6f2589..e32b5472 100644
--- a/content/md/index.md
+++ b/content/md/index.md
@@ -64,6 +64,7 @@ I have switched blog software multiple times. I might be back filling some of th
[2016-04-09 - Jails and ZFS with Puppet on FreeBSD](./gemfeed/2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md)
[2016-04-03 - Offsite backup with ZFS](./gemfeed/2016-04-03-offsite-backup-with-zfs.md)
[2015-12-05 - Run Debian on your phone with Debroid](./gemfeed/2015-12-05-run-debian-on-your-phone-with-debroid.md)
+[2014-03-24 - The fibonacci.pl.c Polyglot](./gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md)
[2011-05-07 - Perl Daemon (Service Framework)](./gemfeed/2011-05-07-perl-daemon-service-framework.md)
[2010-05-09 - The Fype Programming Language](./gemfeed/2010-05-09-the-fype-programming-language.md)
[2010-04-09 - Standard ML and Haskell](./gemfeed/2010-04-09-standard-ml-and-haskell.md)