11/26/13

Countcha Blog

Countcha news and updates...

Dec 1
Version 4 status - in development
• Full version: save and reopen counters, more units, new theme colors, no Ads.

Nov 30
Version 3 available on the App Store, free.
• Improved Help Functions tab now shows visual example of gestures.




Nov 19
Version 2 available on the App Store, free.
• Menu gesture hint is shown on start up and hidden on first menu gesture
• Hint is re-displayed anytime all counters are deleted

Nov 10
Version 1 available on the App Store, free.

Misc

Countcha Website
iTunes


4/15/13

C

iOS Assets Library

#import <AssetsLibrary/AssetsLibrary.h>

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    [self dismissViewControllerAnimated:YES completion:nil];
    NSURL * assetUrl = [info objectForKey:UIImagePickerControllerReferenceURL];
    NSLog(@"%@", assetUrl.absoluteString);  //"assets-library://asset/asset.JPG?id=ABC7EF08-B1BF-4FFB-9FF9-4FF70FD0610F&ext=JPG"
    [self loadImageFromAsset:assetUrl];
}

-(void)loadImageFromAsset:(NSURL *)assetUrl
{
    ALAssetsLibrary * assetLib = [[ALAssetsLibrary alloc] init];
    [assetLib assetForURL:assetUrl
              resultBlock:^(ALAsset * asset)
                          {
                              ALAssetRepresentation * assetRep = [asset defaultRepresentation];
                              CGImageRef image = [assetRep fullScreenImage];  //full-screen-image to show edited version
                              [self setImageViewWithImage:image];
                          }
             failureBlock:^(NSError * error)
                          {
                              //log...
                          }];
}

-(void)setImageViewWithImage:(CGImageRef)image
{
    UIImageView * imageView = (UIImageView *)[[self view] viewWithTag:ivTag];
    [imageView setImage:[UIImage imageWithCGImage:image]];
}


-----------------------------------------------------------

Objective-C Delegate Protocol

Use UIResponder touchesBegan:withEvent and a protocol to enable a UIImageView to respond to user touch. Sends message to delegate (view controller in this example), delegate can then respond to image touch by launching image picker, etc


Storyboard - ESTouchImageView Settings


Components




ESTouchViewDelegate (Protocol)
- declares the protocol delegate method esTouchViewMsg
- when the user touches a view, an esTouchViewMsg should be sent to the delegate (class) that conforms to the protocol
//file ESTouchViewDelegate.h
@protocol ESTouchViewDelegate<NSObject>

    -(void)esTouchViewMsg;
@end

ESTouchImageView (Custom UIImageView Class)
- has ESTouchViewDelegate protocol property
- on touchesBegan:withEvent: sends esTouchViewMsg to delegate (class) that conforms to the protocol
//file ESTouchImageView.h
#import "ESTouchViewDelegate.h"

@interface ESTouchImageView: UIImageView

    @property (weak, nonatomic) id<ESTouchViewDelegate> esTouchViewDelegate;
@end


//file ESTouchImageView.m
#import "ESTouchImageView.h"

@implementation ESTouchImageView

    //send touch message to delegate from UIResponder touches began event
    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        NSLog(@"ESTouchImageView - touchesBegan");
        [self sendESTouchViewMsgToDelegate];
    }

    -(void)sendESTouchViewMsgToDelegate
    {
        NSLog(@"ESTouchImageView - sendESTouchViewMsgToDelegate");
        [[self esTouchViewDelegate] esTouchViewMsg];
    }
@end

ESViewController (Delegate)
- has ESTouchImageView control
- conforms to the ESTouchViewDelegate protocol
- is the delegate (ESTouchViewDelegate) for ESTouchImageView
- sets self (view controller) as delegate using IBOutlet property (or viewWithTag reference)
- will respond to the esTouchViewMsg delegate method
//file ESViewController.h
#import "ESTouchImageView.h"

    @interface ESViewController: UIViewController<ESTouchViewDelegate>

        @property (weak, nonatomic) IBOutlet ESTouchImageView * esTouchImageView;
    @end


//file ESViewController.m
#import "ESViewController.h"

@implementation ESViewController

    -(void)viewDidLoad
    {
        [super viewDidLoad];

        //set delegate using IBOutlet property
        [[self esTouchImageView] setEsTouchViewDelegate:self];  //set view controller as delegate

        //set delegate using viewWithTag reference
        //ESTouchImageView * esTouchImageView = (ESTouchImageView *)[[self view] viewWithTag:100];
        //[esTouchImageView setEsTouchViewDelegate:self];  //set view controller as delegate
    }

    -(void)esTouchViewMsg
    {
        NSLog(@"ESViewController - esTouchViewMsg");
        //launch image picker, etc
    }
@end

NSLog Output
ESTouchImageView - touchesBegan
ESTouchImageView - sendESTouchViewMsgToDelegate
ESViewController - esTouchViewMsg

-----------------------------------------------------------

Objective-C Delegate Protocol

On scene exit, send exit message from destination/presented view to the source/presenting view, pass bool indicating cancelled
//file ESExitSceneDelegate.h
@protocol ESExitSceneDelegate<NSObject>

    @optional
    -(void)esExitSceneMsg;
    -(void)esExitSceneMsgCancelled:(BOOL)cancelled;
@end


//file ESEditViewController.h
#import "ESExitSceneDelegate.h"  //protocol

@interface ESEditViewController: UITableViewController

    @property (weak, nonatomic) id<ESExitSceneDelegate> esExitSceneDelegate;
 // @property (weak, nonatomic) IBOutlet UIBarButtonItem * uiCancelBtn;
    @property (weak, nonatomic) IBOutlet UIBarButtonItem * uiSaveBtn;
@end


//file ESEditViewController.m
#import "ESEditViewController.h"

@implementation ESEditViewController
{
    //ivar referencing outlet, alt to prop
    IBOutlet UIBarButtonItem * uiCancelBtn;
}

    -(IBAction)cancel:(id)sender
    {
        [[self navigationController] popToRootViewControllerAnimated:YES];
        [[self esExitSceneDelegate] esExitSceneMsgCancelled:YES];
    }

    -(IBAction)save:(id)sender
    {
        [[self navigationController] popToRootViewControllerAnimated:YES];
        [[self esExitSceneDelegate] esExitSceneMsgCancelled:NO];
    }


//file ESViewController.h
#import "ESExitSceneDelegate.h"  //protocol

@interface ESViewController: UIViewController<ESExitSceneDelegate>
@end


//file ESViewController.m
#import "ESEditViewController.h"
#import "ESViewController.h"

@implementation ESViewController

    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        ESEditViewController * esEditViewController = segue.destinationViewController;
        [esEditViewController setEsExitSceneDelegate:self];  //set delegate
    }

    -(void)esExitSceneMsgCancelled:(BOOL)cancelled
    {
        if (cancelled)
        {
            //...
        }
        else
        {
            //...
        }
    }
@end

1/2/13

PC Load Letter - Google Checkout Wallet "Oops" Error

Anybody know a solution to this error?

Get error when trying to sign up to sell Android apps on Google Play Developers site.
Error occurs when submitting the Google Merchant Account Business Information page.







Links
http://code.google.com/p/android/issues/detail?id=35945
http://productforums.google.com/forum/#!topic/android-market/AB6F-YcJ5bg
http://productforums.google.com/forum/#!msg/checkout-merchant/nwRms9_LgHA/UP8Pdf25TFoJ


ahhhh, Thank you Onion, "mf time vampire" :)
"Google Releases Stupid F*cking Piece Of Sh*t That Doesn't F*cking Work!"
http://www.youtube.com/watch?v=AOgwQZd9eDc
http://www.youtube.com/watch?v=8AyVh1_vWYQ

5/2/12

Emacs Keyboard Shortcuts

GNU Emacs v22.1.1 (mac-apple-darwin)
ctl  control key
met  escape / option / alt key  (settings -> keyboard -> use option as meta key)
cmd  command key / apple key

//FILES, BUFFERS
ctl + X, ctl + F        open file, find file
ctl + X, ctl + V        find alternate file
ctl + X, ctl + S        save
ctl + X, ctl + W        save as
met + X, revert-buffer  revert
ctl + X, K              close, kill buffer
ctl + X, ctl + Q        toggle buffer read-only
ctl + X, ctl + B        list buffers
ctl + X, B              toggle between 2 buffers
ctl + x, B, [temp]      new temp buffer
ctl + X, right          select next buffer, loop
ctl + X, left           select prev buffer, loop
ctl + G                 abort command, escape minibuffer

//NAVIGATE
met + V                 page up
ctl + V                 page down
met + <                 move cursor to start of file
met + >                 move cursor to end of file
ctl + A                 move cursor to start of line
ctl + E                 move cursor to end of line
met + B                 move cursor left 1 word
met + F                 move cursor right 1 word
ctl + L                 center current line in window
cmd + right             focus next window, loop
ctl + X, RM             set bookmark
ctl + X, RB             goto bookmark
met + X, goto-line, 42

//EDIT
ctl + J                 new line with indentation
ctl + M, ctl + K        delete sentence
met + C                 capitalize word, repeat
met + U                 uppercase word, repeat
met + L                 lowercase word, repeat
ctl + X, I              insert file
ctl + X, U              undo
met + /                 abbreviation
met + X, abbrev-mode    word abbreviation
         ctl + X, AIL   add-inverse-local
         [abb]          abbreviation, br
         [def]          definition,   <br />

;LISP, SHELL
ctl + met + X           define function, cursor outside last paren
ctl + X, ctl + E        eval expression, eval-last-sexp
ctl + G, Q              abort command, quit debugger, lisp error
met + !                 run shell command, ls -1alt ~/*.txt

//MISC
ctl + X, ctl + C        quit/exit
cmd + I                 apple terminal inspector
ctl + H                 help
ctl + H, M              describe mode
ctl + Z                 suspend
FG                      restart from suspend, fg = foreground

//SEARCH
ctl + S, [text]         search, i-search, incremental
         ctl + S        search forward, find next match
         enter          stop search
ctl + R, [text]         search reverse
         ctl + R        search reverse, find previous match
ctl + S, ctl + W        search current word at cursor, cursor first letter

//REGEX SEARCH
ctl + met + S, [regex]         regex search, eg [0-9] instead of \d
ctl + S, ctl + Q, [tab]        regex search tab characters
met + X, query-replace-regexp  regex search and replace, prompt
         Y/N                   replace/do not replace, skip
met + X, replace-regexp        regex search and replace all, no prompt


CRM  BUFFER      SIZE  MODE              FILE
.%   file1.txt   1234  Text              ~/file1.txt
  *  file2.el     500  Emacs-Lisp        ~/file2.el
  *  *scratch*    100  Lisp Interaction
  *  *Messages*   200  Fundamental
CRM
.   current
 %  read only
  * modified

MODE LINE
-uu-:---F1  file1.txt  (write)
-uu-:%%-F1  file1.txt  (read-only)
-uu-:**-F1  file1.txt  (edit)
-uu-:%*-F1  file1.txt  (read-only, edit)

9/1/11

Powershell Asynchronous Download String

WebClient DownloadStringAsync
Powershell Register-ObjectEvent
PSEventArgs Properties
# - get webclient
$webClient = new-object net.webclient

# - register event handler for DownloadStringCompleted event
#   action script block is event handler code, show string DownloadStringCompletedEventArgs.Result
register-objectEvent $webClient downloadStringCompleted e1 {write-host $args[1].result}  #positional input params

# - begin asynchronous download string
#   event handlers will execute when download is complete
$webClient.downloadStringAsync("http://www.expressionsoftware.com")

# - list event subscriptions
get-eventSubscriber  #output #SubscriptionId  : 1
                             #SourceObject    : System.Net.WebClient
                             #EventName       : downloadStringCompleted
                             #SourceIdentifier: e1
                             #Action          : System.Management.Automation.PSEventJob
                             #SupportEvent    : False
                             #ForwardEvent    : False
                             #HandlerDelegate :

# - list jobs
get-job | fl  #output  #Id           : 1
                       #Name         : e1
                       #Command      : write-host $args[1].result
                       #State        : Running
                       #JobStateInfo : Running
                       #HasMoreData  : True
                       #Finished     : System.Threading.ManualResetEvent
                       #InstanceId   : 010f31f4-e8d2-4742-a782-79057faefebf
                       #Module       : __DynamicModule_a48149c1-5a56-4172-bc68-473ec7c83119
                       #StatusMessage:   #Location
                       #ChildJobs    : {}  #Output, Error, Progress, Verbose, Debug, Warning

# - register another handler, multiple event handlers supported, named input params
register-objectEvent -inputObject $webClient `
                     -eventName downloadStringCompleted `
                     -sourceIdentifier e2 `
                     -action {write-host ("async event at {0}`nevent handler source identifier: {1}`n{2}" -f ($event.timeGenerated.tostring("HH:mm:ss")), $event.sourceIdentifier, $args[1].result)}

# - unregister events
unregister-event -subscriptionId 1
unregister-event -sourceIdentifier e2
get-eventsubscriber -force | unregister-event -force  #unregister all events

# - synchronous download string
$webClient.downloadString("http://www.expressionsoftware.com")

Powershell asynchronous download file with WebClient DownloadFileAsync

8/25/11

CSS Selector & XPath Expression Browser Commands

CSS selectors and XPath expressions can be used to answer queries such as
- How many scripts does this page have?
- How many are external? What are they?
- How many are inline? Show me the source.

CSS Selectors - W3
"Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to select nodes in an XML document. Selectors have been optimized for use with HTML and XML, and are designed to be usable in performance-critical code."

Firefox and Chrome support CSS and XPath commands in the console via the Firebug Command Line API.

Syntax
$$(selector)  Returns an array of elements that match the given CSS selector.
$x(xpath)     Returns an array of elements that match the given XPath expression.
$(id)         Returns a single element with the given id.
CSS Selector Examples
//scripts
$$("script")                     //script tags
$$("script").length              //count
$$("script[async]")              //async scripts
$$("script[src]")                //external scripts with src
$$("script:not([src])")          //inline scripts with no src not
$$("script:not([src])")[0].text  //show inline script source code

//list external scripts src url
var x = $$("script[src]"); console.log("page: " + window.location.href + "\n" + x.length + " external scripts"); for(var i = 0;i < x.length; i++){console.log(x[i].src)}

//list inline script source code
var x = $$("script:not([src])"); console.log("page: " + window.location.href + "\n" + x.length + " internal scripts"); for(var i = 0;i < x.length; i++){console.log("script #" + (i + 1.0) + "\n" + x[i].text)}

//*************
//anchors
$$("a")                   //anchor tags
$$("a").length            //count
$$("a[class]")            //anchors with class
$$("a[href]")             //anchors with hrefs
$$("a:not([href])")       //anchors with no hrefs not
$$("a[href*=foo]")        //anchors with href url containing "foo"
$$("a[href*=\\?]")        //anchors with href url containing querystring
$$("a[onclick]")          //anchors with onclick event
$$("a[onclick^=foobar]")  //anchors with onclick event name starts with foobar

//list anchor link href urls
var x = $$("a[href]"); console.log("page: " + window.location.href + "\n" + x.length + " anchor urls"); for(var i = 0;i < x.length; i++){console.log(x[i].href)}

//*************
//images
//list image src urls
var x = $$("img[src]"); console.log("page: " + window.location.href + "\n" + x.length + " image urls"); for(var i = 0;i < x.length; i++){console.log(x[i].src)}

//*************
//iframes
//list iframe src urls
var x = $$("iframe"); console.log("page: " + window.location.href + "\n" + x.length + " iframes"); for(var i = 0;i < x.length; i++){console.log("id: " + x[i].id +"\nsrc: "+ x[i].src)}

//*************
//meta tags
$$("meta[name^=descr]")[0].content  //description meta tag, meta tag with name starts with "descr"
$$("meta[name$=words]")[0].content  //keywords meta tag, meta tag with name ends with "words"

//list meta tags
var x = $$("meta"); console.log("page: " + window.location.href + "\n" + x.length + " meta tags"); for(var i = 0;i < x.length; i++){console.log(x[i])}

//*************
//all elements
$$("[class]")      //elements with class
$$("[class=foo]")  //elements with class name equal "foo" match
$$("[id]")         //elements with id

//list element ids
var x = $$("[id]"); console.log("page: " + window.location.href + "\n" + x.length + " ids"); for(var i = 0;i < x.length; i++){console.log(x[i].id)}

CSS Selector Syntax: www.w3.org/TR/css3-selectors/#selectors
Chrome Dev Tools Resources UI can be used to access image and external script info.
Don't even ask about ie just view source.


8/1/11

Visual Studio 2010 VB.NET Macros

'Visual Studio 2010 VB.NET Macros
'www.expressionsoftware.com
'v11.8.1

Imports System
Imports System.Collections.Generic
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100

Public Module ExpressionSoftwareMacros

    Sub PrintFilenamesForOpenFiles()
        Dim output = "macro: PrintFilenamesForOpenFiles" + vbCrLf
        Dim outputFiles As String
        Dim openFiles = GetOpenFiles()

        'openFiles.Sort()  'error: failed to compare two elements in the array
        openFiles.Sort(New EnvDteDocumentComparerClass())

        For Each file In openFiles
            outputFiles += "file: " + file.FullName + vbCrLf
        Next

        output += "date: " + Date.Now + vbCrLf
        output += "count: " + Str(openFiles.Count) + vbCrLf
        output += outputFiles
        Out(output)
    End Sub

    Sub HideLinebreakToBrace()
        Dim output = "macro: HideLinebreakToBrace" + vbCrLf
        Dim count = 0

        'vs pofs regex
        ':b whitespace or tab
        'Dim searchString = ":b*\n:b*\{"  'matches "\b\n{" which cannot be hidden, can use if count is not output, else count incorrect
        Dim searchString = "{:b+\n:b*\{}|{:b*\n:b+\{}"

        DTE.Find.FindWhat = searchString
        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument  'search current file only
        DTE.Find.Action = vsFindAction.vsFindActionFind
        DTE.Find.MatchInHiddenText = True
        DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr  'regex search
        DTE.SuppressUI = False

        DTE.ActiveDocument.Selection.StartOfDocument()  'set cursor top of file
        While DTE.Find.Execute() <> vsFindResult.vsFindResultNotFound
            count += 1
            DTE.ActiveDocument.Selection.CharLeft(True, 1)  'unselect brace char
            DTE.ExecuteCommand("Edit.HideSelection")
        End While
        DTE.ActiveDocument.Selection.StartOfDocument()

        output += "date: " + Date.Now + vbCrLf
        output += "file: " + DTE.ActiveDocument.FullName + vbCrLf
        output += "count: " + Str(count)
        Out(output)
    End Sub

    Private Function GetOpenFiles() As List(Of EnvDTE.Document)
        Dim openFiles As New List(Of EnvDTE.Document)

        For Each doc As EnvDTE.Document In DTE.Documents
            If doc.ProjectItem IsNot Nothing Then  'todo: combine 
                If doc.ProjectItem.IsOpen() Then
                    openFiles.Add(doc)
                End If
            End If
        Next

        Return openFiles
    End Function

    Private Sub Out(ByVal output)
        GetMacrosOutputWindow().OutputString(output)
    End Sub

    'requires Microsoft Samples Utilities module,
    'copy module into MyMacros project
    Private Function GetMacrosOutputWindow() As OutputWindowPane
        Dim windowTitle = "Expression Software Macros"
        Dim window As Window
        Dim target As Object
        Dim document As EnvDTE.Document

        window = DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
        If DTE.ActiveWindow Is window Then
            target = window.Object
        Else
            target = Utilities.GetOutputWindowPane(windowTitle)
            target.clear()
        End If

        Return target
    End Function
End Module


Public Class EnvDteDocumentComparerClass
    Implements IComparer(Of EnvDTE.Document)

    'compare docs by full filename, for sorting
    Function Compare(ByVal file1 As EnvDTE.Document, _
                     ByVal file2 As EnvDTE.Document) _
                     As Integer Implements IComparer(Of EnvDTE.Document).Compare

        Return file1.FullName.CompareTo(file2.FullName)
    End Function
End Class


Public Class EnvDteDocumentComparableClass
    Implements IComparable(Of EnvDTE.Document)

    'compare docs by full filename, for sorting
    Function CompareTo(ByVal other As EnvDTE.Document) _
                       As Integer Implements IComparable(Of EnvDTE.Document).CompareTo

        Return FullName.CompareTo(other.FullName)
    End Function
End Class


'**************************************************************
'Misc
'DTE.Documents.Count includes closed docs
'DTE.ActiveDocument.FullName
'output += "date: " + Date.Now + vbCrLf
'Microsoft.VisualBasic.Constants.vbCrLf
'DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
'keyboard shortcuts
'  alt + F8    macro explorer
'  alt + F11   macros ide
'**************************************************************