Skip to content

Instantly share code, notes, and snippets.

View swarut's full-sized avatar
💭
TapiUnicornnnnnn

Warut Surapat swarut

💭
TapiUnicornnnnnn
  • Medidata Solutions
  • Tokyo, Japan
View GitHub Profile
@swarut
swarut / set_custom_font.m
Created October 1, 2012 18:44
Objective-C : Set custom font to all labels in view controller #objective-c #font #customfont #label
defaultFont = [UIFont fontWithName:@"Bariol" size:14.0];
for(UIView *aView in [[self view] subviews]){
if([aView isKindOfClass:[UILabel class]]){
[((UILabel*)aView) setFont:defaultFont];
}
}
@swarut
swarut / Gemfile
Created October 1, 2012 11:35
Rails : Essential gem #rails #gem
source 'https://rubygems.org'
gem 'rails', '3.2.8'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'mysql2'
gem 'jquery-rails'
@swarut
swarut / CustomViewFactory.m
Created September 30, 2012 17:57
Objective-C : CustomViewFactory #customview #objective-c #ui #view
@implementation CustomViewFactory
+(CustomView*)newCustomView:(NSString*)lang{
NSArray *nibs = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil];
CustopmView *customView;
for(UIView *view in nibs){
if([view isKindOfClass:[CustomView class]]){
customView = (CustomView*)view;
@swarut
swarut / font_list.m
Created September 30, 2012 09:22
Objective-C : Listing and using a custom font #font #objecitve-c #ui #customfont
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
@swarut
swarut / request_handling.m
Created September 29, 2012 17:46
Objective-C : Requesting and handling a response #objective-c #api #request #handling
-(void) request{
NSString *targetUrlString = @"url";
NSURL *targetUrl = [NSURL URLWithString:targetUrlString];
NSData *data = [NSData dataWithContentsOfURL:targetUrl];
[self performSelectorInBackground:@selector(callback:) withObject:data];
}
-(void) callBack:(NSData*)respondedData{
NSError *error;
NSDictionary *dataDic = [NSJSONSerialization
@swarut
swarut / user_preference.m
Created September 29, 2012 15:21
Objective-C : User preferencing with NSUserDefaults #objective-c #user-preference #nsuserdefaults
NSUserDefaults *userPreference = [NSUserDefaults standardUserDefaults];
[userPreference setValue:user_info forKey:@"key"];
[userPreference removeObjectForKey:@"key"]
[userPreference synchronize];]
@swarut
swarut / gist:3804325
Created September 29, 2012 15:17
Objective-C : Initialize a specific viewcontroller from storyboard #objective-c #storyboard #viewcontroller
UIStoryboard *storyboard = self.storyboard;
MyViewController *view = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
self.view.window.rootViewController = view;
@swarut
swarut / where_stub_pattern.rb
Created September 24, 2012 08:58
Ruby : Stub pattern for injecting statement to where() method #ruby #test #stub
before do
User.stub(:where) do |like_query, bind_param|
case bind_param
when 'Bob%' then [bob]
when 'Jane%' then [jane]
else []
end
end
end
@swarut
swarut / gist:3774995
Created September 24, 2012 08:52
Ruby : Caching processed value in an instance variable #cache #ruby #pattern
class UserParser
attr_reader :mentioned_users
def mention_users
@mentioned_users ||= <some processing>
end
end
@swarut
swarut / gist:3774957
Created September 24, 2012 08:41
try from sublime
test