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 / 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 / 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 / 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 / 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 / .bash_profile
Created October 1, 2012 21:23
Bash : My bash profile as of oct-2012 #bash #bash-profile
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
fi
export CLICOLOR=1
export LSCOLORS=cxfxcxdxbxegedabagacad
export GREP_OPTIONS='--color=auto'
source "`brew --prefix`/etc/grc.bashrc"
@swarut
swarut / StringHelper.h
Created October 2, 2012 14:17
Objective-C : StringHelper
#import <Foundation/Foundation.h>
@interface StringHelper : NSObject
+ (NSString*)costString:(NSString*)source;
+ (NSString*)dateString:(NSString*)source;
+ (NSString*)dateString:(NSString*)source withTime:(BOOL)enableTime;
+ (NSString*)imagePathStringWithSource:(NSString*) source;
+ (NSString*)UTF8DecodedString:(NSString*)source;
+ (NSString*)UTF8EncodedString:(NSString*)source;
@swarut
swarut / visibility_filtering.rb
Created October 3, 2012 05:59
Rails : A proper validation #rails #validation
def appropriate_visibilities
unless (self.visibilities - self.user.roles).empty?
errors.add(:visibilities, "invalid visibilities assignment")
end
# Below is a bad one, change the visibilities silently. this is not a right behavior of validation
# self[:visibilities] = BIT_MASKER.mask(
# # This is assuming that self.visibilities, at least, must have :regular as its member
# # or we will end up getting visibilities = [].
# # See the comment on visibilities() above
@swarut
swarut / RoudedTextField.m
Created October 3, 2012 17:47
Objective-C : Custom UITextField with left padding, background and keyboard hiding on exit #objective-c #textfield #customtextfield #ui #hidekeyboard
#import "RoundedTextField.h"
@implementation RoundedTextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
}
@swarut
swarut / .pryrc
Created October 4, 2012 08:32
Rails : Setting up Pry #rails #setup #pry
if defined?(Rails) && Rails.env
extend Rails::ConsoleMethods
end
@swarut
swarut / hirb.rb
Created October 4, 2012 10:08
Rails : Setting up hirb #rails #hirb
require 'hirb'
require 'pry'
ActiveSupport.on_load :active_record do
Hirb::Formatter.dynamic_config['ActiveRecord::Base']
Hirb.enable
old_print = Pry.config.print
Pry.config.print = proc do |output, value|
Hirb::View.view_or_page_output(value) || old_print.call(output, value)
end