Jourdein

I code, I experienced, I blog and I share my enthusiasm

RSS
people

Cross browser styling for inline-block

IE does support inline-block css styling but to which the elements are natively inline. Apply inline-block styling to strong, spans and ems.

But there’s another thing. If hasLayout is triggered on a block element, and then set that element to display inline, it will automagically become an inline-block in IE. However, you must do a *property hack to hide the display:inline from non-IE browser.

display: inline-block;
zoom: 1;
*display: inline;
No Comments | Tags: , , ,

ForkLift 1.7 crashed on Snow Leopard

forklift.pngI’ve install ForkLift 1.7 and suddenly, it crashed. Examining the report that is supposed to be sent to Apple, I found that, ForkLift is trying to access some of the files that aren’t there.

Googled and found that the files has been placed under a different folder in Snow Leopard. Logical thinking, the files are there but ForkLift doesn’t know where they are.

Found a fix that restore those file references by creating symlinks:

sudo ln -s /System/Library/Frameworks/AppleShareClientCore.framework /System/Library/Frameworks/AppleShareClient.framework
sudo ln -s /System/Library/Frameworks/AppleShareClientCore.framework/Versions/A/AppleShareClientCore /System/Library/Frameworks/AppleShareClientCore.framework/Versions/A/AppleShareClient
sudo ln -s /System/Library/Frameworks/QuickLook.framework /System/Library/PrivateFrameworks/QuickLookUI.framework
sudo ln -s /System/Library/Frameworks/QuickLook.framework/QuickLook /System/Library/Frameworks/QuickLook.framework/QuickLookUI
sudo ln -s /System/Library/Frameworks/QuickLook.framework/Versions/A/QuickLook /System/Library/Frameworks/QuickLook.framework/Versions/A/QuickLookUI

Run the above commands in terminal. If you have problem copying and pasting, download it here. Execute the file from terminal either by

$ ./fixsymlinks

or

$ source fixsymlinks

From whom did I get the solution… Zolntanb (thanks mate)

No Comments | Tags: , , , ,

Updating a has_many relational model

has many relationship solution.png

Last night, found a problem in codes during updating form for a has_many relationship model. Rather than updating the record, it created a new one.

The solution is in railscasts episode 75.

Consider contact that has_many contact_email addresses. Created

def contact_email_attributes=(contact_email_attributes)
  contact_email_attributes  do |attributes|
    contact_emails.build(attributes)
  end
end

Changed to this one:

def contact_email_attributes=(contact_email_attributes)
  contact_email_attributes.each  do |attributes|
    if attributes[:id].blank?
      contact_emails.build(attributes)
    else
      contact_email = contact_emails.detect { |e| e.id == attributes[:id].to_i }
      contact_email.attributes = attributes
    end
  end
end

that will updates contact_email if there’s :id attributes. Then, I need to add the :id inside the form as hidden_field_tag:

- @contact.contact_emails.each do |contact_email|
...
= hidden_field_tag "contact[contact_email_attributes][][id]", contact_email.id
...

And that’s all. It’s done.

In the form, you could do fields_for rather than using _tag methods. In fact, my original code was using that but after I tried everything and it ended up with the _tag methods, I was lazy to change it back. By the way, it works both ways…

No Comments | Tags:

Passenger, Rails and XAMPP on Mac

I’ve successfully setup my Rails on Passenger. It was not a swift tasks as I was trying to setup it on ‘my’ XAMPP.

I had XAMPP all the way since I’ve started development on PHP. Don’t want to install different Apache server just to setup Passenger. Because of that, I took 1 full day of my life to finally have a functional Rails with Passenger on Apache in XAMPP.

(assuming you had Rails with Mongrel and XAMPP already)

  1. Install gem Passenger
  2. Download XAMPP dev (this is the key for success!)
  3. Run passenger install script
  4. Modify Apache .conf file

(you’re ready to go)

Add some miscellaneous (that’ll make your life easier)

  1. Download and install Passenger Preference Pane

1. Install gem Passenger

$ sudo gem install passenger

2. Download XAMPP Developer

XAMPP Developer package for Mac

3. Run passenger install script for Apache

$ sudo passenger-install-apache2-module

(No. 4 step is given at the end of module installation above)

Download & install Passenger Preference Pane here

No Comments | Tags: , ,

Centering text vertically and horizontally

Vertical-Align.pngYet again, I faced this difficulty when centering text vertically. I’ve done this before but I’ve forgotten. Was hoping to find new way but landed on the same page I was referring before.

By Gavin Kistner, Understanding vertical-align, or “How (Not) To Vertically Center Content”

This is the code I used:
div.outer {height:100%;text-align:center;}
div.inner {position:absolute;top:40%;left:40%;height:36px;width:200px;}
<div class="outer">
<div class="inner">
<span class="title">Title</span>
<small>Caption</small>
</div>
</div>

I modified the code to fit my need. I wanted to center the content with the width of the viewing/browser width. I think, finding the correct percentage need trials. It depend on the width of the container. You could calculate though, mathematically.

No Comments | Tags:

Sliding UITextFields visible when keyboard appear

When keyboard visibleBefore keyboard visible



I thought there was an easy way such as enabling it in IB but seem I had to go to Google to find out how. For those who want to know how, here’s the original source.

Mainly, the codes involve on delegate functions:

- (void)textFieldDidBeginEditing:(UITextField *)textField
- (void)textFieldDidEndEditing:(UITextField *)textField

So, here’s the codes

1
2
3
4
5
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLL_FRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
- (void)textFieldDidBeginEditing:(UITextField *)textField {
   [UIView beginAnimations:nil context:NULL];
   [UIView setAnimationBeginsFromCurrentState:YES];
   // the setAnimationBeginsFromCurrentState allow smooth transition
   // to new text field if the user taps on another
   [UIView setAnimationDuration:0.3];
 
   CGRect textFieldRect = [self.view.window convertRect:textField.bounds
                                               fromView:textField];
   CGRect viewRect = [self.view.window convertRect:self.view.bounds
                                               fromView:self.view];
 
   CGFloat midline = textFieldRect.origin.y + 0.5 * textFieldRect.size.height;
   // find the midline of textfield
   CGFloat numerator = midline - viewRect.origin.y - MINIMUM_SCROLL_FRACTION
                       * viewRect.size.height;
   CGFloat denominator = (MAXIMUM_SCROLL_FRACTION - MINIMUM_SCROLL_FRACTION)
                       * viewRect.size.height;
   CGFloat heightFraction = numerator / denominator;
 
   if (heightFraction < 0.0) { heightFraction = 0.0; }
   else if (heightFraction > 1.0) { heightFraction = 1.0; }
 
   animatedDistance = floor(PORTRAIT_KEYBOARD_HEIGHT*heightFraction);
   self.view.frame = CGRectMake(self.view.frame.origin.x,
   self.view.frame.origin.y-animatedDistance,
   self.view.frame.size.width,
   self.view.frame.size.height);
   [UIView commitAnimations];
}
1
2
3
4
5
6
7
8
9
10
11
12
13
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    CGRect viewFrame = self.view.frame;
    viewFrame.origin.y += animatedDistance;
 
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDuration:KEYBOARD_ANIMATION_DURATION];
 
    [self.view setFrame:viewFrame];
 
    [UIView commitAnimations];
}

However, you could also refer to UICatalog example which also has example quite similar to this one but I prefer this one.

No Comments | Tags: , , , ,

Hide keyboard when a field lost focus

I’ve found 2 ways, currently, on how to hide keyboard when textfield lost focus on when user has done editing.

  • Delegate method
  • Callback for the event nbsp;nbsp;Did End On Exit

Delegate method

1
2
3
4
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
	[textField resignFirstResponder];
	return YES;
}

Very simple indeed. Just add this function in view where you want textfield to be delegated to.

Callback for event Did End On Exit

Outlines:

  • Create dummy method: -(IBAction)endEditing:(id)sender;
  • Connect event codeDid End On Exit/code to the dummy method created

References:

No Comments | Tags: , , , ,

Array Controller bounded to an Array

I was scratching my head of why the heck does the my tableview does not automatically update its data.

My binding:

NSArrayController = ACIssues
Controller Class = Issue Controller (have NSArray property subviewControllers)

ACIssues has it contentArray binded to subviewControllers’s array in Issue Controller. Somehow, changes made to the array of subviewControllers in Issue Controller does not reflect on other table which I had it binded to ACIssues.

After searching the internet, I found this

http://boredzo.org/blog/archives/2008-11-26/how-to-work-with-a-bound-to-array (open in new window)

Very good one. What it said… There’re right and wrong way to bind.

The right way is by using indexed accessors. Then, your Array Controller will see any changes you’ve made. What I did was creating indexed accessor methods.

- (void)insertObject:(id)object inSubviewControllersAtIndex:(unsigned)index {
[[self subviewControllers] insertObject:object atIndex:index];
}


- (void)removeObjectFromSubviewControllersAtIndex:(unsigned)index {
[[self subviewControllers] removeObjectAtIndex: index];
}

and calling it where I wanted to change the array.

[self insertObject:obj inSubviewControllersAtIndex:(index + 1)];
[self removeObjectFromSubviewControllersAtIndex:index];

the structure of this indexed accessor:

insertObject:(id)object inKeyAtIndex:(unsigned)index

where key is the property or in my case array that is binded to the Array Controller.

No Comments | Tags: , , , , ,

301 or 302 or Meta refresh tag

I did a google search on which is the best one to use to redirect page from another. I had this in mind, whether to use meta tag refresh or 301 redirect in htaccess file. I was afraid that using meta redirect would be rank penalize by google.

After the search, the safest way to redirect is to use 301 redirect. To do 301 redirect you just need to add this code in .htaccess file in the root directory:

RewriteEngine On
Redirect 301 /index.html http://mydomain.com/blog/

You might be asking what is meta fresh tag… It just a simple html code put on the top of the html file that redirect user from that page to another page. It look like this:

<meta http-equiv="refresh" content="0;url=http://www.anotherdomain.com">

Here I’ve got some good illustration of the what those mean with other types or redirection.

redirection cartoon illustration

Here is the link which I referred to (all links open in new window):

No Comments | Tags: , , ,

Otai post on sweetcron modification

Azri has uploaded sweetcron modification code to change option.
http://codegenius.wordpress.com/2008/12/31/adding-new-option-in-sweetcron/#more-7

No Comments | Tags: ,