bensangeorge.com

Drupal bits: Migrating remote files in Drupal

without comments

Recently I had to import a set of remote image files from another server but was not absolutely clear on how to get this done the Drupal way. I found the really came up with a solution of my own with drupal_http_request() which accepts an incoming URL and then executes a HTTP client request. The function returns the data and the response code.

  1. $binary_image = drupal_http_request($url);

After checking the response code to make sure it was successful, use the Drupal function file_save_data() to physically store the file into whatever directory you want to store the image file in.

  1. if ($binary_image->code == 200) {
  2. $filepath = file_save_data($binary_image->data, $save_to, FILE_EXISTS_RENAME);
  3. if ($filepath !== 0) {
  4. // attach other relevant information as well
  5. $fileinfo[‘filepath’] = $filepath;
  6. $fileinfo[‘filesize’] = filesize($save_to);
  7. $fileinfo = array_merge($fileinfo, getimagesize($save_to));
  8. return $fileinfo;
  9. }

The physical file should be saved but just because you’ve saved the file in the directory does not mean that Drupal is aware of the file. In order for that to happen, you also need the mime type, the file size, and the filepath and manually insert into a node. Once you’ve got those, you can create a node and insert those values along with the rest into it.

  1. // create a node
  2. // add the file’s information into the node
  3. $node[‘field_thumbnail’] = array(
  4. ‘list’ => 1,
  5. ‘data’ => array(
  6. ‘alt’ => ,
  7. ‘title’ => ,
  8. ),
  9. ‘fid’ => $fid,
  10. ‘uid’ => $user->uid,
  11. ‘filename’ => $resource[‘logo_file’],
  12. ‘filepath’ => ‘files/_thumbnails/’.$resource[‘logo_file’],
  13. ‘filemime’ => $info[‘mime’],
  14. ‘filesize’ => $info[‘filesize’],
  15. ’status’ => 1,
  16. ‘timestamp’ => time(),
  17. ‘alt’ => ,
  18. ‘title’ => ,
  19. ‘upload’ => ,
  20. ),

This will make Drupal recognize your files. Everything should be gravy. Hope this works for you.

By the way, for all of you already on Drupal 7(lucky you), file_save_data() saves the data and automatically updates the database with the file information.

Written by bensan

June 27th, 2009 at 10:45 pm

Microsoft Twitter fail

without comments

tweetie

I tweeted about the fact Microsoft was running a marketing campaign that gives a web site user a chance at winning ten grand. The catch? You will only be able to use Microsoft IE8. Leaving the obvious user agent switching hacks aside, I was still shocked that Microsoft thought this was in anyway good marketing so I tweeted about it.

Within a few hours, Microsoft’s Twitter account re-tweeted my rant about their ten grand contest. :-O I don’t really know what they were trying to go for here but it certainly had my co-workers and I laughing hard about it. My best explanation for this is that MS had a Twitter bot that scanned all tweets with the word Microsoft. Too bad they didn’t see the word fail right next to it.

I tried to get Microsoft to RT another not-so-flattering message but it didn’t work again. Ah well.

Good ole’ Microsoft. <sigh>

Written by bensan

June 24th, 2009 at 11:25 pm

Drupal Bits: Views 2 Relationships

without comments

In around 8 minutes, I understood the concept of Views 2 Relationships by watching this video. Relationships helps you connect relate (duh) nodes to other nodes. In short, it is probably most helpful to think about this as a SQL join.

Check out this video from drewish.com for the screencast:

http://drewish.com/node/127

Written by bensan

June 16th, 2009 at 5:56 pm

Posted in bensangeorge

Tagged with ,

Book Review of “The Passionate Programmer”

without comments

For developers that are really interested in steering their IT career instead of having their career steered for them, “The Passionate Programmer” is a must have. This book is a revision of My Job went to India. While some of it is relevant information on how to compete in a global development market, it is also talks about how to really make yourself a valuable asset to your organization. One of the more interesting ideas in the book is to not count on your technical skillsets to make yourself valuable but to start knowing your business. In other words, your business does not care if you are love working with Python or PHP but rather can you get the job done and do you know enough about your business domain. Seems extremely trite but for techies, it takes a while to get used to the idea. You can get this book at pragprog.com. Hope it raises your level of thinking about your tech career as it did mine.

Written by bensan

May 20th, 2009 at 2:06 pm

Posted in book reviews, software

The future of Drupal (as envisioned by Lullabot!)

without comments

Fascinating glimpse into an alternate view of the enriched UI experienced spearheaded by Lullabot. This is a separate project than the “offical” Drupal 7UX project. I am excited at the prospect of Drupal having a very friendly user experience. Enjoy!

project buzzr

Written by bensan

April 14th, 2009 at 1:36 am

Posted in software

Tagged with

dumping mysql and importing mysql

without comments

One thing that a developer has to do during the course of a project is to export a mysql database so that he can set up a new development environment, transfer data, etc.

In mysql, the mysqldump command works great for this:
mysqldump –verbose -user -h [hostname] -p[password] [database_name] > file.sql

When importing a sql file, just go the other way:

mysql -u [username] –verbose -p[password] -h [hostname] [database_name] < file.sql

This two commands will make importing and exporting databases a snap.

Written by bensan

March 30th, 2009 at 2:13 pm

Launching Running Expo 2.0

without comments

running expo screenshot

Do you love to run or jog? Training for a marathon or 5K? Running Expo allows you to connect with the Facebook user community and create your own digital running route information using Google Maps. Users can search on nearby routes that other people have saved against their profiles as well. For security purposes, we made sure that all routes have access levels. Each route can be made viewable by everyone that is using the Facebook application [public], seen only by your Facebook friends [shared], or be viewable only by you[private].

The future of this project looks bright. A big shout-out to the lead developer of the app, Seth Cardoza for having the vision and bringing me on board. For now, one of the main responsibilities that I will have is to make sure that the word gets out about Running Expo and getting other people to realize it’s value in the Facebook app-space. Without giving away too much, the primary focus of the next iteration will be to hook integrate much deeper with the Facebook platform. So stay tuned.

Please look around and let me know what you think. I would love to hear some feedback. Hope you like the app as much as I enjoyed making it!

Written by bensan

February 26th, 2009 at 5:11 am

Keeping an engineering notebook

with 4 comments

If you took a lab in college like I did, you’d probably know how much your professors forced students to keep an engineering notebook. Well, it turns out that keeping an engineering notebook really pays off significantly. There’s a lot to gain by keeping a documented account of your work.

It helps you record your solutions and store it in one centralized location. How many times have you come across the same problem when working and not recall that pivotal eureka moment that let you arrive at your solution? Even if your solution is not made explicity in your notebook, even retracing  the steps taken to achieve your answer will help you jog your memory faster than anything else can.

Engineering notebooks can help you to reveal previous trends. The items that wasn’t so obvious when you are in the thick of it. Things such as individual workflow habits and the effort spent on each task.ruled-moleskine-pic

Documents a history of work as evidence Working in a creative role, it is sometimes hard to quantify your level of effort against a certain task or group of tasks. When it comes to software development, it seems there are always items that have not been taken into account of in the official project plan. We’ve all been there. There’s always “that one other thing” you have to do before you get into the main task at hand. Before you know it , the level of effort it takes to accomplish the periphery tasks snowball out of control. Next thing you know, your boss is hovering over your desk demanding to know why a task that was slated for half a day has been unresolved for a week. An engineering notebook can help you persuade them by showing them exactly how much effort is going into finding a solution. (Of course, it’s your job to estimate tasks responsibly but that’s another topic altogether).

Read the rest of this entry »

Written by bensan

February 13th, 2009 at 5:02 am

How the iPhone helped me navigate NYC

without comments

My brothers and I decided to spend a week in New York city. We went out to Manhattan for a couple of days to soak in some of that “real” New York culture and do a bit of overdue sightseeing. I was really happy that we were going out but none of us really knew where anything was. My iPhone to the rescue…

Google Maps – whether it it is finding the best way to Junior’s cheesecake or figuring out where to get the next E train, Google Maps has earned a place on the first page of my iPhone after this trip. The fact that you can map driving, walking, and metro directions is still completely mind-boggling to me. The ability to swoop down and peek at some real panoramic street view photos is also really helpful when you want to verify that you’re headed to the right place.

Twitterific – Whether I want to broadcast where I was going next, get tips on what I should be checking out in the city, or sharing some quick pictures with my friends, Twitterific is the one tool I used to do it all. What I really liked was Twitterific’s camera feature which allows you to use the built-in iPhone camera interface to send photos right up to Twitpic.com. It also helped me to keep in touch with friends when I am on the go.

Safari – The best mobile browser on the market did not fail to disappoint. Safari proved it’s worth on my phone when I needed to find out phone numbers for the nearest Apple store or when I needed to take a break and check out the latest articles on dzone.com,

These iPhone apps made a huge difference in my nyc vacation. The time that I saved and that sense of security I felt knowing that any piece of information was available to me at anytime(except for when on the subway) really made me feel much more comfortable traversing Manhattan even though I was a complete stranger to it. Now if only I can get my cousins to admit the same thing.

Written by bensan

January 4th, 2009 at 2:14 pm

I am not THAT old, damn it!!

with 4 comments

With every Happy New Year comes the realization that I am going to be another year older on the 2nd of every January. sloppy bday cakeRegardless of what all my friends seem to think about my 28 years of experience, I am very excited about the next year. I have got a lot of personal and professional goals that I have set for myself. Many people are going into 2009 apprehensive about the state of their job but for some reason I have got a very upbeat attitude about the entire thing.

I am learning to live in the present here and now. Here’s to a great year for all of us.

Written by bensan

January 2nd, 2009 at 1:39 pm