RSS
 

Kill a process in Mac OS X from the terminal command line

14 Oct

It can sometimes be necessary to kill a process in Mac OSX. We’ve all tried it.
To kill a process or program in the Mac OSX Leopard / Snow leopard / Lion do the following commands

ps -A | grep [name of program you want to close]

This will give you the number of the processes found (if any). Now just close them with this command

kill -9 [process id]

So, for example to kill my activity monitor program

ps -A | grep activity
39049 ??         0:01.81 /Applications/Utilities/Activity Monitor.app/Contents/MacOS/activitymonitord
kill -9 39049
 
No Comments

Posted in Mac

 

Rails 3.1 Redirect back to controller after custom authentication

12 Oct

If, like me, and Ryan Bates, you like doing the important things yourself, so that if there are errors, they’re your errors, chances are you will want to create your Rails authentication from scratch yourself. Ryan of Railscasts has an excellent screencast about this.

I switched from Devise to this in a breeze, and then comes the customization. One of these is the all-important redirecting back to the funnel a user came from after they are done signing in, or up. This can actually be achieved very easily, following some
Devise conventions.

Say I have a CharitiesController, that I want to close to unauthenticated users. In line with Devise, I would do this to force them to authenticate:

class CharitiesController < ApplicationController
  before_filter :authenticate_user!, :except => [:show, :index]

And in my ApplicationController, given i have set the user sign in route to user_login, I can define a return point:

class ApplicationController < ActionController::Base
  def authenticate_user!(return_point = request.url)
    unless user_signed_in?
    set_return_point(return_point)
    redirect_to user_login_path
  end
  def return_point
    session[:return_point] ? session[:return_point] : root_path
  end
end

And then, in my UserSessionsController, I can redirect the user back to the return point:

class UserSessionsController < ApplicationController
  def create
    user = User.find_by_email(params[:email])
    if user and user.authenticate(params[:password])
      session[:user_id] = user.id
      redirect_to return_point, :notice => "You are now signed in"
    end
  end
[...]

Now, whenever a controller calls authenticate_user!, my ApplicationController will save the calling URL before redirecting to the login page, and by fetching return_point from the UserSessionsController, I can redirect them back to that page. I can even override it, such that I can send them wherever I want, should I so desire. Awesome!

 

Carrierwave with Rails 3.1 upgrade

12 Oct

So I had some trouble with Activesupport and CarrierWave when upgrading to Rails 3.1, so I’m putting my solution here, hopefully for others to enjoy. I got this error:

Bundler could not find compatible versions for gem “activesupport”:
In Gemfile:
rails (= 3.1.1) depends on
activesupport (= 3.1.1)

carrierwave depends on
activesupport (3.0.10)

And the solutions was to do the bundle update command

bundle update

Or, if you like me are using rvm

rvmsudo bundle update

And now everything works just perfect ^^

 

Rails 3 Magic Migrations

23 Sep

I Always forget what the Magic Migrations (migration generator names that automatically populate the migration with code) in Rails 3 are, so I thought I’d scratch my own itch and post them here for me (okay, and others) to find:

Rails 3 Magic Migrations

 

CreateSchemaName field1:type field2:type
 
AddColumnColumnNameToSchemaName field1:type field2:type
 
RemoveColumnNameFromSchemaName field1:type field2:type

 

 

 
 

The best Ruby on Rails book

13 Mar

I have found a book that is really great. The best beginners’ book for Ruby on Rails 3 to me: The Rails 3 Tutorial book

I’m always learning new programming languages for projects (just have a look at the books ive read so far), and though they’re often very similar, a good book is essential to me in grasping new languages quickly.  For Rails, I started with Agile Web Development with Rails by the Pragmatic guys, but found that it was way too problem-specific and not giving enough real rails knowledge. So i went back to the official guides, which are very, very, very good.

Now, however, I have found what I was looking for: The Rails 3 Tutorial book

And to sweeten the deal, you can read it online for free (though I bought and printed it – you just cant beat the reusability of a book that you’ve underlined yourself) and there’s even a bunch of screencasts to further your education after reading the book.

Thank you Michael Hartl

 
 

Meowgle – Google with kittens. LOTS of kittens

03 Jan

Do you like kittens? I know, who doesn’t, right?

On Meowgle.com you can get your standard Google search, only wrapped in wonderful Kitten pictures. There’s a new kitten image and video every day, so you can start the day with a cute little fluffy kitten :)

Meowgle - Google with kittens

Meowgle - Google with kittens

 
 

Diablo 3 release date info page

03 Jan

So I’m pretty excited about Diablo 3 coming out this year, and decided to create a page dedicated to that most important of dates, the release date. So head on over, and check out my Diablo 3 Release Date page – I think it’s the most stylish one out there :-)

Screenshot

 
 

Rails 3 Cucumber and webrat “undefined method” error fix

03 Dec

So, I recently started using Rails 3, and I am running my test with the awesome Cucumber framework, and Webrat. To set it up in Rails 3, however, I had to apply a little fix, because my
task kept giving me this lovely error

1
undefined method `fill_in' for # (NoMethodError)

Now, the fix for this is very easy – you go to your “env.rb” file under features/support, and change :rails to :rack, like this:

1
2
3
4
Webrat.configure do |config|
  config.mode = :rack
  config.open_error_files = false # Set to true if you want error pages to pop up in the browser
end

And presto! It works!

 
 

SEO Guide for Drupal and other websites

12 Nov

SEO Guide

So I created a basic SEO guide to help webmasters (Drupal in particular) increase their SEO and search engine ranking.

Top Elements of SEO

Ordered by importance

  1. Incoming links (links from other domains) are the most important contributor to SE ranking with Google. Generally it is more important to have quality of links than quantity. Few high-quality links are better than many low-quality, and many high-quality links are best. The important factors are:
    1. The Pagerank of the site linking to you
    2. The relevance of the site linking to you. Sites with a similar content theme will elevate your ranking for their ranked keywords. Sites with a theme different from your site will dilute your keyword relevance.
      Note: One or two sites with a different theme are irrelevant. Only incoming link tendencies are important. As always, the higher the pagerank of the site linking in, the higher the importance of the link.
    3. The link label of the incoming link (e.g. SEO guide for Drupal)
      The link above links to basico’s page, and elevates the site’s ranking for the keywords (search words) Drupal and SEO
  2. On-page keywords. These are the words you want people to find you by when entering a search phrase in Google. E.g. “Drupal SEO” The important keywords here are Drupal and SEO, so these must be used in pages on the site that you want your users to find. The important places to use the keywords are:
    1. Page title: The title shown in the top of the browser window when viewing a page
      1. Note: Page title is not equal to headings in the document content
    2. Keywords in path: Having the keywords to rank for in the URL (e.g. blog.houen.net/seo/seo-guide-for-drupal-and-other-websites)
      1. The above URL will elevate the ranking for SEO, Drupal, guide and websites.
    3. Heading: The part of the page’s content that is wrapped in a <h1> tag
    4. Emphasized body parts: Parts of the text enclosed in the <strong> tag
    5. General mention of keywords in text.
  3. Internal links (links from other content on your own domain) should be treated like incoming links, albeit with less relevance.
    1. While links internally on your site are nowhere near as important as incoming links, they are still relevant.
  4. Sitemap
    1. A XML sitemap will tell SE’s what content you have an index it all. This is automatically generated and updated by Drupal if you have the XML Sitemap module installed.

Keyword considerations

  1. Research keywords by using google’s keyword tool
    1. Use this tool to find the keywords searched most by people relevant as customers for you.
  2. Do not target a page (one page in the website with a unique URL) towards too many keywords. This is always a trade-off. Google ranking is most determined by incoming link strength. This is divided by the number of keywords targeted in a page. The more different keywords, the less strength each will receive.
    More keywords means a page will target more searches, but have a harder time ranking top for each of them.
  3. Do not stuff a page# with too many mentions of the same keyword. 2-3 mentions of a keyword is sufficient, and too many will hurt SE ranking. If wondering if a page has too many or too few mentions of a keyword, use the following golden rule: Does the keywords flow naturally with the content?
    While this may seem superficial, this is exactly what Google attempts to determine. A page is most relevant if it is on topic without pretending to be something it isn’t.

    Note: Synonyms of keywords are regarded as the same keywords, but without incurring the same stuffing penalty. Using synonyms will work positively towards keyword ranking.

Targeting keywords

This section will assume that desired keywords for a page are already determined, and will give an outline of how to target them within Drupal with the modules Page Title, Nodewords, Pathauto, XML sitemap, Global Redirect, Path redirect, Site map, Search 404 Installed.

Go to the editing section of the page you wish to SEO-boost, and edit the following:

Title
Give the page a title containing the desired keywords.

Meta tags

  • Description
    • The description is the field most search engines (including Google) will use to display a little example text to the user. This is where the user should be caught by the site when they see it in search listings.
  • Keywords
    • Meta keywords used to be the main source of info for search engines. Not anymore. It is discussed whether having your keywords listed here will affect your site ranking at all. It is rumored to have an impact on Yahoo ranking. I recommend listing the page’s keywords here, if nothing else, then just to have them listed for later reference.
  • Robots
    • This section of Meta tags is largely irrelevant, but the NOINDEX option can be used for pages that you dont want listed in SE’s. When this tag is set to NOINDEX, most search engines will disregard the page (note: some SE’s still index it.)
  • URL redirects
    • As will be discussed under “SEO Pitfalls”, having duplicate content is the single worst “White hat#” SEO thing you can do to your Google ranking. This is of course mainly targeted towards duplicating other people’s content on the web, but also refers to having duplicate content within your own site, such as two pages having the same content.If you want to have a page listed by two different URLs, or have a large amount of incoming links to a URL that is no longer valid, instead of creating a new page at the URL (creating duplicate content), you want to use URL redirects and add a redirect from the invalid URL to the page you are editing.
  • Body
    • Use the keywords when relevant in the the textual content of the page, preferably in boldface text.

SEO pitfalls

SEO pitfalls are practices that will effectively hurt your SEO ranking. Avoid these whenever possible:

Link stuffing

As discussed above, dont overdo keyword mentions. Keep the text flowing naturally.

Broken links

Broken links are links from your own, or other domains that link to nonexistant pages. These will hurt your SEO ranking, and irritate users trying to reach your site.

  • To find internal broken links, use the “Broken links” report within Drupal and fix the links on the reported pages
    • Disregard broken links in the report starting with “http://testcms.basico.dk” – these are a remnant of the development phase and no longer an issue.
  • To find incoming broken links, use the “Top page not found errors” report, and create URL redirects for top the missing URLs to the relevant pages.
    • Always set URL redirects to 301 status. This tells search engines that the move is permanent, and that it is not duplicate content.
    • Use common sense when searching for broken links. Anything not a URL to a page that is missing can be disregarded (such as AutoDiscover/AutoDiscover.xml which is an automatic web indexer trying to find a weird xml document)

Links

To read more about SEO factors, take a look at this site
SEO factors investigation

I would also very much recommend signing up for the Hobo SEO newsletter (signup in right side)

 
No Comments

Posted in SEO

 

Actionscript 3 using string or integer to access variables

18 Aug

Here’s a situation I often run into: Having a set of variables that are almost alike, but differ in number. For example:

1
2
var textbox1:TextField;
var textbox2:TextField;

Now say I have a function that needs to change these based on a number in another variable. I could do a switch to access them, but that would be repeating myself. Instead I can just access them through my string or integer variable like this:

1
2
var num:int = 1;
trace(this["textbox" + num])

You could, for instance use it to loop over your variables:

1
2
3
4
5
function update_textfield() {
   for each(var i:int = 5; i < something; i++) {
      trace(this["textbox" + i])
   }
}

And presto! Easily accessable variables :)