Find MYSQL Duplicate records

In : mysql, Posted by admin on Mar.03, 2009

If the database has a table call employees. The values are:


ID           Name
1              a
2              b
3              a
4              c
5              b

You want to find the duplicate record but not the first one (ie, ID# 3 and 5). You can do the following:

select id from employees where id not in (select distinct id from employees group by name);



CSS box model

In : Uncategorized, Posted by admin on Mar.03, 2009

Each box has a content area (e.g., text, an image, etc.) and optional surrounding padding, border, and margin areas; the size of each area is specified by properties defined below. The following diagram shows how these areas relate and the terminology used to refer to pieces of margin, border, and padding:

The margin, border, and padding can be broken down into left, right, top, and bottom segments (e.g., in the diagram, “LM” for left margin, “RP” for right padding, “TB” for top border, etc.).

The perimeter of each of the four areas (content, padding, border, and margin) is called an “edge”, so each box has four edges:

content edge or inner edge
The content edge surrounds the element’s rendered content.
padding edge
The padding edge surrounds the box padding. If the padding has 0 width, the padding edge is the same as the content edge. The padding edge of a box defines the edges of the containing block established by the box.
border edge
The border edge surrounds the box’s border. If the border has 0 width, the border edge is the same as the padding edge.
margin edge or outer edge
The margin edge surrounds the box margin. If the margin has 0 width, the margin edge is the same as the border edge.

Each edge may be broken down into a left, right, top, and bottom edge.

The dimensions of the content area of a box — the content width and content height — depend on several factors: whether the element generating the box has the ‘width’ or ‘height’ property set, whether the box contains text or other boxes, whether the box is a table, etc. Box widths and heights are discussed in the chapter on visual formatting model details.

The box width is given by the sum of the left and right margins, border, and padding, and the content width. The height is given by the sum of the top and bottom margins, border, and padding, and the content height.

The background style of the various areas of a box are determined as follows:

  • Content area: The ‘background’ property of the generating element.
  • Padding area: The ‘background’ property of the generating element.
  • Border area: The border properties of the generating element.
  • Margin area: Margins are always transparent.

Problem with IE css hack

According to the W3C, an assigned ‘width’ (and ‘height’) of a box refers to the ‘content area’ of a box only. The padding, borders, and margins are then added to this value to arrive at the total box width. If the ‘width’ property is omitted, the total box width is the same as the ‘content area’ of the surrounding container element.

All well and good. Unfortunately, all CSS enabled versions of IE before IE6/strict use a different box model. In that model, the padding and borders are counted as part of any assigned ‘width’ or ‘height’. In the absence of borders and padding, the two models agree. However, if a box has an assigned “width’, and if borders and/or padding are added, the standard box model causes the overall box width (between the outer border edges) to increase, while in IE’s model the ‘content area’ gets squeezed by the same amount. This is a major problem for proper page layout.

Consider the following CSS:

{width:100px; padding:10px; border:10px;}

When viewed in a ’standards’ browser the dimension from border edge to border edge will be ‘140px’. (100+10+10+10+10=140) Because IE5.x puts all these values inside the ‘width’, the border edge to border edge dimension will be ‘100px’.

Note: For technical reasons it sometimes would be desirable to employ the old IE box model. It has been bruited about that CSS-3 will feature a way to choose between the two models, but the current standard model will no doubt remain the default.

Source: http://css-discuss.incutio.com/?page=BoxModelHack

Tags :


Javascript closure

In : Uncategorized, Posted by admin on Mar.03, 2009

A javascript closure is the local variables for a function – kept alive after the function has returned. For example, in the following example, the variable text is still alive after the function is closed. The reason is that the internal function sayAlert is still alive.

function sayHello2(name) {
  var text = 'Hello ' + name; // local variable
  var sayAlert = function() { alert(text); }

  return sayAlert;
}



Source: http://blog.morrisjohns.com/javascript_closures_for_dummies

Tags :


ActionView::TemplateError (undefined method `logged_in?’ for #)

In : ruby, Posted by admin on Mar.03, 2009

I am converting an old Ruby on Rails application to Rails 2.2.2 because the app does not work for dreamhost anymore. Dreamhost rails version is 2.2.2.

It is painful. A lot of plugin does not work. For example, I was using acts_as_authenticated plugin. However, it is no longer support. I need to convert it to restful_anthuenication plugin. The database structure is more or less the same but some of the internal stuff needs to be changed.

For example, after I add the plugin, I keep getting undefined method logged_in in the view. This is driving me crazy because I am using the logged_in method in the view to display whether the user is logged in or not. If login, I will display a logout button. If logout, I will display a login button. Since rails complain about logged_in method is not defined, I cannot display the view.

After a lot of searchs, I find it. It is n vendor/plugins/restful_authentication/generators/authenticated/templates/authenticated_system.rb:

# Inclusion hook to make #current_<%= file_name %> and #logged_in?
# available as ActionView helper methods.
def self.included(base)
base.send :helper_method, :current_<%= file_name %>, :logged_in?, :authorized? if base.respond_to? :helper_method
end

The key thing is that in your app/controllers/application.rb you need to add this:

include AuthenticatedSystem

oh well… move to next rail 2.2.2 migration problem..



How FriendFeed uses MySQL to store schema-less data

In : mysql, Posted by admin on Mar.03, 2009

Here is a posting about how FriendFeed uses MySQL to store the Json object. Then it creates separate table for each meta field to store the meta data. I use similar method to store all the static data (for example, order payment and transaction information). This method is good for data which is relatively stable.

http://bret.appspot.com/entry/how-friendfeed-uses-mysql

Tags :


rubygems.rb:142:in `activate’: can’t activate rubyforge

In : ruby, Posted by admin on Jan.01, 2009

My rails app is using the old version of rubyforge.

When I start the app using ./script/server. It complains about the rubyforge as:

/usr/lib/ruby/site_ruby/1.8/rubygems.rb:142:in `activate’: can’t activate rubyforge (= 0.4.5, runtim
e), already activated rubyforge-1.0.1 (Gem::Exception)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require’
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:
in `require’
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:342:
in `new_constants_in’
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:
in `require’
from /usr/lib/ruby/1.8/soap/streamHandler.rb:62
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/dependencies.rb:495:
in `require’
… 65 levels…
from /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/commands/server.rb:39
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require’
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’
from ./script/server:3

What you need to do is uninstall rubyforge and reinstall it as:

[root@pony ]# gem uninstall rubyforge

Select gem to uninstall:
1. rubyforge-0.4.4
2. rubyforge-0.4.5
3. rubyforge-1.0.0
4. rubyforge-1.0.1
5. All versions
> 5
Successfully uninstalled rubyforge-0.4.4
Successfully uninstalled rubyforge-0.4.5
Successfully uninstalled rubyforge-1.0.0

You have requested to uninstall the gem:
rubyforge-1.0.1
hoe-1.5.0 depends on [rubyforge (>= 0.4.4)]
hoe-1.5.1 depends on [rubyforge (>= 0.4.4)]
hoe-1.5.3 depends on [rubyforge (>= 1.0.0)]
hoe-1.8.1 depends on [rubyforge (>= 1.0.0)]
hoe-1.8.2 depends on [rubyforge (>= 1.0.1)]
hoe-1.3.0 depends on [rubyforge (>= 0.4.4)]
hoe-1.7.0 depends on [rubyforge (>= 1.0.0)]
If you remove this gems, one or more dependencies will not be met.
Continue with Uninstall? [Yn]
Successfully uninstalled rubyforge-1.0.1
[root@pony ]# gem install rubyforge
Successfully installed rubyforge-1.0.1
1 gem installed
Installing ri documentation for rubyforge-1.0.1…
Installing RDoc documentation for rubyforge-1.0.1…



Adding a second IP address to Fedora Linux

In : linux, system, Posted by admin on Jan.01, 2009

http://www.oclc.org/support/documentation/ezproxy/technote/2l.htm

These are the steps to add the second IP address to your existing network adapter under non-SUSE distributions of Linux.

  1. Become root on your system, either by logging into that account or using the su command.
  2. Change your current directory to the /etc/sysconfig/network-scripts directory with the command:
    
    cd /etc/sysconfig/network-scripts
    
  3. Check for existing network adapters with the command:
     ls ifcfg-* 

    In most instances, you will see the files ifcfg-eth0 and ifcfg-lo.

  4. Edit /etc/hosts and add a line for your new address and name such as:
    24.249.162.195 www.xyz.org
  5. To create the new interface, you will copy ifcfg-eth0 to ifcfg-eth0:0 with the command:
    cp ifcfg-eth0 ifcfg-eth0:0 

    Next, edit icfg-eth0:0 and change the DEVICE line to be similar to:

    DEVICE=eth0:0 

    and change the IPADDR line to be similiar to:

    IPADDR=24.249.162.195 
  6. To activate the new IP address, issue a command similar to:
    ./ifup eth0:0 


How to setup MyDNS

In : Uncategorized, Posted by admin on Nov.11, 2008

Useful document for how to setup MyDNS. The database table name may need to change but in general very good.

http://www.smartcgi.com/docs/mydns.html

Tags :


New Star Terk Trailer

In : Uncategorized, Posted by admin on Nov.11, 2008

We cool. New star terk trailer.

Tags :


undefined method `init_gettext’ for ApplicationController:Class

In : ruby, Posted by admin on Oct.10, 2008

I just updated to rails 2.1.2 and see this error:

undefined method `init_gettext’ for ApplicationController:Class

To resolve it.

  1. make sure you have the latest gettext gems.
  2. if it does not help, try add this to the first line of your app/controllers/application.rb
    • require ‘gettext/rails’
Tags :