Saturday, March 3, 2012

Text Editors

In my years as a programmer, I have used many, many different text editors.

At first I used editors with the normal GUI interface with a lot of mouse interaction, a regular file menu, and normal key bindings. But then, I started playing with gvim and emacs. I was impressed by the power and customizability of both of these amazing editors, and really like the fact that there was no need to use the mouse at all. In the end I chose vim/gvim as my editor of choice. The learning curve was a little steep, and even steeper than for emacs. However, it has the convenience of not constantly having to press the ctrl key. (I have recently remapped my caps-lock as a ctrl key, which alleviates that somewhat, but I didn't know that was possible at the time). I also worked as a software developer for a year on a team that primarily used gvim, and so I got used to using vim there. I wouldn't say that vim is intrinsically better than emacs, but it is what I am used to now, and I really like it.

HTML By Hand


So, here is the HTML I wrote by hand for the Webcraft school. I have worked with html before, so It only took me one try.

Friday, March 2, 2012

Badges and Webcraft

So, Mozilla (and probably others) are making this new "Badges" system, where you can demonstrate your skills by earning online badges. The idea is that a college degree doesn't give employer's an accurate specific idea of what you do and do not know. The same degree from different universities may include entirely different sets of skills, and knowledge sets. Badges provide way to demonstrate more granular knowledge.

This badges system is very exciting to me, because over the years I have taught myself a lot informally. However demonstrating these skills to employers and/or universities/grad schools, is a challenge.

And so, while these badges are new and in development I am going to try and earn some, both to show off the skills I have already acquired, maybe pick up some new skills, and hopefully help progress this new method of education.

This post is actually part of Web 101 on the P2PU Webcraft school. I am already fairly proficient with HTML, but I have no formal training, and this give me an opportunity to get some form of exterior validation, and possibly pick up something new.

Tuesday, December 13, 2011

A simple FFT

So, following my PDE's class, I decided to try my hand at writing an FFT algorithm. I ended up doing it in both c and Fortran. Surprisingly, I found it easier to write in Fortran (accounting for the fact that I am more familiar with c, and had to look up the syntax for just about everything in fortran). So, without further ado, here is my code:

FORTRAN:


 module FFT  
   implicit none  
   save  
   public  
   REAL, parameter :: PI = 4*atan(1.0)  
   contains  
   recursive function fft1(f) result(r)  
     !assumes that f is of length n where n is a power of 2  
     !output is zero indexed  
     COMPLEX, intent(in) :: f(:)   
     integer :: N, first, last, k   
     COMPLEX :: r(0:size(f)-1)  
     COMPLEX, dimension(0:size(f)/2-1) :: even, odd  
     N = size(f)  
     first = lbound(f,1)  
     last=ubound(f,1)  
     if( N == 1) then  
       r = f  
       return  
     end if  
     even = fft1(f(first:last-1:2))  
     odd = fft1(f(first+1:last:2))  
     do k=0,N/2-1  
      odd(k) = exp((0,-2)*PI*k/N)*odd(k)  
     end do  
     r(0:N/2-1) = even+odd  
     r(N/2:N-1) = even-odd  
   end function  
   recursive function ifft1(f) result(r)  
     !assumes that f is of length n where n is a power of 2  
     !output is zero indexed  
     COMPLEX, intent(in) :: f(:)   
     integer :: N, first, last, k   
     COMPLEX :: r(0:size(f)-1)  
     COMPLEX, dimension(0:size(f)/2-1) :: even, odd  
     N = size(f)  
     first = lbound(f,1)  
     last=ubound(f,1)  
     if( N == 1) then  
       r = f  
       return  
     end if  
     even = ifft1(f(first:last-1:2))  
     odd = ifft1(f(first+1:last:2))  
     do k=0,N/2-1  
       odd(k) = exp((0,2)*PI*k/N)*odd(k)  
     end do  
     r(0:N/2-1) = even+odd  
     r(N/2:N-1) = even-odd  
     r=r/2  
   end function  
 end module  

C:

 #include <complex.h>  
 #include <math.h>  
 #include <stdlib.h>  
 #include "fft.h"  
 double complex* _fft1( double complex*, size_t, unsigned int);  
 double complex* _ifft1(double complex*, size_t, unsigned int);  
 /** use the Cooley-Tukey method to take the fast fourier transform of an  
  * Array of lenth 2^n   
  *  
  * input and output are both complex arrays of length N, which must be a  
  * power of 2. Returns 0 if succusfull, nonzero if failed.  
  **/  
 double complex* fft1( double complex *input, size_t N) {  
   return _fft1(input,N,1);  
 }  
 double complex* _fft1( double complex *data, size_t N, unsigned int step) {  
   double complex *result;  
   double complex *even;  
   double complex *odd;  
   size_t k;  
   if ( (N > 2) && ( N % 2 != 0 )) return NULL;  
   result = (double complex*) malloc( sizeof(double complex) * N);  
   if ( N ==1 ) {  
     result[0]=data[0];  
     return result;  
   }  
   even = _fft1(data, N/2, 2*step);  
   odd = _fft1(data+step, N/2, 2*step);  
   //multiply the odds by the twiddle factor e^(-i*2*pi*k/N)  
   for( k=0; k < N/2; k++) {  
     odd[k] = cexp(-2.0*I*M_PI*k/N)*odd[k];  
   }  
   //generate result  
   for( k =0; k < N/2; k++) {  
     result[k] = even[k] + odd[k]; //first N/2 results  
     result[k+N/2] = even[k]-odd[k]; // last N/2 results  
   }  
   free(even);  
   free(odd);  
   return result;  
 }  
 double complex* ifft1( double complex* data, size_t N) {  
   return _ifft1(data, N, 1);  
 }  
 double complex* _ifft1( double complex *data, size_t N, unsigned int step) {  
   double complex *result;  
   double complex *even;  
   double complex *odd;  
   size_t k;  
   if ( N % 2 != 0 ) return NULL;  
   result = (double complex*) malloc( sizeof(double complex) * N);  
   if ( N ==1 ) {  
     result[0]==data[0];  
     return result;  
   }  
   even = _ifft1(data, N/2, 2*step);  
   odd = _ifft1(data+1, N/2, 2*step);  
   //multiply the odds by the twiddle factor e^(i*2*pi*k/N)  
   for( k=0; k < N/2; k++) {  
     odd[k] = cexp(I*2*M_PI*k/N)*odd[k];  
   }  
   //generate result  
   for( k =0; k < N/2; k++) {  
     result[k] = (even[k] + odd[k])/2; //first N/2 results  
     result[k+N/2] = (even[k]-odd[k])/2; // last N/2 results  
   }  
   free(even);  
   free(odd);  
   return result;  
 }  

Sunday, November 13, 2011

What is a miracle

The first definition of miracle on Dictionary.com is "an effect or extraordinary event in the physical world that surpasses all known human or natural powers and is ascribed to a supernatural cause." I don't really like this definition, and this post will explain why.

First of all, what does it mean for something to be caused by a supernatural cause? It would be something that does not obey the laws of the universe, correct? But the universe, and its laws were created by God. And why would God ever have need to break his own laws? God certainly influences things in the universe, and performs miracles on scales from affecting the entire universe to a single individual. But I have no reason to believe that he does so outside of the laws of the universe that he established at his creation. As an Example look at Moses parting the Red Sea. It is entirely conceivable that some natural phenomenon caused the water to stop flowing at some point, and then start again. But why should that preclude the involvement of God. It would be a remarkable coincidence for the phenomenon to occur at precisely the right time for the Israelites to cross on dry land. If it is the case, as I speculate that it is, that God performed the miracle by utilizing natural forces, then Moses' miracle was the result of a natural cause, but it was also a miracle of God.

Now let me talk about my own life. There have been a vast many occurances in my life that are entirerly explainable by human and/or natural forces, which nonetheless I would consider miracles. Often they take the form of something like me, or someone else, being in the right place at the right time, or someone saying something I really needed to hear, or a pathway opening to me that had previously been shut. I believe that these sorts of things happen to everyone. Some may say that they are just coincidences or random occurances. But the frequency with which they have occured in my life is too statistically significant to reasonably accept that as an explanation. I see the work of God in my life, and the lives of others, even when they do not see it. That is what I call a miracle.

You can do incredible things with science and technology. Today's technology would look like magic to the ancients. And our current understanding of the laws of the universe is limited at best. Just look at quantum mechanics. We can make remarkable predictions in that realm, but we have only half-baked philosophical musings about what is really going on. There are many things in this world that cannot be explained by the science we currently have, but they are not considered miracles by most, because eventually when our knowledge progresses we can explain them as natural phenomina. And there is nothing wrong with that. But just because something is natural doesn't mean it doesn't come from God.

One of God's greatest miracles is the miracle of creation. It is a miracle that we can see just by looking around us, and on deeper study the miracle only becomes more profound. If the physical constants that show up in our laws of physics differed by even a small amount, the universe would be the way it is, there might have been no stars, no matter, and certaiinly no life as we know it. And there is a beuaty and symmetry in the way the world works, down from the most complex organisms on Earth (i.e. humans) to the most basic laws of physics.

In order to miss the works of God in the Universe you must actively be trying not to see them.

Wednesday, August 17, 2011

Thoughts on Unity

This is just a short post. I have finally had a chance to try out Ubuntu's Unity Desktop. In short, it appears to be an attempt to mimac macs. There is a dock along the side which functions pretty well with basic drag and drop functionality. Although I would like a little bit more customizability, such as controlling when it is visible and maybe put special applets on it. Also, the if a program is maximized its menu bar combines with the task-bar. Which is kind of cool, but is inconstant with non-maximized windows, and isn't obvious since the menus are hidden unless the mouse is hovering over them.

As for the Ubuntu symbol in the left top corner, clickin on it gives you something akin to Kickoff in KDE4, where you have an entry box where you can type the name of an application or folder and it will show results which you can select to run. It also lists favorites, and shortcuts to menus for other apps. The downside is that if browsing through you applications is a bit tedious with the mouse, however it gives you hints about uninstalled programs you might like, which I think is pretty cool.

Overall, I am pretty impresssed by Unity, but I still like KDE 4 better. And Enlightenment for when I want something a little simpler.

Apple, iTunes, and DRM

First of all, as a Linux user, I am rather annoyed by the fact that you need to use iTunes in order to purchase anything from the iTunes store. Then again, it doesn't matter all that much, since DRM makes it impossible to play anyways.

DRM for those of you that don't know is "Digital Rights Management," or as some more correctly call it "Digitla Restrictions Management." It is the use of technology to restrict the ways that users can use copyrighted material, and is supposedly intended to combat Piracy, though in reality I think the restrictions it places on users, only makes piracy more popular and illegally downloaded materials more attractive than legal downloads. http://www.slate.com/id/2298871/pagenum/all/gives a very good discussion of the issue.

Anyway, my family recently purchased the Third Season of Merlin (from BBC) in my absense via iTunes without fully understanding the limitations of DRM. Then we discovered just how crippling DRM is. First of all, we can't burn the videos onto a DVD that is playable by our DVD player, which would make it impossible for most people to watch the movies on their TVs. Fortunately we have a (older) computer hooked up to our TV, but that only partly solved the problem. The videos are in the .m4v format, and are encrypted which means that the only program that can play it is iTunes. This would be a little annoying in and of itself (I would prefer to play it with VLC), but it is even worse becuas playing movies (at least these TV episodes) is very glitchy on iTunes, with frames constantly freezing, the audio misaligning with the video, and worst of all, about once every 10 minutes iTunes crashes, and it takes about 5 minutes to stop the not responding iTunes program and start it again. To be fair, I was playing off of a data DVD which might possibly be damagged, and iTunes was unable to copy the files to the hard drive, (another failing for iTunes).

Ok, so I looked around and tried to figure out if there was a way to remove the DRM from the files so I could actually watch the content we purchased. And there was, unfortunately it involved playing the content, and recording it. Well, if iTunes crashes whenever I try to play it I can't really record it again, can I?

So, Apple is not going to get any business from me anytime soon, and never if they don't start offering products that are more interoperable with products provided by companies other than Apple. And I am going to avoid DRM as much as possible, which might mean that I will be sticking to DVDs and hard copies until the Movie Industry realizes that DRM is restricting their profits and making consumers unhappy. The music industry figured that out eventually, I just hope that the movie industyr figures it out faster. And I would really like Congress to repeal the Digital Millenium Copyright Act, which is in contradiction with the Fair Use Act anyway.

By the way, if anyone knows of a way to legally obtain movies that are playable on Linux besides ripping DVDs, or to remove the DRM of iTunes movies, please let me know.