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 / gist:2343507
Created April 9, 2012 13:46
Android : InputType property for Android's EditText
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id = "@+id/login_tel"
android:inputType="phone"
/>
@swarut
swarut / gist:2354762
Created April 10, 2012 21:37
Android : Custom view from ViewGroup
public class MyCustomView extends LinearLayout{
public MyCustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
View.inflate(context, R.layout.your_layout_name, this);
}
public MyCustomView(Context context, AttributeSet attrs) {
this(context, null, 0);
}
public MyCustomView(Context context) {
this(context, null);
@swarut
swarut / .bash_profile
Created September 13, 2012 15:00
Bash : My 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 / gist:3774851
Created September 24, 2012 07:57
Git : Showing a file at a specific commit
git show <treeish>:filename
#<treeish> can be something like HEAD~3 or a hash number.
@swarut
swarut / gist:3774957
Created September 24, 2012 08:41
try from sublime
test
@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 / 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: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 / 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 / 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