“Are Borderline Blogs Useful for BPD Patients?”

The internet has become all pervasive these days. There is hardly any area of life, which is left untouched by the World Wide Web. It is unsurprising then that the internet is also a useful resource in the domain of mental health problems such as Borderline Personality Disorder. While medical treatment and therapies have their own place, many BPD patients also look for other resources to help them improve their lifestyle and successfully return to the mainstream. Find out whether Borderline blogs can be useful for BPD sufferers.

I just re-discovered Virtual Machines and they are awesome!

I started playing with an Ubuntu Server VM in Virtual Box today and my first and immediate thought:
- Snapshots are incredibly cool. We can set everything up at a base-level, and create a “snapshot”. Then, we can experiment with a build and if anything breaks, we can easily reset to my baseline snapshot.

- We can create a base development environment for a project. This would make it easy to bring on new team members and set them up with a dev machine. Just give them the dev VirtualBox image and we’re good to go!

- Every project can have it’s own VM! A nice, sandbox to develop out of. This lets each project to have it’s own OS, database, and web-server, and any supporting software. This lets you run more than one project at a time, without needing to worry about dependency or version conflicts.

You’ve been missing out when you arrive late to a party and it is still going on in full force.

An introduction to aquaponics

A couple of years ago I watched Dan Barber’s TED talk on sustainable aquaculture, which got me interested in environmentally friendly food production.

Six months ago, I became interested in aquaponics. I was trying to find a way to get involved in environmentally friendly food production. Other than cultivating a permaculture forest, aquaponics is the next most resource friendly method of producing food.

Here’s an explanation of aquaponics – what it is and how it works!.

Starting new projects and making them succeed

Congratulations! You’ve found that new thing. The idea that you’re going to work on! It’ll make you rich! Famous! Powerful! It’ll make your world a better place! It is perfectly inline with everything you want.

It is rare to find such a project – one that speaks to us in all the right ways – one with the right balance of upsides to match our personality. The downside – the potential hit, should we fail, to our finances and image, is also important to consider. There is also the time lost in pursuing a failed project.

There’s so much to do before your project is complete! Very exciting!
Minimizing risk – minimizing the chance of failure increases our chances of success. Things like research, planning, building, outreach, supporting… there’s so much to do. There’s a good chance that you suck at some of it. There’s an even bigger chance that a bunch of these are really, really boring. Like, “can’t someone else do it, Moe?” boring.

If it helps, think about doing the boring tasks as reducing your risk of failure. There’s also a good chance that there are others that are willing to do the boring stuff. There’s a good chance that they’re excited by tasks that you find boring! It may be worthwhile to find these people and compensate them for their help.

To reduce the risk of losing all your money, many very successful people suggest on doing lots of research, and starting small. To avoid losing face, minimize publicity until the risk of failure has been reduced. More specifically, we should avoid spreading the word until the project needs help or until the chances of the project’s success are believable.

“A beginning is the time for taking the most delicate care that the balances are correct.” from Frank Herbert’s, Dune.

“There was once a dream that was Rome. You could only whisper it. Anything more than a whisper and it would vanish… it was so fragile. And I fear that it will not survive the winter.”. – Marcus Aurelius in the movie, Gladiator.

There’s an excitement around each new project. It is the fuel that keeps the fire burning. But publicly stating your intentions may work against you – you may no longer be as excited, you may gain competitors, you may gain unwanted opinions too early on. It will also no longer be a new idea in the public mind and not being new makes it less fresh. On the other hand, not telling anyone means not having anyone else who believes in you, or gaining constructive criticism or guidance.

In this new year, I wish you and yours wonderful new ideas and the resources to see them complete and the returns to call them successful! =)

How to do fullscreen in JavaScript and CSS

I’ve been using the YouTube JavaScript Player API for a project. Something that I needed to figure out was how to create fullscreen controls for my custom video player. Here’s how:

Take the element (probably a div) to be full-screened, and full-screen it with the following JavaScript:

var c = document.getElementById('id_of_div_being_fullscreened'); 
// Browser specific fullscreening:
if (c.requestFullScreen) {
  c.requestFullScreen();
} else if (c.mozRequestFullScreen) {
  c.mozRequestFullScreen();
} else if (c.webkitRequestFullScreen) {
  c.webkitRequestFullScreen();
}

Now, what happens is fun. We can assign CSS properties to elements that are different in full-screen mode than regular mode. When in full-screen mode, the browser adds a class name of :-webkit-full-screen to full-screened elements. There’s probably one for Firefox called :-moz-full-screen, and one for other browsers called :-full-screen. How to use it:

  .MyPlayer:-webkit-full-screen {
    margin-top:0px;
    display:block;
    width:100%;
  }

  .MyPlayer:-webkit-full-screen .DefaultControls {
    z-index:2;
    display:block;
    top: 0px;
    position:absolute;
  }

As an aside: I noticed something while browsing through videos on Vimeo and YouTube: in this day of excellent HTML5 video, they still use Flash. Why? Because the Flash experience is the same across all browsers. When we try to full-screen a video, regardless of browser, the video instantly becomes full-screen, along with the controls, which behave appropriately. I bet the folks that worked on the Flash control don’t have to worry about detecting what browser the user is in.

Some things to remember when writing Chrome extensions (Part 2):

I recently built a chrome extension. It maps craigslist housing searches onto a map. This is a two part blog post on a few things I’ll keep in mind when writing more Chrome extensions. This is the second post and will talk about specifics about how different parts communicate with each other. Of course the official api reference probably does a better job, but this summary is as much for me as it is for you.

Message passing and organization:
This is the part that took the longest to understand because there a bunch of commands provided for sending messages between content scripts, background scripts, outside scripts, inside scripts, scripts that your grandma wrote and that doctor’s prescription for your hamster’s stress knee pain.

So here’s how I did it. Two parts to each message – sending, and receiving:
From a content script to a background script:
In the background.js, the following umbrella method:

"chrome.extension.onRequest.addListener"

.
In the content.js, the following single call:

chrome.extension.sendRequest('data', function (response) {/* do stuff if needed */});

From the background script to content:
In the background.js, a single call with:

chrome.tabs.sendMessage(tab.id, {message: 'addAdToMap', data: this.adData}, function() {/* do stuff if needed */});

The following umbrella method to handle them all in the content.js:

chrome.extension.onMessage.addListener( function(request, sender, response)

From content scripts to iframes that live inside the content
Whoa. Doube-you Tee Eff, mate. Why would you do this? Why, I’m glad you asked: The reason you’d want to is because Chrome is a bully that protects you from bullies. Seriously this made me refactor my whole extension.
From the content window to the iframe:
In the content.js:

mapAway = function(location, data) {  
  var iframe = document.getElementById('mapFrame');
  var message = {
    command: 'mapMe',
    mapData: {
      mapLocation: location,
      mapData: data
    }
  };
  iframe.contentWindow.postMessage(message, '*');
}

In the iframe’s js, the following umbrella method:

window.addEventListener("message", function(event) {

From iframe to content scripts the following:
In the iframe.js:

  var message = {
    command: 'ready'
  }
  window.parent.postMessage(message, '*');

In the content.js the following umbrella method:

window.addEventListener("message", function(event) {

More to come as I think. I almost feel like this post is therapy for me and help for you. And help for me the next time I write an extension. Also, here’s the code to my extension. It makes use of all the different types of message passing described above. So, I hope it helps!

Some things to remember when writing Chrome extensions (Part 1):

I recently built a chrome extension. It maps craigslist housing searches onto a map. This is a two part blog post on a few things I’ll keep in mind when writing more Chrome extensions. This is the first post and will talk about parts of a chrome extension and where to put code. Of course the official documentation probably does a better job, but this summary is as much for me as it is for you.

Each Chrome extension has the following files:
- manifest.js: This file will contain basic but important information about the extension, such as it’s name, description, any files being included, websites when the extension will come alive, as well as be able to make cross-site requests, as well as security considerations.
- background.js: This file is your grand daddy. It orchestrates communication between the different parts of the system.
- Other JavaScript files: These files represent what will happen inside different content views – page actions, browser actions, tabs etc.

Code organization:
background.js – Anything that the browser does, such as opening new tabs, placing buttons, assigning action to a browser button and so on, is handled by background.js.
some_content_script.js – You guessed it! Things that happen inside the content of a window – basically whatever happens inside the html tags is handled by some content js.

Rails model without corresponding database tables

Lately, I’ve been fortunate enough to contribute to Dot429. It is, among other things, a great place for the LGBT community and their supporters to connect, discuss business and mentor each other.

One of the mini-projects, a contest, required us to ask for a telephone number, but in three separate fields: (area-code), (first three digits), (last four digits). Once the fields were accepted and validated, they were to be concatenated and stored in the database.

Rails makes this very easy: just add the accessors for non-database fields and validate them as we normally would through the built in validators:

  attr_accessor :phone_area, :phone_part_one, :phone_part_two
  attr_accessible :phone_area, :phone_part_one, :phone_part_two
  validates_presence_of :phone_area, :phone_part_one, :phone_part_two, :message => 'Please provide your phone number.'
  validates_format_of :phone_area, :with => /^[0-9]{3}$/, :message => 'Please enter the phone number in Digits 0 - 9'
  validates_format_of :phone_part_one, :with => /^[0-9]{3}$/, :message => 'Please enter the phone number in Digits 0 - 9'
  validates_format_of :phone_part_two, :with => /^[0-9]{4}$/, :message => 'Please enter the phone number in Digits 0 - 9'

When the save() function is called in the controller, the model should validate just fine, even if the particular fields do not correspond to columns in the database.

Now, what if we want to make use of validators for a model that has no table in the database?
Rails throws its arms in the air if you do the above but for a model that has no corresponding database table. The solution is simple: create a dummy table. This, in my opinion, is the simplest solution to the problem because it makes Rails happy. We can even create one dummy talble and associate it to any model that does not have a corresponding database table. Like so:

class Contact < ActiveRecord::Base
  set_table_name :the_empty
  attr_accessor :phone_area, :phone_part_one, :phone_part_two
  attr_accessible :phone_area, :phone_part_one, :phone_part_two
  validates_presence_of :phone_area, :phone_part_one, :phone_part_two, :message => 'Please provide your phone number.'
  validates_format_of :phone_area, :with => /^[0-9]{3}$/, :message => 'Please enter the phone number in Digits 0 - 9'
  validates_format_of :phone_part_one, :with => /^[0-9]{3}$/, :message => 'Please enter the phone number in Digits 0 - 9'
  validates_format_of :phone_part_two, :with => /^[0-9]{4}$/, :message => 'Please enter the phone number in Digits 0 - 9'
end

The first line in our model’s declaration attaches the model with our dummy table. Now we have all the advantages of a regular rails model, without the need to store it.

Here’s the rest of the code from the test project that I created:

# Routes
ActionController::Routing::Routes.draw do |map|
  map.resources :contacts, :member => { :new => :get, :create => :post }
end

# Migration
class CreateContacts < ActiveRecord::Migration
  def self.up
    create_table :the_empty do |t|
    end
  end

  def self.down
    drop_table :the_empty
  end
end

# Contact Controller
class ContactsController < ApplicationController
  def new
    @contact = Contact.new(params[:contact])
    @message = params[:message]
    respond_to do |format|
      format.html
    end
  end

  def create
    @contact = Contact.new(params[:contact])    
    respond_to do |format|
      if @contact.valid?
        phone = "You entered: (#{@contact.phone_area}) #{@contact.phone_part_one} - #{@contact.phone_part_two}"
        format.html { redirect_to :action => :new, :params => {:message => "#{phone}"} }
      else
        message = "Error: #{flash[:error] = @contact.errors.first[1]}"
        format.html { redirect_to :action => :new, :params => {:message => "#{message}"} }
      end
    end
  end
end

<!-- Contact Form -->
<% form_for :contact, :url => contacts_path do |f| %>
  <% if @message %>
  <div><%=@message%></div>
  <% end %>
  <span id="phone_help_text">Phone Number:</span>
  <%= f.text_field :phone_area, :minlength => 3, :maxlength => 3, :tabindex => 6 %>
  <%= f.text_field :phone_part_one, :minlength => 3, :maxlength => 3, :tabindex => 7 %>
  <%= f.text_field :phone_part_two, :minlength => 4, :maxlength => 4, :tabindex => 8 %>
  <%= f.submit %>
<% end %>

When was the last time you went to the library?

I recently moved to Daly City and have been going to the Mission in San Francisco to work – they have some wonderful cafes over there; I mostly go because I’d rather work from outside the house than drink coffee.

On the way back (I took the subway back) I noticed the a public library – it is only a ten minute walk from the house. So here I am, at the library today – it is fairly quiet but not eerily silent, there are others here working and studying – usually older folks, college students and a few kids off in the distance being kids.

The desks are excellent, just perfect for a laptop! There are lots of wall sockets, good Wifi, tons of books if you need a break. Since not many people use the library these days, there is plenty of empty space here – many empty desks – great place for a team. They also have meeting rooms. Oh, and did I mention that all of this is available for free?

Use OSX as an alarm clock with iTunes, AppleScript, iCal or crontab and Energy Saver

Update: Follow this tutorial for Spotify, instead of iTunes

What if none of the alarm clock apps for OSX work just the way we want them? My favorite app until a couple of hours ago was Robbie Hanson’s excellent Alarm Clock 2 app to wake me up. It is simple, intuitive and did exactly what I needed, which was to let me pick a song from my iTunes and set it as my repeating alarm. But then it couldn’t play Soma.fm streams, which iTunes gladly plays.

Luckily OSX comes with excellent built-in tools to make it play the awesome internet radio at 10am.
Here are the steps:

  1. First, create a playlist using iTunes and add music to it.
  2. Now, lets tell our Mac what we want it to do: Open AppleScript Editor. It should open a new script editor window. Paste the following code – be sure to replace MY_PLAYLIST with the name of our iTunes playlist.
    set volume 10
    tell application "iTunes"
    	set the sound volume to 0
    	play user playlist "MY_PLAYLIST"
    	repeat 10 times
    		if sound volume is less than 100 then
    			set sound volume to (sound volume + 10)
    			delay 3
    		end if
    	end repeat
    end tell
    

    The AppleScript is very easy to read. We first set the computer’s volume to full, then start iTunes and tell it to set the volume to 0. Then we tell it to play a playlist. Finally, we gradually increase the volume.
    Go ahead and press the “Compile” button, and then the “Run” button to test out the script. iTunes should fire up and start playing the desired playlist.
    . Now save the script to an appropriate location – I put mine in my home directory (/Users/Vishal/) and called it alarm_clock. AppleScript will save it with a .scpt extension, so it might look like alarm_clock.scpt, depending on our display settings.

  3. We now need to do two things: First, we must schedule a time for our alarm_clock script to run everyday at our chosen time, and then we need to make sure that our computer starts up on time for the script to actually run on time! Lets tackle the scheduling first.
  4. We have two choices for this step: the easy way using iCal that Joachim suggested, or the crontab way, which involves some Unix magic!
  5. The iCal way
    Simply, open iCal and create an event. Set the event to start at our preferred wake-up time (10am), and set the alarm to Run Script and select our AppleScript (in my case, alarm_clock). Thats it! Lets skip the crontab, and move onto the final step.
  6. Alternatively, the crontab way:
    We are going to use crontab to schedule our alarm clock. Open up Terminal. What we are going to do now is open up the scheduler file in a text editor, and enter a line for our alarm clock to run at the appropriate time. Here is what the crontab line’s format is:

    MM HH dd mm ww osascript /Path/to/alarm clock script.scpt

    Here MM stands for Minte, HH, stands for hour, dd for day of month, mm for month and ww for day of week. osascript is a program that lets us run AppleScript files from the command line. And finally we will want to enter the path to our alarm clock script. Start crontab’s editor:

    crontab -e

    If we have never done this before, then we are most likely in the vi editor. By default, the vi editor does not let us enter text. Press i to enter insert-mode. Now lets start typing in our crontab entry. Here’s what mine looks like:

    00 10 * * * osascript /Users/eyce/alarm_clock.scpt

    Thats right. I plan to wake up at 10:00am every day! The *’s represent wild-card entries meaning every day / month / day of the week.
    Now, when we’re happy with the line, press Escape to get out of insert-mode, and then type in :wq and press enter. This will save the crontab settings and quit the editor. Lets type in crontab -l and press Enter and crontab should show us our new settings.
    We are done in Terminal and can type in exit and press Enter to end the Terminal session and finally quit the Terminal.

  7. For the last step, we are ready to tell our system to wake up at the right time for our crontab or iCal event to run our AppleScript to run iTunes at the right time! Lets go into System Preferences, then Energy Saver. Lets press the Schedule button and set the wake-up time to about 5 minutes before our actual alarm is supposed to go off. In my case, since my alarm is set for 10am, I set the scheduler to turn my macbook on at 9:55am.

And that is all! =). The computer should start up, along with the cron/iCal event, and then the AppleScript, which will start iTunes with our favorite playlist at 10am! Or, whatever time you set yours for ;-)

Next Page »