Jourdein

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

RSS
people

I tried Git

images-1.jpgCurrently, I hosted my repositories with XP-Dev that utilize Subversion as it’s source code management system (SCM). Hearing a lot of hypes about the Git, I did try setting up a git account at Project Locker.

images-3.jpgYep, it seems that Git is really is an advance SCM. It has a lot of features. What differentiate it from Subversion is it’s decentralize repository system. Rather than recreate the post, you can read it at Why you should switch form Subversion to Git.

images-2.jpgOn Mac, if you’re using git, there an open source Git UI called GitX. It trying to utilize the advance features in Git producing such an interface. You have a history graph which I’ve never seen in Subversion UI yet. After you commit, you can see which file and which line has been merges/changes rather than executing command diff.

When you first checkout, you are cloning form the main repository. Thus, when you are in offline mode, you can still commit or revert to previous revision. When you online, push it the server and it will merge with other repo.

Frankly, I would love to convert to Git but project-wise, Subversion can still do what Git can do since my project is not so big and with small team. Moreover, Git is complex because of features it has while in Subversion, I just need to commit or update and does not worry about commit, push and branch merging etc.

No Comments | Tags: , ,

Software Is Hard

Developing software is hard. Below is an article form August 19, 2007.

Software is hard

Really, developing software is hard. If you want all those nifty features, biasing to certain framework because it’s the best, feeding your preference for certain os and without final decision. Yes, if all of those are free then go for it. In reality, those are cost. What languages you gonna use and how many developers you have? What are their expertise?

Some need to be compromise in order to benefit others or to maintain balance.

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: , ,

Learning Ruby on Rails for 2 weeks

I’m really tired. It has been a hectic weekend for me. Code code and more code. Learn Rails in two weeks while developing application at the same time. Today, I think I’ll stop here. The system seems O.K. I would like to enjoy my weekend left.

No Comments | Tags: , ,

Wordpress plugin and iPhone app

Default_250x375.shkl.png test_ur_westness.png
wordpress_plugin.png
wp_plugin.png

Successfully finish a wordpress plugin for simple book order and an iPhone app for simple Q&A test.

No Comments | Tags: , , ,

Started development of an iPhone app

kwbear5_125.jpgYesterday was officially the day I’ve started developing my Elance customer iPhone app. I was hoping to give my best through out this period.

Though it was yesterday, I’ve already slowly started developing it after receiving the description and content for the app.

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: , , , ,

Radio Button to UISegmentedControl

There’s no radio button in XCode for iPhone. Following good design practices, if you have 3 or 4 options, it is good to show it all rather than putting in drop down menu. It it is on web application, you can do it as radio button but if for application in iPhone, there is no radio button. However, there’s UISegmentedControl that function as in radio button.

Radio Button for Web App on iPhone

Radio Button for Web App on iPhone

UISegmentedControl

UISegmentedControl

Now, have to convert all algorithm from javascript to objective-c for iphone app. However, I want to test it, rather on iphone simulator, on real iphone but there’s other restrictions to it… “Code Signing”, “IDP (IPhone Developer Program). I did found the workaround but didn’t try yet.

What you need:

  • Jailbreak iPhone
  • Link-Identity-Editor..
  • Certificate..Code Signing or what-not.
  • etc..etc.

Here’s the link for detailed instructions. Better read there coz I don’t applied it yet. You’ll need to read about Code Signing Identify.

Here is another reference but seemed to not work but I think it just missed steps. The other steps is good for reference.

No Comments | Tags: , , , ,