Permalink
Browse files

first pass at import

  • Loading branch information...
1 parent 8fa1292 commit 72b227694fec242e906ab0a1b1044a2d2f32a84a @mmcgrana committed Nov 17, 2012
Showing with 13,834 additions and 18 deletions.
  1. +2 −0 .env
  2. +1 −0 Procfile
  3. +43 −6 README.md
  4. +29 −0 public/404.html
  5. +195 −0 public/arrays
  6. +207 −0 public/atomic-counters
  7. +179 −0 public/base64-encoding
  8. +145 −0 public/channel-buffering
  9. +138 −0 public/channel-directions
  10. +170 −0 public/channel-synchronization
  11. +160 −0 public/channels
  12. +185 −0 public/closing-channels
  13. +180 −0 public/closures
  14. +348 −0 public/collection-functions
  15. +159 −0 public/command-line-arguments
  16. +303 −0 public/command-line-flags
  17. +171 −0 public/constants
  18. +183 −0 public/defer
  19. +175 −0 public/environment-variables
  20. +166 −0 public/epoch
  21. +281 −0 public/errors
  22. +190 −0 public/execing-processes
  23. +162 −0 public/exit
  24. BIN public/favicon.ico
  25. +164 −0 public/for
  26. +152 −0 public/functions
  27. +196 −0 public/goroutines
  28. +132 −0 public/hello-world
  29. +174 −0 public/if-else
  30. +174 −0 public/index.html
  31. +222 −0 public/interfaces
  32. +379 −0 public/json
  33. +207 −0 public/line-filters
  34. +217 −0 public/maps
  35. +186 −0 public/methods
  36. +157 −0 public/multiple-return-values
  37. +285 −0 public/mutexes
  38. +165 −0 public/non-blocking-channel-operations
  39. +199 −0 public/number-parsing
  40. +163 −0 public/panic
  41. +183 −0 public/pointers
  42. +206 −0 public/random-numbers
  43. +174 −0 public/range
  44. +147 −0 public/range-over-channels
  45. +246 −0 public/rate-limiting
  46. +280 −0 public/reading-files
  47. +119 −0 public/recursion
  48. +320 −0 public/regular-expressions
  49. +172 −0 public/select
  50. +190 −0 public/sha1-hashes
  51. +177 −0 public/signals
  52. +201 −0 public/site.css
  53. +291 −0 public/slices
  54. +150 −0 public/sorting
  55. +167 −0 public/sorting-by-functions
  56. +244 −0 public/spawning-processes
  57. +303 −0 public/stateful-goroutines
  58. +426 −0 public/string-formatting
  59. +191 −0 public/string-functions
  60. +209 −0 public/structs
  61. +162 −0 public/switch
  62. +144 −0 public/tickers
  63. +254 −0 public/time
  64. +207 −0 public/time-formatting-parsing
  65. +182 −0 public/timeouts
  66. +160 −0 public/timers
  67. +222 −0 public/url-parsing
  68. +144 −0 public/values
  69. +173 −0 public/variables
  70. +163 −0 public/variadic-functions
  71. +205 −0 public/worker-pools
  72. +270 −0 public/writing-files
  73. +207 −0 server.go
  74. +1 −12 tools/generate.go
View
@@ -0,0 +1,2 @@
+CANONICAL_HOST=127.0.0.1
+FORCE_HTTPS=0
View
@@ -0,0 +1 @@
+web: gobyexample
View
@@ -22,7 +22,7 @@ To build the site:
```console
$ tools/build
-$ open site/index.html
+$ open public/index.html
```
To build continuously in a loop:
@@ -40,15 +40,52 @@ $ export PATH="$HOME/repos/pygments:$PATH"
```
-### Serving
+### Local Deploy
-The site is served by the [gobyexample-server](https://github.com/mmcgrana/gobyexample-server)
-tool. To export to this tool:
+```bash
+$ mkdir -p $GOPATH/src/github.com/mmcgrana
+$ cd $GOPATH/src/github.com/mmcgrana
+$ git clone git@github.com:mmcgrana/gobyexaple.git
+$ cd gobyexample
+$ go get
+$ foreman start
+$ foreman open
+```
-```console
-$ SITEDIR=../gobyexample-server/public tool/build
+
+### Platform Deploy
+
+Basic setup:
+
+```bash
+$ export DEPLOY=$USER
+$ heroku create gobyexample-$DEPLOY -r $DEPLOY
+$ heroku config:add -r $DEPLOY \
+ BUILDPACK_URL=https://github.com/kr/heroku-buildpack-go.git -r $DEPLOY \
+ CANONICAL_HOST=gobyexample-$DEPLOY.herokuapp.com -r $DEPLOY \
+ FORCE_HTTPS=1 \
+ AUTH=go:byexample
+$ git push $DEPLOY master
+$ heroku open -r $DEPLOY
```
+Add a domain + SSL:
+
+```bash
+$ heroku domains:add $DOMAIN
+$ heroku addons:add ssl -r $DEPLOY
+# order ssl cert for domain
+$ cat > /tmp/server.key
+$ cat > /tmp/server.crt.orig
+$ cat /tmp/server.crt.orig /tmp/rapidssl_bundle.pem > /tmp/server.crt
+$ heroku certs:add /tmp/server.crt /tmp/server.key -r $DEPLOY
+# add ALIAS record from domain to ssl endpoint dns
+$ heroku config:add CANONICAL_HOST=$DOMAIN -r $DEPLOY
+$ heroku open -r $DEPLOY
+```
+
+
+
### License
View
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-eqiv="content-type" content="text/html;charset=utf-8">
+ <title>Go by Example: Not Found</title>
+ <link rel=stylesheet href="site.css">
+ </head>
+ <script type="text/javascript">
+ if (window.location.host == "gobyexample.com") {
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-34996217-1']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ }
+ </script>
+ <body>
+ <div id="intro">
+ <h2><a href="./">Go by Example</a></h2>
+ <p>Sorry, we couldn't find that! Check out the <a href="./">home page</a>?</p>
+ <p class="footer">
+ <a href="https://twitter.com/gobyexample">@gobyexample</a> | <a href="mailto:mmcgrana@gmail.com">feedback</a> | <a href="https://github.com/mmcgrana/gobyexample">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
+ </p>
+ </div>
+ </body>
+</html>
View
@@ -0,0 +1,195 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta http-eqiv="content-type" content="text/html;charset=utf-8">
+ <title>Go by Example: Arrays</title>
+ <link rel=stylesheet href="site.css">
+ </head>
+ <script type="text/javascript">
+ if (window.location.host == "gobyexample.com") {
+ var _gaq = _gaq || [];
+ _gaq.push(['_setAccount', 'UA-34996217-1']);
+ _gaq.push(['_trackPageview']);
+ (function() {
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+ })();
+ }
+ </script>
+ <body>
+ <div class="example" id="arrays">
+ <h2><a href="./">Go by Example</a>: Arrays</h2>
+
+ <table>
+
+ <tr>
+ <td class="docs">
+ <p>In Go, an <em>array</em> is a numbered sequence of elements of a
+specific length.</p>
+
+ </td>
+ <td class="code empty leading">
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre><span class="kn">import</span> <span class="s">&quot;fmt&quot;</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre><span class="kd">func</span> <span class="nx">main</span><span class="p">()</span> <span class="p">{</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>Here we create an array <code>a</code> that will hold exactly
+5 <code>int</code>s. The type of elements and length are both
+part of the array&rsquo;s type. By default an array is
+zero-valued, which for <code>int</code>s means <code>0</code>s.</p>
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">a</span> <span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="kt">int</span>
+ <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;emp:&quot;</span><span class="p">,</span> <span class="nx">a</span><span class="p">)</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>We can set a value at an index using the
+<code>array[index] = value</code> syntax, and get a value with
+<code>array[index]</code>.</p>
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre> <span class="nx">a</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span> <span class="p">=</span> <span class="mi">100</span>
+ <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;set:&quot;</span><span class="p">,</span> <span class="nx">a</span><span class="p">)</span>
+ <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;get:&quot;</span><span class="p">,</span> <span class="nx">a</span><span class="p">[</span><span class="mi">4</span><span class="p">])</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>The builtin <code>len</code> returns the length of an array.</p>
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre> <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;len:&quot;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="nx">a</span><span class="p">))</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>Use this syntax to declare and initalize an array
+in one line.</p>
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre> <span class="nx">b</span> <span class="o">:=</span> <span class="p">[</span><span class="mi">5</span><span class="p">]</span><span class="kt">int</span><span class="p">{</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">}</span>
+ <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;dcl:&quot;</span><span class="p">,</span> <span class="nx">b</span><span class="p">)</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>Array types are one-dimensional, but you can
+compose types to build multi-dimensional data
+structures.</p>
+
+ </td>
+ <td class="code">
+ <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">twoD</span> <span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="mi">3</span><span class="p">]</span><span class="kt">int</span>
+ <span class="k">for</span> <span class="nx">i</span> <span class="o">:=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="p">&lt;</span> <span class="mi">2</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="nx">j</span> <span class="o">:=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">j</span> <span class="p">&lt;</span> <span class="mi">3</span><span class="p">;</span> <span class="nx">j</span><span class="o">++</span> <span class="p">{</span>
+ <span class="nx">twoD</span><span class="p">[</span><span class="nx">i</span><span class="p">][</span><span class="nx">j</span><span class="p">]</span> <span class="p">=</span> <span class="nx">i</span> <span class="o">+</span> <span class="nx">j</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="nx">fmt</span><span class="p">.</span><span class="nx">Println</span><span class="p">(</span><span class="s">&quot;2d: &quot;</span><span class="p">,</span> <span class="nx">twoD</span><span class="p">)</span>
+<span class="p">}</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ </table>
+
+ <table>
+
+ <tr>
+ <td class="docs">
+ <p>Note that arrays appear in the form <code>[v1 v2 v3 ...]</code>
+when printed with <code>fmt.Println</code>.</p>
+
+ </td>
+ <td class="code leading">
+ <div class="highlight"><pre><span class="gp">$</span> go run arrays.go
+<span class="go">emp: [0 0 0 0 0]</span>
+<span class="go">set: [0 0 0 0 100]</span>
+<span class="go">get: 100</span>
+<span class="go">len: 5</span>
+<span class="go">dcl: [1 2 3 4 5]</span>
+<span class="go">2d: [[0 1 2] [1 2 3]]</span>
+</pre></div>
+
+ </td>
+ </tr>
+
+ <tr>
+ <td class="docs">
+ <p>You&rsquo;ll see <em>slices</em> much more often than arrays in
+typical Go. We&rsquo;ll look at slices next.</p>
+
+ </td>
+ <td class="code empty">
+
+ </td>
+ </tr>
+
+ </table>
+
+
+ <p class="next">
+ Next example: <a href="slices">Slices</a>.
+ </p>
+
+ <p class="footer">
+ <a href="https://twitter.com/gobyexample">@gobyexample</a> | <a href="mailto:mmcgrana@gmail.com">feedback</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/arrays">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
+ </p>
+ </div>
+ </body>
+</html>
Oops, something went wrong.

0 comments on commit 72b2276

Please sign in to comment.