Skip to content

Instantly share code, notes, and snippets.

View matt-curtis's full-sized avatar

Matt Curtis matt-curtis

View GitHub Profile
@matt-curtis
matt-curtis / gist:5703839
Last active December 18, 2015 01:28
Get all text/html in rectangle or CSS3 Column
var getAllTextInColumn = function(rect){
/*
rect should be the size and x,y of the column
*/
if(document.caretPositionFromPoint){
var caretRangeStart = document.caretPositionFromPoint(rect.left, rect.top);
var caretRangeEnd = document.caretPositionFromPoint(rect.left+rect.width-1, rect.top+rect.height-1);
} else if(document.caretRangeFromPoint){
var caretRangeStart = document.caretRangeFromPoint(rect.left, rect.top);
@matt-curtis
matt-curtis / gist:5843862
Last active December 18, 2015 20:59
Redraw/relayout UIWebView's Webkit DOM
- (void) forceRedrawInWebView:(UIWebView*)webView {
NSArray *views = webView.scrollView.subviews;
for(int i = 0; i<views.count; i++){
UIView *view = views[i];
//if([NSStringFromClass([view class]) isEqualToString:@"UIWebBrowserView"]){
[view setNeedsDisplayInRect:webView.bounds]; // Webkit Repaint, usually fast
[view setNeedsLayout]; // Webkit Relayout (slower than repaint)
@matt-curtis
matt-curtis / linkgrabber.js
Last active November 9, 2022 22:17
JS Link Grabber - Uses TextArea to Acquire Links Dropped onto Pages
var LinkGrabber = {
textarea: null,
/* Textarea Management */
attach_ta: function(){
if(LinkGrabber.textarea != null) return;
var textarea = LinkGrabber.textarea = document.createElement("textarea");
textarea.setAttribute("style", "position: fixed; width: 100%; margin: 0; top: 0; bottom: 0; right: 0; left: 0; z-index: 99999999");
@matt-curtis
matt-curtis / AppSwitcher.as
Created March 26, 2014 13:23
Application Subclass for...switching between application instances...
package
{
import flash.events.Event;
import mx.controls.SWFLoader;
import mx.core.Application;
import mx.managers.SystemManager;
public class AppSwitcher extends Application
{
@matt-curtis
matt-curtis / gist:f9efbd2c2df1b77e3471
Last active January 22, 2018 14:48
Get number of lines in UITextView (iOS 7 compat.)
id<UITextInputTokenizer> tokenizer = textView.tokenizer;
UITextPosition *pos = textView.endOfDocument;
NSInteger lines = 0;
while (true){
UITextPosition *lineEnd = [tokenizer positionFromPosition:pos toBoundary:UITextGranularityLine inDirection:UITextStorageDirectionBackward];
if([textView comparePosition:pos toPosition:lineEnd] == NSOrderedSame){
pos = [tokenizer positionFromPosition:lineEnd toBoundary:UITextGranularityCharacter inDirection:UITextStorageDirectionBackward];
@matt-curtis
matt-curtis / NumberPadDoneBtn.h
Last active December 31, 2020 14:29
Done Button for UIKeyboard NumberPad (must be set as inputAccessoryView)
#import <UIKit/UIKit.h>
@interface NumberPadDoneBtn : UIView
@end
@interface NumberPadButton : UIButton
@end
@matt-curtis
matt-curtis / gist:6b9235f3a3e94ce9145d
Last active September 11, 2017 08:35
Disable animation in UINavigationBar
@implementation MyNavBar
- (NSArray*) subviews {
NSArray *subviews = [super subviews];
if(_animationDisabled) [self removeAllAnimationsInViews:subviews];
return subviews;
}
@matt-curtis
matt-curtis / gist:b92dc5987a9c423968de
Last active May 18, 2018 18:11
Google Apps Scripts - Loading external libraries/javascript
/*
1.) Add any extra libraries as "html" files (New > HTML File)
*/
/* 2.) */ eval(HtmlService.createTemplateFromFile("JSLib").getRawContent()); /* exclude the .html extension */
@matt-curtis
matt-curtis / gist:0ba79643a7412b1dd64a
Last active August 29, 2015 14:07
XPath + Text Nodes
var getNodeTreeXPath = function(node){
// Built from Firebug source -
// https://github.com/firebug/firebug/blob/235efff40332f85cb34b55f2da0de6bf98d083e4/extension/content/firebug/lib/xpath.js
var paths = [], nodePath, element = node;
// If text node find its place among its siblings
if(element.nodeType == Node.TEXT_NODE){
var siblings = node.parentElement.childNodes;
var nodeIndex = Array.prototype.indexOf.call(siblings, node)+1;
@matt-curtis
matt-curtis / gist:c0fa7aa820d6257e7b2a
Last active August 21, 2019 13:49
UINavigationBar Multiline Title
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(!self.navigationItem.titleView){
self.navigationItem.titleView = ({
UILabel *titleView = [UILabel new];
titleView.numberOfLines = 0;
titleView.textAlignment = NSTextAlignmentCenter;
titleView.attributedText = [[NSAttributedString alloc] initWithString:@"2\nLINES" attributes:
self.navigationController.navigationBar.titleTextAttributes