honzasheepskin

5 Mar

Clipped from link: https://github.com/honza/sheepskin

honza/sheepskin

Sheep Skin is a document authoring utility. It allows you to write your document in Markdown and then compile it to HTML, Latex (PDF) and epub. It’s especially useful for writing long, multi-section documents (such as books or reports). It uses Pandoc to parse your Markdown.

Javascript – How to parse xml, write to html5 local storage, then read from local storage, and allow user to search content.

27 Feb

Javascript – How to parse xml, write to html5 local storage, then read from local storage, and allow user to search content. from http://mantascode.com/javascript-how-to-readwrite-html5-local-storage/

This simple example will demonstrate how to use javascript to write to, and read from, html5 local storage.

The file being parsed and saved is books.xml.  There are two html pages here, LAUNCH.html and OFFLINE.html.

LAUNCH.html will parse the xml file and write it to the user’s browser:

OFFLINE.html will allow the user to search the content of their local storage

 

LAUNCH.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

This page will parse and save books.xml into the users browser<br />
specifically into html5 localStorage<br />
The xml file being pushed is called books.xml<br />
<br />
<a href="books.xml">books.xml</a>
<br />
<a href="OFFLINE.html">OFFLINE.html</a>

<script type="text/javascript">  

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

var xmlRowString = "";

for (var i = 0; i < xmlDoc.documentElement.childNodes.length; i++)
{
if ( xmlDoc.documentElement.childNodes[i].nodeName == 'book' )
{
for ( var k = 0 ; k < xmlDoc.documentElement.childNodes[i].childNodes.length; k++ )
{
if ( xmlDoc.documentElement.childNodes[i].childNodes[k].nodeName == 'author' )
{
xmlRowString += "<book><author>"+xmlDoc.documentElement.childNodes[i].childNodes[k].textContent+"</author>";
}
if ( xmlDoc.documentElement.childNodes[i].childNodes[k].nodeName == 'title' )
{
xmlRowString += "<title>"+xmlDoc.documentElement.childNodes[i].childNodes[k].textContent+"</title>";
}
if ( xmlDoc.documentElement.childNodes[i].childNodes[k].nodeName == 'description' )
{
xmlRowString += "<description>"+xmlDoc.documentElement.childNodes[i].childNodes[k].textContent+"</description></book>";
}
}
}
if ( xmlRowString === "" )
{
}
else
{
//Here for each book we populate a local stoage row
if (typeof(localStorage) == 'undefined' ) 
{
alert('Your browser does not support HTML5 localStorage. Try upgrading.');
} 
else 
{
try                          
{ 
localStorage.setItem(i, xmlRowString);
} 
catch (e) 
{
alert("save failed!");
if (e == QUOTA_EXCEEDED_ERR) 
{
alert('Quota exceeded!'); //data wasn't successfully saved due to quota exceed so throw an error
}
}
}
xmlRowString = "";	
}
}

</script>

</body>
</html>

OFFLINE.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search local storage</title>
</head>

<body>

This page will allow the user to search the content saved in your local storage.<br />
Search By Author name, results will be returned by book title.<br />

<form action="OFFLINE.html" method="get">
  Search By Author : <input type="text" name="txtA" /><br />
  <input type="submit" value="Submit" />
</form> 
<br />
<br />

<div id="results_ID"></div>

<script type="text/javascript">

var localStorageRow = localStorage.getItem(localStorage.key(i)) ;

var author_query = getUrlVars()["txtA"];

if (typeof(author_query) == "undefined" || author_query === "" )
{
}
else
{
for ( var i = 0 ; i < localStorage.length;  i++)
{
var localStorageRow = localStorage.getItem(localStorage.key(i)) ;

if (window.DOMParser)
{
parser=new DOMParser();
xmlDoc=parser.parseFromString(localStorageRow,"text/xml");
}
else // Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(localStorageRow);
} 

for ( var k = 0 ; k < xmlDoc.firstChild.childNodes.length ; k++ )
{
if ( xmlDoc.firstChild.childNodes[k].nodeName === "author" )
{

var auth_row = xmlDoc.firstChild.childNodes[k].textContent;			
var authMatch = auth_row.match(new RegExp(author_query, "i"));
if ( authMatch )
{
//CANNOT USE XPATH(a lot of browsers dont support this) 
//YOU HAVE TO LOOP THOUGH ELEMENTS (again) TO GET TITLE
/*
var nodesSnapshot = document.evaluate('//title', xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );  
for ( var q=0 ; q < nodesSnapshot.snapshotLength; q++ )  
{  
document.getElementById("results_ID").innerHTML += nodesSnapshot.snapshotItem(q).textContent+"<br />";
}  
*/

for ( var p = 0 ; p < xmlDoc.firstChild.childNodes.length ; p ++ )
{
if ( xmlDoc.firstChild.childNodes[p].nodeName == 'title' )
{
document.getElementById("results_ID").innerHTML += xmlDoc.firstChild.childNodes[p].textContent+"<br />";
}
}

}
}
}
}
}

//GET URL VARS function
function getUrlVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}

</script>

</body>
</html>
This entry was posted in Javascript. Bookmark the permalink.

 

Question
if the pages are on a web server and the book.xml is on my PC
How can we access the file on my pc using HTML tags and perform the search

  • Stefano says:

    What you should do is upload book.xml and it’s definition file (if available) via ftp to the same web server where the pages are. Then the pages can find the XML file.

Kellytom/FileNameTagging · GitHub

22 Feb

Kellytom/FileNameTagging · GitHub.

Proposed Convention for File Naming with Tags

File Name Tagging

I have considered long (several months) and hard (for me) how to organize my files. Here I want to propose a “standard” for filenames that would allow sorting files by tags or labels. The operating systems and programs involved include Windows, ios Dropbox, Google Drive, Evernote, and others. The other operating systems are ones I don’t use: Linux, any ix, OS X, etc. so I am ignorant of their details.

I propose ending filenames with the tags. The filenames are then sorted in reverse order. The standard can be used for bookmarks, posts, or filenames, or anything that needs to be organized.

Level 1:

This is the simplest level. Like so:

My filename writing.txt

Level 2:

The next level is to append a special character like “-” at the end of the filename. I call that character “the tag flag character.” Like so:

My filename writing-.txt

This gives us at least one tag to sort by.

Level 3:

The next level is to put as many tags as possible, including numbers for sequential order. For example:

filename 001 writing-.txt

Level 4:

Programs and apps:

The rest of the proposed convention would have to do with programs and methods to do the sorting and tagging of different files or bookmarks or posts.

  • The advantage of this system is that it can be used immediately with most existing programs that do file searches. For example, a sort for “fun-” would turn up all files including the word “fun-“
  • Each system and program would need a separate method to view, sort, and rename the files.
  • I would call the program that uses this convention just to view and sort the files and perhaps rename them a “helping program.”
  • The absolute simplest solution would be that the filenames could be sorted by direct reverse order Direct reverse order would give a sort result something like:

(-1gat enamelif.txt):
filename tag1-.txt
(-1gat -2gat enamelif.txt):
filename tag1- tag2-.txt
(-1gat -3gat enamelif.txt):
filename tag1- tag3-.txt

  • The next step is to parse or sort in a more complicated way. Each tag could make a separate entry for the file, e.g.

filename tag1- tag2-.txt

results in:

tag1- filename.txt
tag2- filename.txt

At minimum, the helping program would give a view of the files sorted by tag. Then the files could be opened in their respective applications by hand.

Level 5:

The checking and safety features would include:

  • to make sure the filenames are not too long,
  • make sure the user does not enter unsafe characters.
  • make sure the rename does not conflict with an open file.

Variations

  • Use another character at the end, instead of “-“; “the tag flag character” I could recommend any one of these: “-,Q,QQ, _” Personally I like “-“
  • Put the “tag flag character” after every tag, for example:

filename write- edit- scrivener-.txt

Principles

  • KISS – Keep it simple.
  • Make the smallest possible change.
  • Make the change as universal as possible.

Background

As I said before, I have considered long and hard how to organize my files. More on that here. These are the methods and programs I have tried or investigated:

  • Scrivener
  • Markdown
  • WordPresss
  • Evernote
  • etc.

I want to write articles, small books, programs, scripts and posts. I need to organize the material (clips, snippets, scraps) into drafts. The drafts need to be reorganized into finished works. Each step requires easy reorganization. That is why I want to use this file naming scheme.

The Simplest method

The simplest method would be to take the clipboard, sort it, and put it back on the clipboard. The sort would be a simple reverse order sort so the file would look like this:

-1gat enamelif.txt

The clipboard might look like this:

(-1gat enamelif.txt):
filename tag1-.txt
(-1gat -2gat enamelif.txt):
filename tag1- tag2-.txt
(-1gat -3gat enamelif.txt):
filename tag1- tag3-.txt

Conclusion

Input and suggestions are welcome. I will put it on Github for review and improvement.

Feature Requests – Pythonista Forums

19 Feb

Clipped from link: http://omz-software.com/pythonista/forums/discussion/22/feature-requests/p1

Feature Requests – Pythonista Forums

@rhithyn – You can already do that. If you use the modal parameter on the webbrowser class, it can run non-blocking in a different thread – leaving you free to run python code in the background to serve it up.

I’ve got several bits of code I’m working on right now that run python as the "server-side" code with the browser as the UI. Works great….

Feature Requests – Pythonista Forums

19 Feb

Clipped from link: http://omz-software.com/pythonista/forums/discussion/22/feature-requests/p1

Feature Requests – Pythonista Forums

I personally would love to see a simple WebKit- console viewer.. Set stdout to a WebKit browser. Form submits and page requests sent back as stdin… Then we could leverage pythonista as a "server-side" scripting language with an HTML5 FE… Robust UI elements to compliment the graphics set already available….

A live browser preview just General forum Sublime Text 2

19 Feb

Clipped from link: http://sublimetext.userecho.com/topic/92401-a-live-browser-preview-just-like-cssedit/#comment_176438

A live browser preview just … / General forum / Sublime Text 2

uick note: check out plugins. Many for LiveReload, many for open in browser. check youtube for ways to write a command yourself. I am looking for something that actually gives a preview IN Sublime, but I don’t think it exists. Need to open in the browser to keep up with latest browsers……

The best iPhone apps 15 ways to find them — Reality Distortion Macs Mac OS X and Apple stuff

19 Feb

Clipped from link: http://mac.elated.com/2009/01/19/the-best-iphone-apps-15-ways-to-find-them/

The best iPhone apps: 15 ways to find them – Reality Distortion: Macs, Mac OS X, and Apple stuff

Let’s face it: the App Store isn’t the easiest way to find the best iPhone or iPod touch apps.

Sure, it’s great to have all the apps in one place, but the App Store is a pain to navigate, and you can’t sort apps by rating, making it hard to separate the wheat from the chaff. Since the App Store now contains over 15,000 apps this can be a bit of a problem.

Fortunately, there are some great sites out there that make finding the best iPhone apps that much easier. Here’s my top 15:…