Wednesday, October 31, 2012

git how to get all branches into existing local repo?

git how to get all branches into existing local repo?

Git: How to get all branches of remote repo into existing local repo, WITHOUT using git clone into a new directory? (Because you just want to get the diff, and not have to re-download every single thing -__-")


http://www.kernel.org/pub/software/scm/git/docs/git-clone.html

GIT URLS

In general, URLs contain information about the transport protocol, the address of the remote server, and the path to the repository. Depending on the transport protocol, some of this information may be absent.
Git natively supports ssh, git, http, https, ftp, ftps, and rsync protocols. The following syntaxes may be used with them:
  • ssh://[user@]host.xz[:port]/path/to/repo.git/
  • git://host.xz[:port]/path/to/repo.git/
  • http[s]://host.xz[:port]/path/to/repo.git/
  • ftp[s]://host.xz[:port]/path/to/repo.git/
  • rsync://host.xz/path/to/repo.git/
An alternative scp-like syntax may also be used with the ssh protocol:
  • [user@]host.xz:path/to/repo.git/
The ssh and git protocols additionally support ~username expansion:
  • ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
  • git://host.xz[:port]/~[user]/path/to/repo.git/
  • [user@]host.xz:/~[user]/path/to/repo.git/
For local repositories, also supported by git natively, the following syntaxes may be used:
These two syntaxes are mostly equivalent, except the former implies --local option.
When git doesn’t know how to handle a certain transport protocol, it attempts to use the remote-<transport> remote helper, if one exists. To explicitly request a remote helper, the following syntax may be used:
  • <transport>::<address>
where <address> may be a path, a server and path, or an arbitrary URL-like string recognized by the specific remote helper being invoked. See git-remote-helpers(1) for details.
If there are a large number of similarly-named remote repositories and you want to use a different format for them (such that the URLs you use will be rewritten into URLs that work), you can create a configuration section of the form:


2
Git for human beings


3
http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git

If you have many remote branches that you want to fetch at once:
$ git remote update
$ git pull --all
Now you can checkout any branch as you need to, without hitting the remote repo.


But it doesn't seem to do what was asked... If you run those commands and then run "git branch" you will still only see the branches that you had to begin with. – infosec812 Oct 27 '11 at 17:13


4
http://stackoverflow.com/questions/6373277/git-sync-local-repo-with-remote-one

I'm a git noob so this might look like a silly question.
I have local & remote git repositories. I want to sync my local repository with remote repository so that my local repository becomes 100% copy of remote repository. Meaning that if certain files differ in these repos we override local ones with remote ones. And if there are files in local repos that do not exist in remote repo, local files get removed.
Is there a way to achieve that other than doing a fresh clone of remote repo?





7
what is git fetch
http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch

In the simplest terms, git pull does a git fetch followed by a git merge.
You can do a git fetch at any time to update your local copy of a remote branch. This operation never changes any of your own branches and is safe to do without changing your working copy. I have even heard of people running git fetch periodically in a cron job in the background (although I wouldn't recommend doing this).
git pull is what you would do to bring your repository up to date with a remote repository.


5
http://blog.mikepearce.net/2010/05/18/the-difference-between-git-pull-git-fetch-and-git-clone-and-git-rebase/

Git rebase

Finally, git rebase is pretty cool. Anything you’ve changed by committing to your current branch but are no in the upstream are saved to a temporary area, so your branch is the same as it was before you started your changes, IE, clean. It then grabs the latest version of the branch from the remote If you do ‘git pull –rebase’, git will pull down the remote changes, rewind your local branch, then replays all your changes over the top of your current branch one by one, until you’re all up to date. Awesome huh?

Finally..

If you get stuck, run ‘git branch -a’ and it will show you exactly what’s going on with your branches. You can see which are remotes and which are local. This is a good headsup before you start to break things! It’s worth remembering that git branches are basically just a pointer, so to be able to work with those commits you need a local branch which points to somewhere from which those commits are reachable.
Thanks to Ben for the extra stuff, clarifications and calling me an idiot when I get git wrong, because I am, as it’s really pretty simple, except for the simple.












Thursday, October 25, 2012

return str(asdf) or unicode(asdf) ?




*** Python 2.7.2 (default, Jun 24 2011, 12:22:14) [MSC v.1500 64 bit (AMD64)] on win32. ***
*** Remote Python engine  is active ***
>>> import bleach
>>> print bleach.linkify('an http://example.com url')
an <a href="http://example.com" rel="nofollow">http://example.com</a> url
>>> print bleach.linkify('<a href="http://example.com" rel="nofollow">http://example.com</a>')
<a href="http://example.com" rel="nofollow">http://example.com</a>
>>> print bleach.linkify('an <a href="http://example.com" rel="nofollow">http://example.com</a> url')
an <a href="http://example.com" rel="nofollow">http://example.com</a> url
>>> print str(u'asdf')
asdf
>>> print str(u'asdf')
asdf
>>> print str('中国')
中国
>>> print str(u'中国')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
>>> print unicode('中国')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
>>> print unicode('中国')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
>>> print str(u'中国')
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
>>> print str('asdf')
asdf
>>> print unicode('asdf')
asdf



>>> a = str('asdf')
>>> print a
asdf
>>> a
'asdf'
>>> b = unicode('asdf')
>>> print b
asdf
>>> b
u'asdf'



>>> print str('中国')
中国









Store in database as unescaped html tags.. escape only on displaying (from db).

1
http://stackoverflow.com/questions/11844218/xml-to-web2py-html-tag-conversion



The database is storing the original HTML. However, any text written to a web2py view is automatically escaped, so the HTML code displays literally rather than being rendered as HTML. To avoid that, as you have pointed out, you can simply wrap the HTML in the XML() helper.
Be careful, though -- you should not do this with input entered by users. A malicious user could enter Javascript code, which could create a security vulnerability for other users viewing that content (this is why web2py automatically escapes everything in the first place). To be safer, you could also doXML(..., sanitize=True).




2
http://stackoverflow.com/questions/9679561/how-can-i-prevent-web2py-from-automagically-encoding-html-entities


I'm trying to print out HTML generated for user-submitter markdown, by
{{=markdown(post.message)}}
where markdown function is imported through
from gluon.contrib.markdown.markdown2 import markdown
We2Py seems to automatically encode HTML-Entities, so every < is converted into &lt; and every> is converted into &gt;. How do I prevent this from happening?
Are there any security concerns that I'll need to keep in mind while doing so? Also, could anyone kindly tell me how can I strip the HTML when storing it in the database, while retaining the markdown?



Answer:

You have to do this:
{{=XML(markdown(post.message))}}
every string is sanitized by template render, if you pass "<div>" it will be rendered as"&lt;div&gt;" it is to protect against malicious code.
















Web2py escaping html tags.

To NOT escape html tags/entities:



http://web2py.com/books/default/chapter/29/05#XML
Epydoc:
http://www.web2py.com/examples/static/epydoc/web2py.gluon.html.XML-class.html#__init__


XML

XML
XML is an object used to encapsulate text that should not be escaped. The text may or may not contain valid XML. For example, it could contain JavaScript.
The text in this example is escaped:
>>> print DIV("<b>hello</b>")
&lt;b&gt;hello&lt;/b&gt;
by using XML you can prevent escaping:
>>> print DIV(XML("<b>hello</b>"))
<b>hello</b>
Sometimes you want to render HTML stored in a variable, but the HTML may contain unsafe tags such as scripts:
>>> print XML('<script>alert("unsafe!")</script>')
<script>alert("unsafe!")</script>
Un-escaped executable input such as this (for example, entered in the body of a comment in a blog) is unsafe, because it can be used to generate Cross Site Scripting (XSS) attacks against other visitors to the page.
sanitize
The web2py XML helper can sanitize our text to prevent injections and escape all tags except those that you explicitly allow. Here is an example:
>>> print XML('<script>alert("unsafe!")</script>', sanitize=True)
&lt;script&gt;alert(&quot;unsafe!&quot;)&lt;/script&gt;
The XML constructors, by default, consider the content of some tags and some of their attributes safe. You can override the defaults using the optional permitted_tags and allowed_attributes arguments. Here are the default values of the optional arguments of the XML helper.
XML(text, sanitize=False,
    permitted_tags=['a', 'b', 'blockquote', 'br/', 'i', 'li',
       'ol', 'ul', 'p', 'cite', 'code', 'pre', 'img/'],
    allowed_attributes={'a':['href', 'title'],
       'img':['src', 'alt'], 'blockquote':['type']})

Best rich text editor for web2py- fckeditor.

Best rich text editor for web2py- fckeditor,

which when edit source, pretty prints the source html tags.


https://bitbucket.org/PhreeStyle/web2py_ckeditor/wiki/Home





2
how to change web2py sqlform widget JIT.

http://web2py.com/book/default/chapter/07


Widgets can also be assigned to fields a posteriori:
db.mytable.myfield.widget = SQLFORM.widgets.string.widget
Sometimes widgets take additional arguments and one needs to specify their values. In this case one can use lambda



db.mytable.myfield.widget = SQLFORM.widgets.string.widget
form = SQLFORM(db.mytable)

HTML evil tags sanitizing with Python: Bleach is the best library!

Google Search:
html sanitizer for python





>>> import bleach
>>> print bleach.linkify('an http://example.com url')
an <a href="http://example.com" rel="nofollow">http://example.com</a> url
>>> print bleach.linkify('<a href="http://example.com" rel="nofollow">http://example.com</a>')
<a href="http://example.com" rel="nofollow">http://example.com</a>
>>> print bleach.linkify('an <a href="http://example.com" rel="nofollow">http://example.com</a> url')
an <a href="http://example.com" rel="nofollow">http://example.com</a> url
>>>


It's smart enough not to 'double linkify' it.

https://github.com/jsocol/bleach
http://bleach.readthedocs.org/en/latest/goals.html
http://coffeeonthekeyboard.com/bleach-html-sanitizer-and-auto-linker-for-django-344/




Basic Use

The simplest way to use Bleach is:
>>> import bleach

>>> bleach.clean('an <script>evil()</script> example')
u'an &lt;script&gt;evil()&lt;/script&gt; example'

>>> bleach.linkify('an http://example.com url')
u'an <a href="http://example.com" rel="nofollow">http://example.com</a> url
NB: Bleach always returns a unicode object, whether you give it a bytestring or a unicode object, but Bleach does not attempt to detect incoming character encodings, and will assume UTF-8. If you are using a different character encoding, you should convert from a bytestring to unicode before passing the text to Bleach.













Tuesday, October 23, 2012

Favicon links

http://www.11articles.com/?20090716

Add a Favicon.ico to Your Site


By Zabrina Way
Being a successful webmaster is all about paying attention to the little details. One of those often-overlooked little details -- 16 by 16 pixels, to be exact -- is a favicon.ico.
What is a favicon.ico?
A favicon.ico, also known as a favicon, is a small image file that represents a website, much like a logo. The most important thing to remember is that it will be displayed alongside your website's name in a user's favorites menu (this includes "bookmarks" in other browsers). It is also usually displayed in the tab title (if the browser supports tabs) while surfing your site. In some browsers, it is displayed in the URL or location bar, too.



http://stackoverflow.com/questions/2268204/web-favicon-dimensions
Something similar is said on W3.org: w3.org/2005/10/howto-favicon They also specify the formats: The format of the image must be one of PNG (a W3C standard), GIF, or ICO. – Zasurus Jun 26 at 11:24


Wikipedia has this to say:
Additionally, such icon files can be either 16×16 or 32×32 pixels in size, and either 8-bit or 24-bit in color depth (note that GIF files have a limited, 256 color palette entries).
I think the best way is to use a 32x32 gif and test it with different browsers.


http://www.w3.org/2005/10/howto-favicon

Method 1 (Preferred): Use of a rel attribute value defined in a profile

The first approach for specifying a favicon is to use the rel attribute value "icon" and to define what the value means via a profile; profiles are discussed in more detail below. In this HTML 4.01 example, the favicon identified via the URI http://example.com/myicon.png as being a favicon:
<!DOCTYPE html 
      PUBLIC "-//W3C//DTD HTML 4.01//EN"
      "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head profile="http://www.w3.org/2005/10/profile">
<link rel="icon" 
      type="image/png" 
      href="http://example.com/myicon.png">
[…]
</head>
[…]
</html>


http://stackoverflow.com/questions/9312638/optimal-format-and-size-and-browser-support-of-a-favicon

Not all browsers support all sizes of favicons. The best 'one' to use, is the one that will be displayed! That said In my experience, a 32x32 PNG file looks the best.
You can use <link rel='icon' href='images/favicon.png' type='image/png' /> in your<head> tag to specify the icon picture and keep a smaller 16x16 ICO file in the root directory as well. This will let the browsers that can't handle displaying a PNG file for a favicon, fallback to the ICO in the root directory.


Sunday, October 21, 2012

Installers for Python packages for Windows, 64-bit, python2.7.

Installers for Python packages for Windows, 64-bit, python2.7.

http://www.lfd.uci.edu/~gohlke/pythonlibs/
PIL for python2.7 64bit
Crypto (needed for paramiko) etc.











Friday, October 19, 2012

how to tar an archive without getting the intermediate directories?

how to tar an archive without getting the intermediate directories?

http://www.thegeekstuff.com/2010/04/unix-tar-command-examples/

tar czf filename.tar.gz somefolder/
tar xzf filename.tar.gz





3
How I did it in my jenkins shell script:


cd importtool/src/ && python get_latest_schema.py
cd ../../ && tar cvzf importtool.tar.gz -C importtool/ src/


What this does is, tells:
1) tar to -C change the current directory to importtool/, and then tar its file/folder 'src/'.
2) since the working dir is / , the file importtool.tar.gz comes out at the same level as importtool/







2
Prevent parent directories from being tarred
http://stackoverflow.com/questions/4031416/prevent-parent-directories-from-being-tarred

How do I tar a directory of files and folders without including the directory itself?
http://stackoverflow.com/questions/939982/how-do-i-tar-a-directory-of-files-and-folders-without-including-the-directory-it

Q

Basically I just want to tar all the files in a directory, but not get all the parent directories in the archive.
I've tried -C, but I guess I'm not using it right.
tar -cjf archive.tar.bz2 -C /var/some/log/path ./*
This results in tar trying to add all the files in the CWD. Using the full path as last argument doesn't prevent the dirs from being added.
Seems simple enough, but can't figure it out. Somehow tar does not tar ./* as being relative to -C, although it should change to that dir.
Help appreciated.

A

The parent directory (/var/some/log) is included, since /var/some/log/path/.. is included when you do ./*. Try just doing
tar -cjf archive.tar.bz2 -C /var/some/log/path .
Test run:
$ find tmp/some_files
tmp/some_files
tmp/some_files/dir1
tmp/some_files/dir1/dir1file
tmp/some_files/hello
tmp/some_files/world
tmp/some_files/dir2
tmp/some_files/dir2/dir2file
$ tar -cvjf archive.tar.bz2 -C tmp/some_files/ .
./
./dir1/
./dir1/dir1file./hello./world./dir2/
./dir2/dir2file
$ cd tmp/unpacked/tmp/unpacked$ mv /home/aioobe/archive.tar.bz2 .
/tmp/unpacked$ tar -xvjf archive.tar.bz2 ./
./dir1/
./dir1/dir1file./hello./world./dir2/
./dir2/dir2file/tmp/unpacked$ ls
archive.tar.bz2  dir1  dir2  hello  world/tmp/unpacked$ 

That's somewhat better, but now it ads "." as a parent directory in the tar. I want only the files. – Joe Oct 27 '10 at 16:25
No, the "./" prefix is just notation. It contains the files in the "root" of the archive. – aioobe Oct 27 '10 at 16:51
Ah. I see. My bad. – Joe Oct 27 '10 at 17:01



Q

I typically do:
tar -czvf my_directory.tar my_directory
What if I just want to include everything (including any hidden system files) in my_directory, but not the directory itself? I don't want:
my_directory
   --- my_file
   --- my_file
   --- my_file
I want:
my_file
my_file
my_file


A1

cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd .. 
should do the job in one line. It works well for hidden files as well. "*" doesn't expand hidden files by path name expansion at least in bash. Below is my experiment:
$ mkdir my_directory
$ touch my_directory/file1
$ touch my_directory/file2
$ touch my_directory/.hiddenfile1
$ touch my_directory/.hiddenfile2
$ cd my_directory/ && tar -zcvf ../my_dir.tgz . && cd ..
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2
$ tar ztf my_dir.tgz
./
./file1
./file2
./.hiddenfile1
./.hiddenfile2

This will also work on files with spaces or other special characters. Good job! – PanCrit Jun 3 '09 at 20:45

A2

Use the -C switch of tar:
tar -czvf my_directory.tar.gz -C my_directory .
The -C my_directory tells tar to change the current directory to my_directory, and then .means "add the entire current directory" (including hidden files and sub-directories).

+1 thank you! It was the damn '.' I was missing. so aggravating – JCotton May 5 '11 at 2:08