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 / awake_from_nib.m
Created October 7, 2012 20:42
Objective-C : Configure subviews of custom view in awakeFromNib method #objective-c #view #subview #awakefromnib
#import "HomeTitleView.h"
#import "UIFactory.h"
@implementation HomeTitleView
@synthesize ticketLabel;
@synthesize monthLabel;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
@swarut
swarut / plist.m
Created October 7, 2012 05:08
Objective-C : Using plist via dictionary #objective-c #plist #resource
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
NSString *resourcePath = [bundlePath stringByAppendingPathComponent:@"resource.plist"];
sharedInstance.objectCompositionDic = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
@swarut
swarut / snippet.java
Created October 6, 2012 07:45
xxxxxxxxx
class Human{
private String name;
private int age;
private String birth;
private int weigth;
private int height;
private String[] nisai;
private String status;
private float money;
private house home;
@swarut
swarut / gist:3844337
Created October 6, 2012 07:41
Human blah
////////
class Human{
private String name;
private int age;
private String birth;
private int weigth;
private int height;
private String[] nisai;
private String status;
private float money;
@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
@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 / 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 / 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 / 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 / .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"