To the one I love
This one goes out to the one I love, because Tomorrow Is A Long Time
This one goes out to the one I love, because Tomorrow Is A Long Time
Well, I’ve been reading up and digging into the Linux kernel quite heavily recently. I’d like to get to the point where I can contribute to the Linux kernel and give back to the community that has given so much to me. I’m nowhere near this point just yet, but I’ve begun the journey.
I took my old Acer Aspire H340 program to drive the LEDs and turned it into a simple kernel module as a baby step. The module creates a kernel thread (you know, those processes running on your Linux box with square brackets around them: [ksoftirqd/0] for example) that loops reading disk stats via part_read_stat and comparing the number of read/write IOs to the last iteration. If it’s greater, obviously there has been disk activity, so turn on the appropriate LED. Simple and the code is quite ugly, but it works and it’s my first one.
Cheers!
Recently, I’ve been trying to come up with an idea of some functionality to implement in a PHP extension. I’ve become interested in the internals of PHP and the Zend Engine. As a PHP developer, it can only help to take a peek under the hood and understand what’s really going on when I code in PHP. It turns out it’s hard to come up with *useful* ideas for PHP extensions that haven’t already been done. I finally gave up and decided to write a PHP extension for the Pusher API. Pusher is a nifty little service that allows you to push data in real time to a web browser or other devices. It utilizes WebSockets and falls back to Flash if they’re unavailable. Basically, the web browser (using a client library, usually JS) will open up a connection to the Pusher backend and subscribe to one or more channels waiting for events. A publisher library will then send an event to Pusher using your API key and secret, which will then trigger any listeners in the browser bound to that event on that channel. It’s a pretty simple idea, but it allows the developer to quickly develop real time apps. For instance, I created a rudimentary chat interface on one of my dev sites in a matter of minutes. Anyway, that’s enough about Pusher. If you’re interested, go sign up for a free API account. Now, there’s already a fairly simple yet effective Publisher API for Pusher that can be found here. Compiling my PHP extension and installing it is definitely not the easiest way to use Pusher in PHP. I would still recommend using Squeeks version above. It was quite rewarding to make my first functioning PHP extension though. There’s really not a whole lot of documentation out there about writing PHP extensions, so I may write some articles in the near future documenting the process. You can check out the code at http://github.com/payden/pusher or http://git.obfuskate.com/?p=pusher.git. Until later.
Well, it’s been quite some time since I’ve posted on here. Haven’t had the time I guess. I recently found another great position at Time4Learning.com. I’m doing PHP development for them here in South Florida. I’m really enjoying working with them. All of the guys are really sharp and encourage each other to get better instead of being comfortable with your current skillset. It’s really been lighting a fire for me to continue my own endeavors in learning new skills/technologies. For example, I’ve been working on yet another implementation of a project that I’ve tried a handful of times. The project is a complete IRC client in the browser. I know this has been done and whatnot, but I always wanted to do a better version than what’s available. My current implementation is using libfcgi in C to handle web page generation as well as the networking layer linking the client side to the IRC server. The client slide will be implemented using EmberJS. Anywho, I’ve just finished learning how to use epoll to handle event driven networking. It’s a good feeling to be constantly learning. I’ve posted the code below even though I took almost no time making things clean. The idea was to quickly figure out epoll which I think should be pretty easily understood by my simple program. It just binds and listens on port 3333 waiting for connections to read and dumping the contents. I’ll definitely be using epoll to handle my network connections in the fastcgi process for my AjaxIRC app. Check it out:
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char **argv) {
int epoll_fd, listen_fd, reuse = 1, ret, i, new_fd;
struct sockaddr_in theiraddr;
socklen_t addrsize;
struct addrinfo hints;
struct addrinfo *servinfo, *cur;
struct epoll_event ev, *events;
char read_buf[1024];
int read_bytes;
if((epoll_fd = epoll_create(100))==-1) {
perror("epoll");
exit(1);
}
printf("Got epoll fd: %d\n",epoll_fd);
memset(&hints, '\0', sizeof(hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
if((getaddrinfo(NULL,"3333",&hints, &servinfo))!=0) {
perror("getaddrinfo");
exit(1);
}
for(cur = servinfo; cur != NULL; cur = cur->ai_next) {
listen_fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
if(listen_fd == -1) {
perror("socket");
continue;
}
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
if((bind(listen_fd, cur->ai_addr, cur->ai_addrlen))==-1) {
close(listen_fd);
continue;
}
break;
}
if(cur == NULL) {
fprintf(stderr,"Failed to bind\n");
exit(1);
}
freeaddrinfo(servinfo);
if(listen(listen_fd, 10) == -1) {
perror("listen");
exit(1);
}
ev.data.fd = listen_fd;
ev.events = EPOLLIN;
printf("Listening...\n");
printf("Adding to epoll..\n");
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, listen_fd, &ev);
printf("Return status of epoll_ctl: %d\n",ret);
printf("Allocating memory for events.");
events = (struct epoll_event *)malloc(sizeof(struct epoll_event)*100);
if(!events) {
perror("malloc");
exit(1);
}
while((ret = epoll_wait(epoll_fd, events, 100, 1000)) >= 0) {
if(ret == 0) {
printf("no events this cycle.\n");
}
else {
for(i=0;i<ret;i++) {
if(events[i].data.fd == listen_fd) {
new_fd = accept(listen_fd, (struct sockaddr *)&theiraddr, &addrsize);
if(new_fd != -1) {
printf("Accepted connection adding to epoll...\n");
ev.data.fd = new_fd;
ev.events = EPOLLIN;
epoll_ctl(epoll_fd, EPOLL_CTL_ADD, new_fd, &ev);
}
}
else {
new_fd = events[i].data.fd;
memset(&read_buf,'\0',1024);
read_bytes = recv(new_fd, &read_buf, 1024, 0);
if(read_bytes==0) {
printf("Closing connection on socket: %d\n",new_fd);
close(new_fd);
continue;
}
printf("Read (%d): %s\n",read_bytes, read_buf);
}
}
}
}
perror("epoll_wait");
return 0;
}
Well, I’ve found the job I’ve been seeking. I’ve just been offered a position at ConnectWise as a PHP developer for the marketing department. This company develops what’s called PSA or Professional Services Automation software. Basically, their software manages and ties together the business aspects of IT companies, i.e.: invoicing, time tracking, help desk, dispatch, CRM, etc. The company seems like a really great place to work and the employees seem genuinely happy. They’ve also been continuously growing for some time. I start on the 24th of October. Wish me luck!
I’ve thought about it before, but until now, I’ve never researched it. Wouldn’t it be nifty to log all your apache logs for various virtual hosts into a MySQL database? Enter mod_log_sql. I was skeptical at first, because it appears there hasn’t been any recent development; however, the module compiled fine and I had no issues getting it to work. This seems like a very powerful tool to me and one that I will quite likely be using in the future. Some easy analytics can now be performed via a SQL shell. Say, for instance, that I want to see all the 404s that happened in the last 24 hours and their respective URIs. How about:
SELECT remote_host,request_uri,time_stamp,virtual_host FROM logs WHERE status=404 AND time_stamp>UNIX_TIMESTAMP()-86400;Or maybe the last 20 hits to a certain host.
SELECT remote_host,request_uri,time_stamp FROM (SELECT remote_host,request_uri,time_stamp FROM logs WHERE virtual_host='paydensutherland.com' ORDER BY time_stamp DESC LIMIT 20) AS tmpTable ORDER BY time_stamp ASCIt seems to me, that I could now roll my own analytics engine in PHP quite a bit easier than it would be if I were to have to parse log files out and do the sorting manually. A project for another day
Well, I got a part time job at Office Depot for the time being. I’m not especially thrilled about the major cut in pay, but I do what I have to. The job itself is not bad either, mostly helping customers find what they need, stocking the shelves and making them look pretty. Speaking of pretty, I also met an extremely bubbly girl who also works there. Hopefully she’s not seeing anyone, because I’d sure like to ask her out sometime. Anyway, until next time. Caio.
A while back I purchased an Acer Aspire H340 home server. I bought this thing to put some 1TB disks in a RAID5 array and store my media. The unit comes pre-installed with Windows Home Server. Needless to say, I immediately installed slackware Linux on it so it would be worthy of my network.
Well, it turns out, when I did this the HDD leds (one per hdd) stopped working. I puzzled over this for a couple of weeks because it really bugged me. After pouring over many technical documents and scouring the net, I found the solution. For those interested, the I/O port to communicate with this thing is 0×800 and spans over 0x7f bytes. There are also a couple of important offsets. General purpose register 1 and general purpose register 5 have to do with the LEDs. So, 0×800 + 0x4b = GP1 and 0×800 + 0x4f = GP5. With some fiddling around, I deduced the individual LED bits for both red and blue and wrote a little program to monitor disk activity and report it accordingly via the LEDs. You can find the program on my git repository: http://git.obfuskate.com/?p=hdd.git;a=summary.
Cheers.
Just playing around with some cgi written in the C language. I have a project in the making so I decided to set up the environment and start playing a little. Came up with a nifty urldecode function for decoding urlencoded strings. You know, like ?name=whatever&msg=This%20is%20url%20encoded%3F. Which consequently comes out as ‘?name=whatever&msg=This is url encoded?’. Well anyway, here’s the function just for kicks.
Say you had a pointer to string, *str, that contained the above urlencoded text.
char *decoded=NULL;
decoded=urldecode(str);
printf(“Urldecoded: %s\n”,decoded);
free(decoded); //release allocated memory
decoded=NULL; //no dangling pointers
//Returns a pointer to newly allocated memory containing decoded string. Remember to free() after use.
char *urldecode(char *s) {
char *s2=(char *)malloc(sizeof(char)*(strlen(s)+1));
char tmp;
int x=0,y=0;
int shift[2];
shift[0]=shift[1]=0;
memset(s2,’\0′,strlen(s)+1);
while(*(s+x)!=’\0′) {
switch(*(s+x)) {
case ‘%’:
tmp=*(s+x+1);
if(tmp>=’0′ && tmp<='9') {
shift[0]=atoi(&tmp);
}
else if(tmp>=’a’ && tmp<='f') {
shift[0]=(int)tmp-87;
}
else if (tmp>=’A’ && tmp<='F') {
shift[0]=(int)tmp-55;
}
tmp=*(s+x+2);
if(tmp>=’0′ && tmp<='9') {
shift[1]=atoi(&tmp);
}
else if(tmp>=’a’ && tmp<='f') {
shift[1]=(int)tmp-87;
}
else if(tmp>=’A’ && tmp<=’F') {
shift[1]=(int)tmp-55;
}
shift[0]<<=4; //Shift four bits left for upper half of hex value
x+=2;
*(s2+y)=shift[0]|shift[1];
break;
case ‘+’:
*(s2+y)=0×20;
break;
default:
*(s2+y)=*(s+x);
}
x++;
y++;
}
*(s2+y)=’\0′;
return s2;
}
Well, I’ve not done any serious changes to the AjaxChat plugin in quite some time. I think it’s time to add some new features and shake things up a bit. Maybe I’ve learned a little bit since last I worked on this project, so cross your fingers for some cooler features
. Also, if you have feature recommendations yourself, please just leave a comment here so I can check it out. Ich muss jetzt arbeiten.