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 / rendering_view_spec.rb
Created November 20, 2012 11:12
Rspec : Rendering View #rspec #rails
require 'spec_helper'
describe FeedsController do
let!(:user) { User.make!(:registered) }
render_views
describe "GET 'events'" do
it "successfully responds to ICS format" do
get 'events', :format => :ics, :token => user.feed_token
@swarut
swarut / map.m
Created November 12, 2012 13:56
Objective C : Map Example
//
// LocationViewController.m
// BoxBox
//
// Created by Warut Surapat on 12/19/11.
// Copyright (c) 2011 StardustDream. All rights reserved.
//
#import "LocationViewController.h"
#import "GlobalData.h"
@swarut
swarut / next.rb
Created November 8, 2012 12:21
Ruby : Using Next to Continue Looping #ruby #loop #next
workload.each do |screen_name|
statuses = Status.retrieve(screen_name, Status.cursor[screen_name])
next if statuses.blank?
....
end
@swarut
swarut / lookahead.rb
Created November 1, 2012 11:24
Ruby : Lookahead Regex #ruby #regex
at_prefixed_chunks = text.split(/(?<=\s)@/).reject(&:blank?)
@swarut
swarut / userPreference.m
Created October 31, 2012 16:59
Objective-C : Using UserPreference #objective-c #userpreference
userPreference = [NSUserDefaults standardUserDefaults];
// Check for a value of a specific key
if([userPreference objectForKey:@"login_info"]){
NSString *userInfo = [userPreference objectForKey:@"login_info"];
NSArray *tokens = [userInfo componentsSeparatedByString:@"/"];
[self.telephoneTextField setText:[tokens objectAtIndex:0]];
[self.passwordTextField setText:[tokens objectAtIndex:1]];
[self login:self];
}
@swarut
swarut / all_task.rake
Created October 31, 2012 07:48
Rails : Creating A Rake Task Which Run All Sub-Tasks
namespace :tasks do
namespace :create do
desc "Create all survey templates"
task :all => [:task1, :task2, :task3]
desc "desc1"
task :task1 => :environment do
end
@swarut
swarut / collect_shorthand.rb
Created October 18, 2012 07:02
Ruby : Using Shorthand Collect #ruby #collect #shorthand
# collect values from a particular field
@users.collect(&:email)
# collect values from a particular method
@users.collect(&method(:user_preferences_url))
@swarut
swarut / gist:3874286
Created October 11, 2012 17:51 — forked from tangmae/gist:3874207
Homework#2 Calculator
public class calculator(){
private Keyboard keyboard;
private Screen screen;
private Stack operant;
private Stack operator;
private String showValue;
private State calState;
enum State{
on,
@swarut
swarut / homework1.java
Created October 10, 2012 18:07
Homework#1 Example
public class Mobile{
private Keyboard keyboard;
private Screen screen;
private Stack callStack;
private State phoneState;
private String currentNumber;
enum State{
on,
off,
@swarut
swarut / nonAnimatedSegue.m
Created October 8, 2012 17:29
Objective-C : Custom non-animated segue #objective-c #segue #customsegue
@implementation NonAnimatedSegue
- (id) initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination{
self = [super initWithIdentifier:identifier source:source destination:destination];
if(self){
}
return self;
}