Skip to content

Instantly share code, notes, and snippets.

View between40and2's full-sized avatar

Juguang XIAO between40and2

  • London & Beijing
View GitHub Profile
@between40and2
between40and2 / rails-how-to-customize-json
Created December 27, 2013 07:48
If you are not satisfied with default to_json implementation of ActiveRecord. Here is the way out.
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
@between40and2
between40and2 / rails-routes-in-depth
Created December 12, 2013 12:14
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 December 29, 2015 08:09
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 November 24, 2013 12:55
FOG means Filtering, Ordering and Grouping on an array/list
## Filtering
NSPredicate
## Ordering/Sorting
NSSortDescriptor
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 October 24, 2013 09:45
class_addIvar, in Objective-C runtime, is 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 December 25, 2015 04:09
Given an Objective-C object and an attribute name, how can you access (read/write) it?
return [self.object valueForKey: attrName];
--
SEL getterSEL = NSSelectorFromString( attrName);
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 December 16, 2015 13:38
favorite links for SCM, SVN, Git. etc.
http://svnbook.red-bean.com/en/1.0/index.html
@between40and2
between40and2 / iOS-Callback
Last active December 16, 2015 13:29
iOS-Callback
Here is my sum on which callback mechanism should be used for which cases.
- for UIView and UIVC, use delegate
- for model change, use NSNotification or KVO. However, KVO is not designed for communicating "events", therefore NSNotif is the preferred.
- for Data Access, use block.
for UIControl subclass, use target-action.
Bye Delegate, Hello Block