My studying notebook

2014/06/04

Welcome document

6/04/2014 09:07:00 PM Posted by Unknown 1 comment

Welcome to StackEdit!

this id d

Hello, I am your first Markdown document within StackEdit1. Don’t delete me, I can be helpful. I can be recovered anyway in the Utils tab of the Settings dialog.


Documents

StackEdit stores your documents in your browser, which means all your documents are automatically saved locally and are accessible offline!

NOTE:

  • StackEdit is accessible offline after the application has been loaded for the first time.
  • Your local documents are not shared between different browsers or computers.
  • Clearing your browser’s data may delete all your local documents! Make sure your documents are backed up using Google Drive or Dropbox synchronization (see Synchronization section).

Create a document

You can create a new document by clicking the button in the navigation bar. It will switch from the current document to the new one.

Switch to another document

You can list all your local documents and switch from one to another by clicking the button in the navigation bar.

Rename a document

You can rename the current document by clicking the document title in the navigation bar.

Delete a document

You can delete the current document by clicking the button in the navigation bar.

Save a document

You can save the current document to a file using the Save as... sub-menu from the menu.

Tip: See Publish a document section for a description of the different output formats.


Synchronization

StackEdit can be combined with Google Drive and Dropbox to have your documents centralized in the Cloud. The synchronization mechanism will take care of uploading your modifications or downloading the latest version of your documents.

NOTE:

  • Full access to Google Drive or Dropbox is required to be able to import any document in StackEdit.
  • Imported documents are downloaded in your browser and are not transmitted to a server.
  • If you experience problems exporting documents to Google Drive, check and optionally disable browser extensions, such as Disconnect.

Import a document

You can import a document from the Cloud by going to the Google Drive or the Dropbox sub-menu and by clicking Import from.... Once imported, your document will be automatically synchronized with the Google Drive / Dropbox file.

Export a document

You can export any document by going to the Google Drive or the Dropbox sub-menu and by clicking Export to.... Even if your document is already synchronized with Google Drive or Dropbox, you can export it to a another location. StackEdit can synchronize one document with multiple locations.

Tip: Using Google Drive, you can create collaborative documents to work in real time with other users. Just check the box Create a real time collaborative document in the dialog options when exporting to Google Drive.

Synchronize a document

Once your document is linked to a Google Drive or a Dropbox file, StackEdit will periodically (every 3 minutes) synchronize it by downloading/uploading any modification. Any conflict will be detected, and a local copy of your document will be created as a backup if necessary.

If you just have modified your document and you want to force the synchronization, click the button in the navigation bar.

NOTE: The button is disabled when you have no document to synchronize.

Manage document synchronization

Since one document can be synchronized with multiple locations, you can list and manage synchronized locations by clicking Manage synchronization in the menu. This will open a dialog box allowing you to add or remove synchronization links that are associated to your document.

NOTE: If you delete the file from Google Drive or from Dropbox, the document will no longer be synchronized with that location.


Publication

Once you are happy with your document, you can publish it on different websites directly from StackEdit. As for now, StackEdit can publish on Blogger, Dropbox, Gist, GitHub, Google Drive, Tumblr, WordPress and on any SSH server.

Publish a document

You can publish your document by going to the Publish on sub-menu and by choosing a website. In the dialog box, you can choose the publication format:

  • Markdown, to publish the Markdown text on a website that can interpret it (GitHub for instance),
  • HTML, to publish the document converted into HTML (on a blog for instance),
  • Template, to have a full control of the output.

NOTE: The default template is a simple webpage wrapping your document in HTML format. You can customize it in the Services tab of the Settings dialog.

Update a publication

After publishing, StackEdit will keep your document linked to that publish location so that you can update it easily. Once you have modified your document and you want to update your publication, click on the button in the navigation bar.

NOTE: The button is disabled when the document has not been published yet.

Manage document publication

Since one document can be published on multiple locations, you can list and manage publish locations by clicking Manage publication in the menu. This will open a dialog box allowing you to remove publication links that are associated to your document.

NOTE: In some cases, if the file has been removed from the website or the blog, the document will no longer be published on that location.


Markdown Extra

StackEdit supports Markdown Extra, which extends Markdown syntax with some nice features.

Tip: You can disable any Markdown Extra feature in the Extensions tab of the Settings dialog.

Tables

Markdown Extra has a special syntax for tables:

Item Value
Computer 1600 USD
Phone 12 USD
Pipe 1 USD

You can specify column alignment with one or two colons:

Item Value Qty
Computer 1600 USD 5
Phone 12 USD 12
Pipe 1 USD 234

Definition Lists

Markdown Extra has a special syntax for definition lists too:

Term 1
Term 2
Definition A
Definition B
Term 3

Definition C

Definition D

part of definition D

Fenced code blocks

GitHub’s fenced code blocks2 are also supported with Prettify syntax highlighting:

// Foo
var bar = 0;

Tip: To use Highlight.js instead of Prettify, just configure the Markdown Extra extension in the Settings dialog.

Footnotes

You can create footnotes like this3.

SmartyPants

SmartyPants converts ASCII punctuation characters into “smart” typographic punctuation HTML entities. For example:

ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is an en-dash and --- is an em-dash – is an en-dash and — is an em-dash

Table of contents

You can insert a table of contents using the marker [TOC]:

Comments

Usually, comments in Markdown are just standard HTML comments.
StackEdit extends HTML comments in order to produce useful, highlighted comments in the preview but not in your exported documents.

MathJax

You can render LaTeX mathematical expressions using MathJax, as on math.stackexchange.com:

The Gamma function satisfying Γ(n)=(n1)!nN is via the Euler integral

Γ(z)=0tz1etdt.

Tip: Make sure you include MathJax into your publications to render mathematical expression correctly. Your page/template should include something like:

<script type="text/javascript" src="https://stackedit.io/libs/MathJax/MathJax.js?config=TeX-AMS_HTML"></script>

NOTE: You can find more information:

  • about Markdown syntax here,
  • about Markdown Extra extension here,
  • about LaTeX mathematical expressions here,
  • about Prettify syntax highlighting here,
  • about Highlight.js syntax highlighting here.

var express = require('express');
var path = require('path');
var favicon = require('static-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var flash = require('express-flash');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');
var oauth = require('./routes/oauth');


  1. StackEdit is a full-featured, open-source Markdown editor based on PageDown, the Markdown library used by Stack Overflow and the other Stack Exchange sites.
  2. GitHub Flavored Markdown (GFM) is supported by StackEdit.
  3. Here is the text of the footnote.

2014/02/02

[Cydia] How to export Audio Record m4a directly.

2/02/2014 11:19:00 PM Posted by Unknown , , 1 comment
iOS Audio Record Cydia tweak is very a awesome tool to record voice phone call with ease. You all need to do is clicking the record button. There is a more detail introduction ( Record iPhone Calls With Audio Recorder – Free & No Warning | iPhone4idiots : http://www.iphone4idiots.com/2013/04/record-iphone-calls-with-audio-recorder-free-no-warning/)

Send m4a file via Email

Audio Record tweak default let you can send voice recording via email as following snapshot show. But you will not be able to send voice recording m4a file when file is too big.

Export m4a file via iFile/iTools etc tools

If we can not send voice recording file via email. You might think that we could get file directly. How do we do? In Audio Recorder list view. When you click shark button. Audio Recorder might take some time prepare data (m4a file) for sending via Email. Audio Recorder will create two m4a file in /var/tmp as following snapshot show. Both of them are same. 

Audio Recorder m4a file path

/var/tmp

2014/01/16

ASP.NET MVC 4 using Google Calendar API via OAuth 2

1/16/2014 10:26:00 PM Posted by Unknown , , , , , 12 comments

Scenario

It's more easily to log in your application via OAuth and OpenID provider in  ASP.NET MVC 4 now. Microsoft has few build-in client for Microsoft, Twitter, Facebook, Google. The Google client is based on OpenID and not OAuth. That's mean you can not access Google Data API. There is a post talk about how to implement custom Google client with Google+ login via OAuth in ASP.NET MVC 4. (http://www.beabigrockstar.com/google-signin-for-asp-net-mvc/ Google+ Signin for ASP.NET MVC - Be A Big Rockstar )

Register a Client ID for web application in Google Developer Console

In order to access Google Data API for web application. You need to register a Client ID to get Client ID an Client Secret for setting in your application.


As above snapshot show, you need to assign redirect URIs for grap OAuth access token callback also. Here we setup Rirect URIs as

 http://localhost:57271/Account/ExternalLoginCallback 

Google Client Library for .NET

The Google APIs Client Library for .NET is generic .NET runtime client for Google Services. The library supports OAuth2.0 authentication, and is able to generate strongly typed client libraries for Discovery-based services.
Google Client library is a higher level library for using Google Data API. You can download beta version from Nuget in visual studio.

 https://www.nuget.org/packages/Google.Apis.Calendar.v3/ 
It's more difficult to handle Google Client Library for .NET with few documents and sample now. Here, just using Google.Apis.Calendar.v3.Data namespace to our strong type class for data binding in deserialize object from API response.

        private Event GoogleEventHandle(string token, string method, string requestURL, string requestBody = null)
        {
            var jsonSerializer = new JavaScriptSerializer();
            var request = WebRequest.Create(requestURL) as HttpWebRequest;
            request.KeepAlive = true;
            request.ContentType = "application/json";
            request.Method = method;
            request.Headers.Add("Authorization", "Bearer " + token);

            if(requestBody != null)
            {
                Stream ws = request.GetRequestStream();
                using (var streamWriter = new StreamWriter(ws, new UTF8Encoding(false)))
                {
                    streamWriter.Write(requestBody);
                }
            }

            var response = request.GetResponse();
            var stream = new StreamReader(response.GetResponseStream());

            var googleEvent = Newtonsoft.Json.JsonConvert.DeserializeObject(stream.ReadToEnd().Trim());

            return googleEvent;  
        }

        private Event CreateGoogleEvent(string token, string calendarId, string requestBody)
        {
            var requestURL = string.Format("https://www.googleapis.com/calendar/v3/calendars/{0}/events", calendarId);
            return GoogleEventHandle(token, "POST", requestURL, requestBody);              
        }
Above is methods how we are accessing Google Calendar v3 API via webrequest.

MVC view

Now, we are be able to access Google Calendar API via OAuth. Nest step, we will create a simple CRUD UI by AngularJS. 

The Google Event we created and save to database also.

You should choose which calendar you want to create a new event.

You can modify event anytime you want.

What you will see in your Google Calendar.

Summary

  1. It a good topic to discuss where do you store the Access token from Google OAuth. Session or database?
  2. Google Client Library for .NET is a convienient library to access Google Data API with OAuth include. It's still in developing and i hope that there have more documents and samples to show how to use it.

Reference

Github repository

As always, all source code can be found in Github in the repository
 https://github.com/cage1016/ASPNETMvc4GoogleOAuth

2012/05/26

[Titanium]iOS: App build fails on Snow Leopard/iOS 4.3 configured machine

5/26/2012 04:55:00 PM Posted by Unknown , , 2 comments
OS
  • Lion 10.7.4
  • xCode 4.3
iPhone Simulator


Titanium SDK 1.7.5, 1.8.2, 2.0.1GA and 2.0.1.GA2. Everything does work on iPhone Simulator. But, it is very SLOW when you want to rebuild project or debug it.


Install to iOS Device

I got an error message below when i want to install project to iOS device in the couple days.  It success when i choose Titanium SDK lower 1.8x.

[ERROR] /Users/timothy/Documents/Titanium Studio Workspace/Scratch/build/iphone/Classes/NetworkModule.m:252:44: error: use of undeclared identifier 'UIRemoteNotificationTypeNewsstandContentAvailability' [2]
[ERROR] /Users/timothy/Documents/Titanium Studio Workspace/Scratch/build/iphone/Classes/NetworkModule.m:304:33: error: use of undeclared identifier 'UIRemoteNotificationTypeNewsstandContentAvailability' [2]
[ERROR] 
[ERROR] Error: Traceback (most recent call last):
File "/Library/Application Support/Titanium/mobilesdk/osx/2.0.1.v20120410131722/iphone/builder.py", line 1318, in main
execute_xcode("iphonesimulator%s" % link_version,["GCC_PREPROCESSOR_DEFINITIONS=__LOG__ID__=%s DEPLOYTYPE=development TI_DEVELOPMENT=1 DEBUG=1 TI_VERSION=%s %s %s" % (log_id,sdk_version,debugstr,kroll_coverage)],False)
File "/Library/Application Support/Titanium/mobilesdk/osx/2.0.1.v20120410131722/iphone/builder.py", line 1224, in execute_xcode
output = run.run(args,False,False,o)
File "/Library/Application Support/Titanium/mobilesdk/osx/2.0.1.v20120410131722/iphone/run.py", line 41, in run
sys.exit(rc)
SystemExit: 65

Finally, i got the solution when i search an issue tracker in appcelerator. This bug has fixed in Release 2.1.0.

Reference

2011/09/22

[Notebook] How to setup iphoneofflinemap on your iPhone, cydia requirement.

9/22/2011 11:47:00 PM Posted by Unknown , , , , 3 comments

Smart phone map App may have already improved your life experience if you ever used it. You can check map anytime and anywhere on your smart phone but internet necessary. Offlinemap let you can check map without internet. It's very convenient to you when you are in oversea or can't access the internet. 

iphoneofflinemap is an iphone cydia app that you can put offline map grabbed from Google map using GMDL (Global Map Download Tool)

simple scenario 

preparing necessary tools → backup current iphone cache map → Download target offline map → modify downloaded map → upload to iPhone → setup bookmark → respring

Step1.Getting started. You need to download few tools.
  1. GMDL (Global Map Download Tool). In iphoneofflinemap project. issues 59 reported: downloaded map doesn't work with ios4. Someone update a GMDL ip4 v10 hack. You can download hacked version here that you don't need to convert maps by mapconverter anymore.
  2. SQLite manager Firefox extension that you can modify downloaded map.
  3. iFunbox that you can upload offline maps to your iPhone very easily.
  4. install iphoneofflinemap app in cydia
Step2. backup iPhone current cache map.
Attache iPhone to computer and backup "/var/mobile/Library/Caches/Map/MapTiles/MapTiles.sqlitedb"  (this is original iPhone cache map)  by iFunbox.

Step3. Grab target offline map you want to download. 
  1. Download maps by GMDL.
  2. Convert maps tiles in an SQLite DB. The only one thing you should notice is locale. "en_TW" for example.

  3. In output folder. You can see "com.apple.Maps" and "MapTiles.sqlitedb". done.
Step4. Modify download maps.
  1. Open backup cache map earlier (original MapTiles.sqlitedb) by Firefox SQLite manager can check version and locale.

  2. Modify downloaded MapTiles.sqlistedb version and locale same as cache map.
Step5. Upload offline map to your iPhone.
  1. put target offline maps MapTiles.sqlitedb to "/var/mobile/Media/Maps/ChiMai". If Media don't have "Maps" folder, create one and put maps on folder you want by iFunbox.
Step6. Setup offline map bookmark.
Without internet access. you still can view map with GPS but search and direction. Therefore, it's better to put some map books in offline map also.

  1. you can visit Google Map (my places) and make some placemarks in maps called "Thailand trip" for example.

  2. copy KML address and visit (http://vcenter.iis.sinica.edu.tw/mobile/kml/loadkml_map.html) to convert those placemarks to iPhone plist.

  3. upload Bookmarks.plist to "/var/mobile/Library/Map" (it's better to backup original one)
Step7. respring (it's very important).
  1. open iphoneofflinemap (atlas) on iphone and "remove all  caches".
  2. type your map and select copy
  3. select "Continues". Do NOT select "Map" directly. 
  4. respring your iPhone 
  5. turn off 3G, WiFi and Data. You can use offline map now.
Result.


2011/09/04

[Notebook] Using jQuery templates in Google AppEngine

9/04/2011 10:52:00 PM Posted by Unknown , , , , , , 343 comments
jQuery is a powerful javascript library that you can improve web browser experience just add some js codes. jQuery also has a lot of useful plugin you can add. lightbox, autocomplete etc.

jQuery supports Templates plugin now that you can render HTML code very simply. Here has very detail document and tutorial. Today, i will talk about how to use jQuery templates in Google AppEngine. What is the problem using jQuery templates in Google AppEngine web application.? Braces {}.

Templates syntax.
Google AppEngine Django template.
{% for item in objs %}
 {{item}},
{% endfor %}

jQuery Templates
<script id="doclistTmp" type="text/x-jquery-tmpl">
        {{each(i, o) obj}}
        <tr class="{{if i%2== 0}}odd{{else}}even{{/if}}">
            <td> ${title}</td>
            <td>${type}</td>
            <td>${folders}</td>
        </tr>
        {{/each}}
</script>

They both use brases is problem that you will meet it if you want to use jQuery templates via ajax in Google AppEngine. Then, how to setup jQuery templates in Google AppEngine.

Step1.
Register a tag in a py file called "verbatim_templatetag.py" {{if condition}} print something{{/if}}. Tell Django don't change anything within this tag.
"""
jQuery templates use constructs like:

    {{if condition}} print something{{/if}}

This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.

Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
to output the contents with no changes.
"""

from django import template

register = template.Library()

class VerbatimNode(template.Node):

    def __init__(self, text):
        self.text = text

    def render(self, context):
        return self.text

@register.tag
def verbatim(parser, token):
    text = []
    while 1:
        token = parser.tokens.pop(0)
        if token.contents == 'endverbatim':
            break
        if token.token_type == template.TOKEN_VAR:
            text.append('{{')
        elif token.token_type == template.TOKEN_BLOCK:
            text.append('{%')
        text.append(token.contents)
        if token.token_type == template.TOKEN_VAR:
            text.append('}}')
        elif token.token_type == template.TOKEN_BLOCK:
            text.append('%}')
    return VerbatimNode(''.join(text))

Step2.
Include custom tag in your py file that you use web template
 template.register_template_library('verbatim_templatetag') 

Step3.
Add you jQuery template to html page.
 {% verbatim %}
        <script id="movieTemplate" type="text/x-jquery-tmpl">
            <tr>
                <td>${posted}</td>
                <td><a href="${link}">${response_count}</a></td>
                <td>{{html content}}</td>
            </tr>
        </script>
 {% endverbatim %} 

Step.4
call jQuery templates.
  $("#movieList").html($("#movieTemplate").tmpl( plurks )); 


Reference