Skip to content

Instantly share code, notes, and snippets.

View guange2015's full-sized avatar

gg guange2015

  • usa
View GitHub Profile
@guange2015
guange2015 / spec_helper.rb
Created May 25, 2012 13:34
spec_helper.rb
require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'
unless defined?(Rails)
require File.dirname(__FILE__) + "/../config/environment"
end
Spork.prefork do
@guange2015
guange2015 / dog.rb
Created June 27, 2012 15:57
Step 1: dog_game.rb
class Dog
def initialize(name)
@name = name
@cans = []
end
def can(*args)
@cans = args
end
@guange2015
guange2015 / UIView+Gradient.m
Created June 28, 2012 03:01
gradient color for view.
#import "CoreText/CoreText.h"
#import <QuartzCore/QuartzCore.h>
enum GradientType {
LEFT2RIGHT = 1,
TOP2BOTTOM = 2,
RIGHT2LEFT = 3,
BOTTOM2TOP = 4
};
@guange2015
guange2015 / gist:3027340
Created July 1, 2012 07:31
扁平化作用域
class CleanRoom
def run(setups, &block)
setups.each do |setup|
instance_eval &setup
end
instance_eval &block
end
end
@guange2015
guange2015 / getwebviewheight.m
Created August 1, 2012 09:01
getwebviewheight
-(void)webViewDidFinishLoad:(UIWebView *)webview {
CGSize size = [[[webview subviews]objectAtIndex:0] contentSize];
[[[webview subviews]objectAtIndex:0] setScrollEnabled:NO];
CGRect rc = webview.frame;
rc.size.height = size.height;
webview.frame = rc;
webview.hidden = NO;
UIView *cell = [[webview superview] superview];
rc = cell.frame;
@guange2015
guange2015 / load.js
Created August 1, 2012 09:03
page_loading_finished.
<script language="javascript" type="text/javascript">
document.onreadystatechange = function(){
if(document.readyState=="complete") {
// alert(document.readyState);
window.location="/cmd/loadfinish";
}
}
</script>
@guange2015
guange2015 / getwebviewheight.m
Created August 1, 2012 09:06
getwebviewheight
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeOther ){
NSString *ts = [request.URL absoluteString];
if ([ts indexOfString:@"cmd/loadfinish"]>0){
int scrollHeight = [[aWebView stringByEvaluatingJavaScriptFromString: @"document.body.scrollHeight"] intValue]; //此处为页面真实高度
return NO;
}
}
@guange2015
guange2015 / keyboard.m
Created September 16, 2012 05:40
uitextfield keyboardshow
-(void) keyboardWillShow:(NSNotification*)notification {
NSDictionary* info =[notification userInfo];
kbSize =[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
UIView *mainV = [self getMainView];
CGPoint p =[self convertPoint:CGPointMake(0, self.frame.size.height) toView:mainV];
if (p.y + kbSize.height > mainV.frame.size.height) {
[UIView beginAnimations:@"" context:nil];
[UIView setAnimationCurve:0.3];
CGRect rc = mainV.frame;
@guange2015
guange2015 / textfiled_add_transparent.m
Created September 16, 2012 05:45
textfiled add transparent
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
UIView *mainV = [self getMainView];
clickV = [[UIClickView alloc]initWithFrame:mainV.bounds];
clickV.edit = input;
[mainV addSubview:clickV];
[clickV release];
[self becomeFirstResponder];
}
@guange2015
guange2015 / uitextfield-transparent-view.m
Created September 16, 2012 05:47
uitextfield transparent view
@interface UIClickView : UIView
@property (nonatomic,assign)UITextField* edit;
@end
@implementation UIClickView
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
CGPoint p = [self convertPoint:point toView:self.edit];
if (p.x>0 && p.y>0) {
return nil;
}
return [super hitTest:point withEvent:event];