rss

Namazu with PHP5 on Linux

1

Category : Featured, PHP

Namazu is a full-text search engine intended for easy use is what the namazu site tells its users. I have already worked on namazu and it worked amazingly fast. Recently i started working on a project having tens & thousands of records and it was cumbersome for MySQL to work efficiently under that much load. I decided to use namazu for that but unfortunately i was working on a windows based platform and its very difficult to configure PHP5 with namazu on windows. I was able to install namazu easily on windows. One can use the CGI mode to use namazu on windows but installing namazu as a PHP extension is difficult at least for me at this time.

But i was able to install namazu on LINUX and was also able to install namazu as a PHP extension on LINUX. While stumbling though site searching for installing namazu with PHP5 i got this link which describes how one can install namazu on LINUX and its PHP extension also.

I will keep on searching how to get namazu as a PHP extension, meanwhile you can use this link to get namazu working on LINUX.

Share

Javascript: Ways to iterate over an array

Category : General

for each in:

JAVASCRIPT:

  1. for each (var item in [1, 2, 3]) alert(item);

JavaScript 1.6 added the Array.forEach method:

JAVASCRIPT:

  1. [1, 2, 3].forEach(function(item) { alert(item) });

JavaScript 1.7 added array comprehensions for array initialization:

JAVASCRIPT:

  1. var squares = [item * item for each (item in [1, 2, 3])];

I just realized I can (ab)use comprehensions to iterate arrays with Perl-like syntax by throwing away the result:

JAVASCRIPT:

  1. [alert(item) for each (item in [1, 2, 3])];

I can iterate object properties the same way:

JAVASCRIPT:

  1. var obj = { foo: 1, bar: 2, baz: 3 };
  2. [alert(name + "=" + obj[name]) for (name in obj)];

Edward Lee points out how to use Iterators:

JAVASCRIPT:

  1. [alert(key + "=" + val) for ([key, val] in Iterator({a:1,b:2,c:3}))]
Share

Rails flash messages helper

2

Category : Ruby on Rails

display_flash(:error) # to display a specific flash message
display_flash # to display all flash messages

1
2
3
4
5
6
7
8
9
10
11
12
13
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  FLASH_TYPES = [:error, :warning, :success, :message]
  def display_flash(type = nil)
    html = ""
    if type.nil?
      FLASH_TYPES.each { |name| html << display_flash(name) }
    else
      return flash[type].blank? ? "" : "#{flash[type]}"
    end
    html
  end
end
Share

Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache