Showing posts with label github. Show all posts
Showing posts with label github. Show all posts

Tuesday, December 4, 2012

Using Github for Windows

I have started using the Github Windows GUI for using git on Windows, and so far I am very impressed. Github has made it very easy to download (clone) an entire directory tree of code files to a new computer, something I have to do more often that I would like. Git is an incredibly powerful tool for version control, and I really do not scratch the surface of its functionality. An important thing to remember for a novice user is that it is best to make sure you are working with the newest version of the repository before you start making edits on any given computer. Otherwise merging the edits from different computers (or users) can be hard. This can be accomplished by opening the github GUI before editing any files and clicking 'sync.'

Note: If, when setting up your repository, you accidentally included files that you did not want to have git follow, you can use this command:
git rm --cached <filename> 
by going to tools>open a shell here in the github GUI. You may also have to include a new line in your .gitignore file...

When you inevitably (in my experience) get an error message along the lines of "failed to sync this branch" with options to "open shell to debug" or "cancel," choose the former, and typing
git push
or
git pull 
depending on if you are trying to upload (push) or download (pull) changes from github.com will sometimes work.

Sunday, June 24, 2012

Code snippets in blogger

I have been experimenting with ways to post code snippets to this blog. Here are two strategies that seem to work:

Strategy 1.

Paste snippets to http://www.smipple.net, then embed them using the embed feature. You can log on to smipple using your google account.



Strategy 2.

Following the advice found here, I experimented with https://code.google.com/p/google-code-prettify/. I just embedded the following code after the meta tag of the html of this blog's template

<link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' rel='stylesheet' type='text/css'/>
<script src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js' type='text/javascript'/>
and this in the script tag

prettyPrint();

I've been testing this as I go, and I see that those snippets are overflowing the intended area. After looking in the code from the example, I see that I need to also add this to the css part of the blog's template (I stuck it right after the closing bracket for the .post-body entry:

pre.prettyprint {
overflow: auto;
}

Now, to embed code I can just type something like this:

<pre class="prettyprint lang-py">var i = 2 + 4;
</pre>


Using this system, our example snippet looks like this:

import numpy as np

def circmean(alpha,axis=None):
    mean_angle = np.arctan2(np.mean(np.sin(alpha),axis),np.mean(np.cos(alpha),axis))
    return mean_angle
    
def circvar(alpha,axis=None):
    if np.ma.isMaskedArray(alpha) and alpha.mask.shape!=():
        N = np.sum(~alpha.mask,axis)
    else:
        if axis is None:
            N = alpha.size
        else:
            N = alpha.shape[axis]
    R = np.sqrt(np.sum(np.sin(alpha),axis)**2 + np.sum(np.cos(alpha),axis)**2)/N
    V = 1-R
    return V

Neither works perfectly. You must re-insert the code into the html template each time you change the blog's layout. Constantly switching between blogger and smipple doesn't seem great, either...

Strategy 3.

Andrew gave me the idea of using github gists. Here is a test: