{"id":574,"date":"2013-12-08T08:35:03","date_gmt":"2013-12-08T13:35:03","guid":{"rendered":"http:\/\/www.clayford.net\/statistics\/?p=574"},"modified":"2013-12-08T08:35:03","modified_gmt":"2013-12-08T13:35:03","slug":"getting-started-with-github-gist-in-wordpress","status":"publish","type":"post","link":"https:\/\/www.clayford.net\/statistics\/getting-started-with-github-gist-in-wordpress\/","title":{"rendered":"Getting started with GitHub Gist in WordPress"},"content":{"rendered":"<p>I&#8217;ve decided it&#8217;s time to use GitHub Gist for posting code snippets in my blog. My original motivation was better syntax highlighting. I was using WP Code Highlight, which isn&#8217;t bad. It&#8217;s easy to use and does what it promises. But it doesn&#8217;t add line numbers and the syntax highlighting doesn&#8217;t seem optimal for R. GitHub Gist on the other hand handles R code beautifully. <\/p>\n<p>Now highlighted code is nice, but what&#8217;s really cool about Gist is that the code is actually stored in a repository. This means I can update the code without having to update my WordPress post. And it&#8217;s easier for other people to use should they ever want to use my code. <a href=\"https:\/\/help.github.com\/articles\/creating-gists\">And there are other benefits as well<\/a>. I guess the only bad thing is that GitHub has my code, which would be bad if they went belly-up. I&#8217;m pretty sure that won&#8217;t happen though, because I don&#8217;t want to think about it.<\/p>\n<p>So here&#8217;s how you use GitHub Gist with WordPress to host R code. First create an account on GitHub and go to <a href=\"https:\/\/gist.github.com\/\">GitHub Gist<\/a>. Where it says &#8220;Name of file&#8221;, type the name of your file and add &#8220;.r&#8221; to the end. Next select R from the language pulldown, though Gist will probably select it for you if you typed a file name ending in &#8220;.r&#8221;. Now copy and paste your code into the editor and click &#8220;create public gist&#8221;. You&#8217;re done with GitbHub<\/p>\n<p>To make this block of code appear in your WordPress post, copy the code in the &#8220;Embed this gist&#8221; field and paste into your post. (Make sure you&#8217;re in the Text editor instead of the Visual editor). It would be really nice if that was the end of it, but it&#8217;s not. WordPress strips out the embed code and nothing happens. The workaround is to add a little plug-in called <a href=\"http:\/\/w-shadow.com\/blog\/2007\/12\/13\/raw-html-in-wordpress\/\">Raw HTML<\/a>. As the description says, &#8220;This plugin adds a set of shortcodes that you can use to &#8220;protect&#8221; specific parts of your post and prevent WP from messing with them.&#8221; Awesome, just what we need. So the final step is to surround the Gist embed code with &#91;raw&#93;&#8230;&#91;\/raw&#93; shortcode. (A tip of my hat to <a href=\"http:\/\/www.presscoders.com\/2012\/12\/10-things-i-hate-about-wordpress\/\">this site<\/a> for telling me about Raw HTML.<\/p>\n<p>Let&#8217;s try this out. Here&#8217;s some code that samples 30 values from a N(15,2) distribution, calculates a 95% confidence interval, and plots the interval as a line. It does this 40 times and colors the CI&#8217;s that don&#8217;t capture 15 red. <\/p>\n\r\n<script src=\"https:\/\/gist.github.com\/clayford\/7842136.js\"><\/script>\r\n\n<p>To make that appear in my post, I added the following: <\/p>\n<p>&#91;raw&#93;<br \/>\n&lt;script src=&#8221;https:\/\/gist.github.com\/clayford\/7842136.js&#8221;&gt;&lt;\/script&gt;<br \/>\n&#91;\/raw&#93;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve decided it&#8217;s time to use GitHub Gist for posting code snippets in my blog. My original motivation was better&#8230; <a class=\"read-more\" href=\"https:\/\/www.clayford.net\/statistics\/getting-started-with-github-gist-in-wordpress\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,13],"tags":[38,37],"class_list":["post-574","post","type-post","status-publish","format-standard","hentry","category-simulation","category-using-r","tag-gist","tag-github"],"_links":{"self":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/comments?post=574"}],"version-history":[{"count":10,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/574\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/posts\/574\/revisions\/593"}],"wp:attachment":[{"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/media?parent=574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/categories?post=574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clayford.net\/statistics\/wp-json\/wp\/v2\/tags?post=574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}