Skip to content

Instantly share code, notes, and snippets.

View guange2015's full-sized avatar

gg guange2015

  • usa
View GitHub Profile
@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 / 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: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 / 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 / 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 / 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 / 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 / authentication_pages_spec.rb
Created May 25, 2012 13:13
authentication_pages_spec.rb
require 'spec_helper'
describe "AuthenticationPages" do
subject {page}
describe "login" do
before {visit login_path}
describe "visit login page" do
it{should have_selector('h1', text:'login')}
end
@guange2015
guange2015 / user_spec.rb
Created May 25, 2012 13:13
user_spec.rb
require 'spec_helper'
describe User do
subject {@user}
before {@user = User.new(name:'ExampleUser', email:'hah@gmail.com',
password: 'foobar', password_confirmation:'foobar') }
it {should be_valid}
it {should respond_to(:name)}
it {should respond_to(:email)}
@guange2015
guange2015 / gist:2760931
Created May 21, 2012 07:22
plist 读取与写入
//系统
NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary];
NSString* version = [infoDict objectForKey:@"CFBundleVersion"];
//写入
NSMutableDictionary* dict = [ [ NSMutableDictionary alloc ] initWithContentsOfFile:@"/Sample.plist" ];
[ dict setObject:@"Yes" forKey:@"RestartSpringBoard" ];
[ dict writeToFile:@"/Sample.plist" atomically:YES ];
//读取