Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Juguang XIAO between40and2

:octocat:
View GitHub Profile
View date time format: ISO_8601
I am developing for iOS and RoR. For date time issue, I feel lucky, since both works with ISO 8601.
By default, Rails 4 returns ISO 8601 format as json output.
On iOS, you should have date format as @"yyyy-MM-dd'T'HH:mm:ssZZZ"
See http://developer.github.com/v3/ (search "ISO")
@between40and2
between40and2 / rails-how-to-customize-json
Created Dec 27, 2013
If you are not satisfied with default to_json implementation of ActiveRecord. Here is the way out.
View rails-how-to-customize-json
Customizing a model object's JSON representation, first of all, is a business of ActiveRecord::Serialization. You will look at ActiveModel::Serializers::JSON class
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serializers/json.rb
and then will come back to ActiveModel::Serialization class
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/serialization.rb
View rails-routes-in-depth
Do you know, you can access your own rails website on /rails/info/routes , under development environment?
The working house is shown below.
https://github.com/rails/rails/blob/master/railties/lib/rails/info_controller.rb
In turn, ActionDispatch::Routing::RoutesInspector is the real hero. Linked below.
https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/routing/inspector.rb
@between40and2
between40and2 / JXUIStory_id_creation__UINC
Last active Dec 29, 2015
JXUIStory_id_creation__UINC
View JXUIStory_id_creation__UINC
UIStory needs a Procedure to guide it, and story listens to Procedure's events of proceed and complete .
It is UIStory to expose proceedNext method for client to call. While UI will have "next" button to proceed the procedure, too.
UIStory has a JXUIVCFactory_ProcedureStep .
VCFactory will createVC, setObject:intoVC, and getObject:fromVC, according to step.
Since the kinds of steps are currently limited, the VC types to be used are limited too, therefore manually manageable.
JXModel_ProcedureStep_ObjectPart_Attribute --- JXUITVDSD_NSArray_Selection (or JXUITVDSD_NSArray_Selection__allowsAddSimpleTextOptions)
@between40and2
between40and2 / FOG
Created Nov 24, 2013
FOG means Filtering, Ordering and Grouping on an array/list
View FOG
## Filtering
NSPredicate
## Ordering/Sorting
NSSortDescriptor
View .NET MVC Controller-Filter-Exchange
Controller 和 Filter 互联方案
以ControllerContext为中介,合理利用ViewData。
http://msdn.microsoft.com/en-us/library/system.web.mvc.controllercontext(v=vs.108).aspx
自定义Model类:
UserIntention
@between40and2
between40and2 / class_addIvar-useless
Created Oct 24, 2013
class_addIvar, in Objective-C runtime, is useless
View class_addIvar-useless
class_addIvar, in Objective-C runtime, is useless, because it does not support to add ivar in an EXISTING class.
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_addIvar
You can use the concept of idInfo (see id-ego-superego), to add run-time generated objects' property.
@between40and2
between40and2 / ios-object-attribute-access
Last active Dec 25, 2015
Given an Objective-C object and an attribute name, how can you access (read/write) it?
View ios-object-attribute-access
return [self.object valueForKey: attrName];
--
SEL getterSEL = NSSelectorFromString( attrName);
View iOS-Keyboard
After 3 years of iOS development practice, finally I have chance to fully work with the soft keyboard. I found the Apple official docs is far from enough to deal with every cases of iOS soft keyboard. Then online 3rd party docs are helpful but not complete either. I can understand it since everyone is busy, very few people to write a complete guide for any specific topics.
Then I come to this. I have to do trial and error to grasp this piece of knowledge. One problem I was facing is when device is in landscape, you cannot use keyboard's height to adjust textview/tableview's contentInsets, since the height actually seems as its "width". UIWindow is mounted always in portrait mode, and keyboard frame goes with it. When device and UI is in landscape, the keyboard frame is still measured as it is in portrait. The solution:
CGRect frameEnd = [[notif.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
frameEnd = [self.view convertRect: frameEnd fromView: nil];
@between40and2
between40and2 / scm-svn-git
Last active Dec 16, 2015
favorite links for SCM, SVN, Git. etc.
View scm-svn-git
http://svnbook.red-bean.com/en/1.0/index.html