From a75b36f5a3b78771fd79038447094439f97cc0c0 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Wed, 6 Nov 2013 12:46:19 +0100 Subject: [PATCH] Add some color. --- _posts/2011-09-02-kramdown-test.markdown | 38 +++++++------- ...0-02-fast-and-simple-proxy-server.markdown | 26 +++++----- ...9-21-badbilla-billomat-api-client.markdown | 49 ++++++++++--------- .../2013-11-06-unicode-codepoints-in-ruby.md | 28 +++++++---- 4 files changed, 76 insertions(+), 65 deletions(-) diff --git a/_posts/2011-09-02-kramdown-test.markdown b/_posts/2011-09-02-kramdown-test.markdown index 0a4627a..24834d8 100644 --- a/_posts/2011-09-02-kramdown-test.markdown +++ b/_posts/2011-09-02-kramdown-test.markdown @@ -9,18 +9,19 @@ With [jekyll][] as my static site generator it is easy to enable it. Just get th This is my current _[_config.yml](https://github.com/badboy/fnordig.de/blob/master/_config.yml)_: - paginate: 5 - permalink: pretty - exclude: Rakefile - markdown: kramdown - kramdown: - use_coderay: true +~~~yaml +paginate: 5 +permalink: pretty +exclude: Rakefile +markdown: kramdown +kramdown: + use_coderay: true - coderay: - coderay_line_numbers: - coderay_tab_width: 2 - coderay_css: class -{:lang="yaml"} + coderay: + coderay_line_numbers: + coderay_tab_width: 2 + coderay_css: class +~~~ If you use `coderay_css: class` make sure to include a CSS file on your page (see my [coderay.css](/coderay.css)). @@ -34,13 +35,14 @@ Adding syntax-highlighted code in your post now works like this: And now some real highlighting to show it in action: - module CodeRay - def about - [self.name.downcase, 'rocks!'].join(" ") - end - module_function :about - end -{:lang="ruby"} +~~~ruby +module CodeRay + def about + [self.name.downcase, 'rocks!'].join(" ") + end + module_function :about +end +~~~ And that's it. diff --git a/_posts/2011-10-02-fast-and-simple-proxy-server.markdown b/_posts/2011-10-02-fast-and-simple-proxy-server.markdown index 4c43c3c..101d292 100644 --- a/_posts/2011-10-02-fast-and-simple-proxy-server.markdown +++ b/_posts/2011-10-02-fast-and-simple-proxy-server.markdown @@ -14,24 +14,24 @@ It's called [proxymachine](https://github.com/mojombo/proxymachine), made by [@m Get it with: gem install proxymachine -{:lang="text"} and you're nearly done. Pipe the following into a text file: - proxy do |data| - next if data.size < 9 - v, c, port, o1, o2, o3, o4, user = data.unpack("CCnC4a*") - return { :close => "\x0\x5b\x0\x0\x0\x0\x0\x0" } if v != 4 or c != 1 - next if ! idx = user.index("\x0") - { - :remote => "#{[o1,o2,o3,o4]*'.'}:#{port}", - :reply => "\x0\x5a\x0\x0\x0\x0\x0\x0", - :data => data[idx+9..-1] - } - end -{:lang="ruby"} +~~~ruby +proxy do |data| + next if data.size < 9 + v, c, port, o1, o2, o3, o4, user = data.unpack("CCnC4a*") + return { :close => "\x0\x5b\x0\x0\x0\x0\x0\x0" } if v != 4 or c != 1 + next if ! idx = user.index("\x0") + { + :remote => "#{[o1,o2,o3,o4]*'.'}:#{port}", + :reply => "\x0\x5a\x0\x0\x0\x0\x0\x0", + :data => data[idx+9..-1] + } +end +~~~ and start it with diff --git a/_posts/2012-09-21-badbilla-billomat-api-client.markdown b/_posts/2012-09-21-badbilla-billomat-api-client.markdown index b4c63c8..7836e84 100644 --- a/_posts/2012-09-21-badbilla-billomat-api-client.markdown +++ b/_posts/2012-09-21-badbilla-billomat-api-client.markdown @@ -34,35 +34,36 @@ And now for some code examples: #### Basic interface: - bill = BadBill.new "billo", "18e40e14" - # => # - bill.get 'settings' - # => {"settings"=> - # {"invoice_intro"=>"", - # "invoice_note"=>"", - # ...}} -{:lang="ruby"} +~~~ruby +bill = BadBill.new "billo", "18e40e14" +# => # +bill.get 'settings' +# => {"settings"=> +# {"invoice_intro"=>"", +# "invoice_note"=>"", +# ...}} +~~~ #### Using defined resources classes: - BadBill.new "billo", "18e40e14" +~~~ruby +BadBill.new "billo", "18e40e14" - BadBill::Invoice.all - # => [#], ...] - - invoice = BadBill::Invoice.find(1) - invoice.pdf - # => {"id"=>"1", - # "created"=>"2012-09-17T13:58:42+02:00", - # "invoice_id"=>"322791", - # "filename"=>"Invoice 322791.pdf", - # "mimetype"=>"application/pdf", - # "filesize"=>"90811", - # "base64file"=>"JVBERi0xLjM..."} - invoice.delete - # => true -{:lang="ruby"} +BadBill::Invoice.all +# => [#], ...] +invoice = BadBill::Invoice.find(1) +invoice.pdf +# => {"id"=>"1", +# "created"=>"2012-09-17T13:58:42+02:00", +# "invoice_id"=>"322791", +# "filename"=>"Invoice 322791.pdf", +# "mimetype"=>"application/pdf", +# "filesize"=>"90811", +# "base64file"=>"JVBERi0xLjM..."} +invoice.delete +# => true +~~~ [repo]: https://github.com/badboy/badbill [apidocu]: http://www.billomat.com/en/api/ diff --git a/_posts/2013-11-06-unicode-codepoints-in-ruby.md b/_posts/2013-11-06-unicode-codepoints-in-ruby.md index 4219b52..022805b 100644 --- a/_posts/2013-11-06-unicode-codepoints-in-ruby.md +++ b/_posts/2013-11-06-unicode-codepoints-in-ruby.md @@ -10,25 +10,33 @@ I ❤ Unicode. Atleast most of the time. That's why I have things like ✓, ✗ But sometimes you need not only the symbol itself, but maybe the codepoint as well. That's easy in ruby: - irb> "❤".codepoints - => [10084] +~~~ruby +irb> "❤".codepoints +=> [10084] +~~~ Got some codepoints and need to map it back to it's symbol? Easy: - irb> [10084, 10003].pack("U*") - => "❤✓" +~~~ruby +irb> [10084, 10003].pack("U*") +=> "❤✓" +~~~ Oh, of course the usual `\uXYZ` syntax works aswell, but you need the hexstring for that: - irb> 10084.to_s 16 - => "2764" - irb> "\u{2764}" - => "❤" +~~~ruby +irb> 10084.to_s 16 +=> "2764" +irb> "\u{2764}" +=> "❤" +~~~ Sometimes you may need to see the actual bytes. This is easy in ruby aswell: - irb> "❤".bytes - => [226, 157, 164] +~~~ruby +irb> "❤".bytes +=> [226, 157, 164] +~~~ There is documentation on these things: