tag:blogger.com,1999:blog-78475816653577932692025-11-19T08:51:52.478+01:00Code Monkey Dobrbrennahttp://www.blogger.com/profile/17040589850564990345noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-7847581665357793269.post-71006254046759373002010-05-19T13:28:00.001+02:002010-05-19T13:28:18.706+02:00A git workflow using bundles<p>Disclaimer: I am a git n00b, so there are probably better ways to do this.</p> <p>Below is the git workflow I use for cases when I do development on two boxes (named Local and Remote below), but there is no way to clone/fetch/pull directly.</p> <p>(Local) Create the initial bundle and create a tag:</p> <pre class="literal-block"> $ git bundle create toremote.bundle HEAD $ git tag toremote </pre> <p>Transfer the bundle file to the remote computer.</p> <p>(Remote) Initialize an empty repository, and pull from the bundle file:</p> <pre class="literal-block"> $ mkdir repo $ cd repo $ git init $ git pull /tmp/toremote.bundle </pre> <p>(Remote) Create a tag:</p> <pre class="literal-block"> $ git tag fromlocal </pre> <p>You now do some bugfixing or development on the remote computer. Use git as normal and commit your changes.</p> <p>(Remote) Then create a bundle containing your changes, and create a tag:</p> <pre class="literal-block"> $ git bundle create tolocal.bundle fromlocal..HEAD $ git tag -f tolocal </pre> <p>Transfer the bundle file to the local computer.</p> <p>(Local) Pull from the bundle to update the local repository:</p> <pre class="literal-block"> $ git pull tolocal.bundle $ git tag -f fromremote </pre> <p>You then do some hacking on the local computer. Use git as normal and commit your changes.</p> <p>(Local) Then create a bundle containing your changes, and create a tag:</p> <pre class="literal-block"> $ git bundle create toremote.bundle toremote..HEAD $ git tag -f toremote </pre> <p>Transfer the bundle file to the remote computer.</p> <p>(Remote) Pull from the bundle and create a tag:</p> <pre class="literal-block"> $ git pull /path/to/toremote.bundle $ git tag -f fromlocal </pre> brbrennahttp://www.blogger.com/profile/17040589850564990345noreply@blogger.com0tag:blogger.com,1999:blog-7847581665357793269.post-47738888546635905312009-06-21T15:26:00.001+02:002009-06-22T14:02:02.895+02:00Using the Blogger API from Python<p>Blogger exposes a Google Data API. Using this API, you can access all parts of your blog using simple HTTP requests. The REST-style API is based on the Atom Publishing Protocol.</p> <p>It is very easy to access the blogger API (or any Google Data API) from Python using the <a class="reference external" href="http://code.google.com/p/gdata-python-client/">Google Data APIs Python Client Library (gdata-python-client)</a>. This library is easy to use, has great documentation and great sample code included.</p> <p>Using <a class="reference external" href="http://docutils.sourceforge.net/rst.html">reStructuredText</a> and gdata-python-client I created a simple application (<tt class="docutils literal"><span class="pre">blogger.py</span></tt>) that takes a rst file, converts it to HTML and publishes the HTML on my blog.</p> <p>Using this approach, I can edit blog posts in <a class="reference external" href="http://www.vim.org">a my editor of choice</a>, using an easy-to-read plaintext markup syntax.</p> <p>Example use:</p> <div class="highlight"><pre><span style="color: #408080; font-style: italic"># first, get the blog id</span> <span style="color: #666666">(</span>vanilla<span style="color: #666666">)[</span>~/misc/blogger<span style="color: #666666">]</span> <span style="color: #19177C">$ </span>python blogger.py --username my.email@gmail.com --listblogs Password: nnnnnnnnnnnnnnnnnnn: Code Monkey Do <span style="color: #408080; font-style: italic"># then create a new blog post</span> <span style="color: #666666">(</span>vanilla<span style="color: #666666">)[</span>~/misc/blogger<span style="color: #666666">]</span> <span style="color: #19177C">$ </span>python blogger.py --username my.email@gmail.com --blog nnnnnnnnnnnnnnnnnnn post1.rst Password: <span style="color: #19177C">$ </span>python blogger.py --help ... </pre></div> <p><tt class="docutils literal"><span class="pre">blogger.py</span></tt> source code (<a class="reference external" href="http://github.com/codeape2/python-blogger/tree/master/blogger.py">on github</a>):</p> <div class="highlight"><pre><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">rstdirective</span> <span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">login</span>(username, password): <span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">gdata.service</span> service <span style="color: #666666">=</span> gdata<span style="color: #666666">.</span>service<span style="color: #666666">.</span>GDataService(username, password) service<span style="color: #666666">.</span>service <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;blogger&#39;</span> service<span style="color: #666666">.</span>server <span style="color: #666666">=</span> <span style="color: #BA2121">&#39;www.blogger.com&#39;</span> service<span style="color: #666666">.</span>ProgrammaticLogin() <span style="color: #008000; font-weight: bold">return</span> service <span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">create_entry</span>(title, content, draft<span style="color: #666666">=</span><span style="color: #008000">False</span>): <span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">atom</span> <span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">gdata</span> entry <span style="color: #666666">=</span> gdata<span style="color: #666666">.</span>GDataEntry() entry<span style="color: #666666">.</span>title <span style="color: #666666">=</span> atom<span style="color: #666666">.</span>Title(title_type<span style="color: #666666">=</span><span style="color: #BA2121">&#39;text&#39;</span>, text<span style="color: #666666">=</span>title) entry<span style="color: #666666">.</span>content <span style="color: #666666">=</span> atom<span style="color: #666666">.</span>Content(content_type<span style="color: #666666">=</span><span style="color: #BA2121">&#39;html&#39;</span>, text<span style="color: #666666">=</span>content<span style="color: #666666">.</span>encode(<span style="color: #BA2121">&#39;utf8&#39;</span>)) <span style="color: #008000; font-weight: bold">if</span> draft: control <span style="color: #666666">=</span> atom<span style="color: #666666">.</span>Control() control<span style="color: #666666">.</span>draft <span style="color: #666666">=</span> atom<span style="color: #666666">.</span>Draft(text<span style="color: #666666">=</span><span style="color: #BA2121">&#39;yes&#39;</span>) entry<span style="color: #666666">.</span>control <span style="color: #666666">=</span> control <span style="color: #008000; font-weight: bold">return</span> entry <span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">listblogs</span>(service): feed <span style="color: #666666">=</span> service<span style="color: #666666">.</span>Get(<span style="color: #BA2121">&#39;/feeds/default/blogs&#39;</span>) <span style="color: #008000; font-weight: bold">for</span> blog <span style="color: #AA22FF; font-weight: bold">in</span> feed<span style="color: #666666">.</span>entry: <span style="color: #008000; font-weight: bold">print</span> <span style="color: #BA2121">&quot;</span><span style="color: #BB6688; font-weight: bold">%s</span><span style="color: #BA2121">: </span><span style="color: #BB6688; font-weight: bold">%s</span><span style="color: #BA2121">&quot;</span> <span style="color: #666666">%</span> (blog<span style="color: #666666">.</span>GetSelfLink()<span style="color: #666666">.</span>href<span style="color: #666666">.</span>split(<span style="color: #BA2121">&#39;/&#39;</span>)[<span style="color: #666666">-1</span>], blog<span style="color: #666666">.</span>title<span style="color: #666666">.</span>text) <span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">listposts</span>(service, blogid): feed <span style="color: #666666">=</span> service<span style="color: #666666">.</span>Get(<span style="color: #BA2121">&#39;/feeds/&#39;</span> <span style="color: #666666">+</span> blogid <span style="color: #666666">+</span> <span style="color: #BA2121">&#39;/posts/default&#39;</span>) <span style="color: #008000; font-weight: bold">for</span> post <span style="color: #AA22FF; font-weight: bold">in</span> feed<span style="color: #666666">.</span>entry: <span style="color: #008000; font-weight: bold">print</span> post<span style="color: #666666">.</span>GetEditLink()<span style="color: #666666">.</span>href<span style="color: #666666">.</span>split(<span style="color: #BA2121">&#39;/&#39;</span>)[<span style="color: #666666">-1</span>], post<span style="color: #666666">.</span>title<span style="color: #666666">.</span>text, <span style="color: #BA2121">&quot;[DRAFT]&quot;</span> <span style="color: #008000; font-weight: bold">if</span> is_draft(post) <span style="color: #008000; font-weight: bold">else</span> <span style="color: #BA2121">&quot;&quot;</span> <span style="color: #408080; font-style: italic"># ... see full source code on github: http://github.com/codeape2/python-blogger/tree/master/blogger.py</span> </pre></div> <p>If you are not familiar with the reStructuredText format, have a look at <a class="reference external" href="http://github.com/codeape2/python-blogger/tree/master/posts/codemonkeydo/using-the-blogger-api-from-python">this example</a>, the rst source for this post.</p> <p>You can download the entire source code from <a class="reference external" href="http://github.com/codeape2/python-blogger">github</a>.</p> brbrennahttp://www.blogger.com/profile/17040589850564990345noreply@blogger.com2tag:blogger.com,1999:blog-7847581665357793269.post-10591185146391359002009-06-04T13:34:00.004+02:002009-06-04T13:44:24.712+02:00Stack overflow reputationI've been using SO for a while now. Nice site for programming QA (I try to answer some <a href="http://stackoverflow.com/questions/tagged/python">Python</a> questions when I have the time). Recently, they added 'flair' - the ability to display your SO reputation on you site. Here's my SO reputation points: <script src="http://stackoverflow.com/users/flair/3571.js?theme=clean" type="text/javascript"></script>brbrennahttp://www.blogger.com/profile/17040589850564990345noreply@blogger.com1tag:blogger.com,1999:blog-7847581665357793269.post-74377922766575651892008-08-29T06:43:00.001+02:002009-06-21T14:45:29.359+02:00A new brace style for C-like languagesToday I came up with a brand new <a href="http://www.c2.com/cgi/wiki?OneTrueBraceStyle">brace</a> <a href="http://catb.org/%7Eesr/jargon/html/I/indent-style.html">style</a>, heavily influenced by <a href="http://www.python.org/">Python</a>. It is like K&amp;R, but with the <b>closing brace appended to the last line of the block</b>. It looks like this (the example code is C# that targets CLR v 1.1): <p></p><pre>using System; using System.Collections; using System.Reflection; namespace Utils.Documentation { public class TypeDocumenter { private Type _type; private MethodInfo[] _methods; public TypeDocumenter(Type type) { Debug.Assert(type != null); _type = type; _methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); } public MethodDocumenter[] Methods { get { ArrayList retval = new ArrayList(); foreach (MethodInfo m in _methods) { if (! m.IsSpecialName) { retval.Add(new MethodDocumenter(m)); }} return (MethodDocumenter[]) retval.ToArray(typeof(MethodDocumenter)); }} public DocumentationParser XmlDocumentation(DocumentationReader docreader) { Debug.Assert(docreader != null); return new DocumentationParser(docreader.GetXmlDocumentationForType(_type)); }}} </pre> <p> This style feels and looks very natural to me, and I am going to start using it for all C# code I write from now on (which is very little - I do 90% of my development in Python). </p> <p> I use a combination of VIM and Visual Studio .NET when developing C# code. The VIM editor handles this brace style very naturally. I haven't had time to tinker with VS.NET's indentation settings yet. </p> <p> Notice that the namespace declaration has the same indent level as the class declaration. I have always done this when programming C#, since the horizontal whitespace used for indenting a class does not add any information. </p> <p> Previously I used the Allman/Emacs brace style, BTW. </p>brbrennahttp://www.blogger.com/profile/17040589850564990345noreply@blogger.com0