Add some color.
This commit is contained in:
parent
5a617e3cfd
commit
a75b36f5a3
|
@ -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)_:
|
This is my current _[_config.yml](https://github.com/badboy/fnordig.de/blob/master/_config.yml)_:
|
||||||
|
|
||||||
paginate: 5
|
~~~yaml
|
||||||
permalink: pretty
|
paginate: 5
|
||||||
exclude: Rakefile
|
permalink: pretty
|
||||||
markdown: kramdown
|
exclude: Rakefile
|
||||||
kramdown:
|
markdown: kramdown
|
||||||
use_coderay: true
|
kramdown:
|
||||||
|
use_coderay: true
|
||||||
|
|
||||||
coderay:
|
coderay:
|
||||||
coderay_line_numbers:
|
coderay_line_numbers:
|
||||||
coderay_tab_width: 2
|
coderay_tab_width: 2
|
||||||
coderay_css: class
|
coderay_css: class
|
||||||
{:lang="yaml"}
|
~~~
|
||||||
|
|
||||||
If you use `coderay_css: class` make sure to include a CSS file on your page (see my [coderay.css](/coderay.css)).
|
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:
|
And now some real highlighting to show it in action:
|
||||||
|
|
||||||
module CodeRay
|
~~~ruby
|
||||||
def about
|
module CodeRay
|
||||||
[self.name.downcase, 'rocks!'].join(" ")
|
def about
|
||||||
end
|
[self.name.downcase, 'rocks!'].join(" ")
|
||||||
module_function :about
|
end
|
||||||
end
|
module_function :about
|
||||||
{:lang="ruby"}
|
end
|
||||||
|
~~~
|
||||||
|
|
||||||
And that's it.
|
And that's it.
|
||||||
|
|
||||||
|
|
|
@ -14,24 +14,24 @@ It's called [proxymachine](https://github.com/mojombo/proxymachine), made by [@m
|
||||||
Get it with:
|
Get it with:
|
||||||
|
|
||||||
gem install proxymachine
|
gem install proxymachine
|
||||||
{:lang="text"}
|
|
||||||
|
|
||||||
and you're nearly done.
|
and you're nearly done.
|
||||||
|
|
||||||
Pipe the following into a text file:
|
Pipe the following into a text file:
|
||||||
|
|
||||||
proxy do |data|
|
~~~ruby
|
||||||
next if data.size < 9
|
proxy do |data|
|
||||||
v, c, port, o1, o2, o3, o4, user = data.unpack("CCnC4a*")
|
next if data.size < 9
|
||||||
return { :close => "\x0\x5b\x0\x0\x0\x0\x0\x0" } if v != 4 or c != 1
|
v, c, port, o1, o2, o3, o4, user = data.unpack("CCnC4a*")
|
||||||
next if ! idx = user.index("\x0")
|
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",
|
:remote => "#{[o1,o2,o3,o4]*'.'}:#{port}",
|
||||||
:data => data[idx+9..-1]
|
:reply => "\x0\x5a\x0\x0\x0\x0\x0\x0",
|
||||||
}
|
:data => data[idx+9..-1]
|
||||||
end
|
}
|
||||||
{:lang="ruby"}
|
end
|
||||||
|
~~~
|
||||||
|
|
||||||
and start it with
|
and start it with
|
||||||
|
|
||||||
|
|
|
@ -34,35 +34,36 @@ And now for some code examples:
|
||||||
|
|
||||||
#### Basic interface:
|
#### Basic interface:
|
||||||
|
|
||||||
bill = BadBill.new "billo", "18e40e14"
|
~~~ruby
|
||||||
# => #<BadBill:0x00000001319d30 ...>
|
bill = BadBill.new "billo", "18e40e14"
|
||||||
bill.get 'settings'
|
# => #<BadBill:0x00000001319d30 ...>
|
||||||
# => {"settings"=>
|
bill.get 'settings'
|
||||||
# {"invoice_intro"=>"",
|
# => {"settings"=>
|
||||||
# "invoice_note"=>"",
|
# {"invoice_intro"=>"",
|
||||||
# ...}}
|
# "invoice_note"=>"",
|
||||||
{:lang="ruby"}
|
# ...}}
|
||||||
|
~~~
|
||||||
|
|
||||||
#### Using defined resources classes:
|
#### Using defined resources classes:
|
||||||
|
|
||||||
BadBill.new "billo", "18e40e14"
|
~~~ruby
|
||||||
|
BadBill.new "billo", "18e40e14"
|
||||||
|
|
||||||
BadBill::Invoice.all
|
BadBill::Invoice.all
|
||||||
# => [#<BadBill::Invoice:0x000000024caf98 @id="1" @data={...}>], ...]
|
# => [#<BadBill::Invoice:0x000000024caf98 @id="1" @data={...}>], ...]
|
||||||
|
|
||||||
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"}
|
|
||||||
|
|
||||||
|
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
|
[repo]: https://github.com/badboy/badbill
|
||||||
[apidocu]: http://www.billomat.com/en/api/
|
[apidocu]: http://www.billomat.com/en/api/
|
||||||
|
|
|
@ -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:
|
But sometimes you need not only the symbol itself, but maybe the codepoint as well. That's easy in ruby:
|
||||||
|
|
||||||
irb> "❤".codepoints
|
~~~ruby
|
||||||
=> [10084]
|
irb> "❤".codepoints
|
||||||
|
=> [10084]
|
||||||
|
~~~
|
||||||
|
|
||||||
Got some codepoints and need to map it back to it's symbol? Easy:
|
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:
|
Oh, of course the usual `\uXYZ` syntax works aswell, but you need the hexstring for that:
|
||||||
|
|
||||||
irb> 10084.to_s 16
|
~~~ruby
|
||||||
=> "2764"
|
irb> 10084.to_s 16
|
||||||
irb> "\u{2764}"
|
=> "2764"
|
||||||
=> "❤"
|
irb> "\u{2764}"
|
||||||
|
=> "❤"
|
||||||
|
~~~
|
||||||
|
|
||||||
Sometimes you may need to see the actual bytes. This is easy in ruby aswell:
|
Sometimes you may need to see the actual bytes. This is easy in ruby aswell:
|
||||||
|
|
||||||
irb> "❤".bytes
|
~~~ruby
|
||||||
=> [226, 157, 164]
|
irb> "❤".bytes
|
||||||
|
=> [226, 157, 164]
|
||||||
|
~~~
|
||||||
|
|
||||||
There is documentation on these things:
|
There is documentation on these things:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue