#rubykaraoke details
10pm Tonight (after the after party)
K BOX @ Chinatown
$38++ pax
211 New Bridge Road
#04-01
Lucky Chinatown
Singapore 059432
Slide 11
Slide 11 text
Red Dot Ruby Conference in Review
Slide 12
Slide 12 text
10 Years of Ruby SG
Slide 13
Slide 13 text
There are two hard things in computer
science: cache invalidation, naming
things, and off-by-one errors.
Slide 14
Slide 14 text
There are two hard things in computer
science: cache invalidation, naming
things, and off-by-one errors.
Slide 15
Slide 15 text
I'll just use this regular expression:
/[\s,]*(~@|[\[\]{}()'`~^@]|"(?:\\.|[^\\"])*"|;.*|[^\s\[\]{}('"`,;)]*)/
Slide 16
Slide 16 text
Ruby has many secrets.
#1: Predefined Variables
#2: ?, => ","
#3: [1,2,3]*? => "1,2,3"
#4: "Hello"[/[A-Z]/] => "H"
Slide 17
Slide 17 text
No content
Slide 18
Slide 18 text
The "fish" in our industry is the ability to
think abstractly and knowing what to do
when the abstraction eventually leaks.
Slide 19
Slide 19 text
Probably your API is fast enough
Slide 20
Slide 20 text
Google Lies.
People don't leave because of managers
Slide 21
Slide 21 text
Unlike documentation, running Ruby
(language) tests is easy. It's only 6 steps!
$ git clone https://github.com/ruby/ruby
$ cd ruby
$ autoconf
$ ./configure --disable-install-doc
$ make -j
$ make check
Slide 22
Slide 22 text
If there are no tests, there'd be no slow
tests
Slide 23
Slide 23 text
Future authorization systems should be
less dependent on the developer and
give more power to the users
Slide 24
Slide 24 text
A change positive architecture provides
maintainable,
sustainable,
and joyful development
Slide 25
Slide 25 text
Always Be Simulating
Slide 26
Slide 26 text
No content
Slide 27
Slide 27 text
Daru
Slide 28
Slide 28 text
Currencies are tricky.
Salaries
Slide 29
Slide 29 text
There are two hard things in computer
science: cache invalidation, naming
things, and off-by-one errors.
Slide 30
Slide 30 text
IoT makes a lot of sense
Slide 31
Slide 31 text
An existing system being used reflects
its real needs.
Slide 32
Slide 32 text
Three years on a cold stone will make
the stone warm
Slide 33
Slide 33 text
Don't believe in Stars
Slide 34
Slide 34 text
explainshell.com
Slide 35
Slide 35 text
Declarative Paradigms can make it
easier to reason about your app
Slide 36
Slide 36 text
In theory, theory and practice are the
same...
Slide 37
Slide 37 text
Regular Expressions: Now you have two
problems
Slide 38
Slide 38 text
My Ruby Story
Slide 39
Slide 39 text
No content
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
No content
Slide 42
Slide 42 text
Started Learning Ruby
in 2006
Slide 43
Slide 43 text
No content
Slide 44
Slide 44 text
After 10 years,
Why Ruby?
Slide 45
Slide 45 text
Community
Slide 46
Slide 46 text
Other Languages
Slide 47
Slide 47 text
Ruby isn't cool anymore
Slide 48
Slide 48 text
People Leaving Ruby
blog.jaredfriedman.com/2015/09/15/why-i-wouldnt-use-rails-for-a-new-
company/
Slide 49
Slide 49 text
Mature Ecosystem
Slide 50
Slide 50 text
"Bro, I wrote a script in Ruby Today.
It felt freeing."
-Yehuda Katz
Slide 51
Slide 51 text
Edges of Ruby
Slide 52
Slide 52 text
Fast is a feature
Slide 53
Slide 53 text
Ruby 3x3
Slide 54
Slide 54 text
Ruby 10% Year over Year
Slide 55
Slide 55 text
Thanks Ruby Core Team,
AppFolio,
Heroku
<3
Slide 56
Slide 56 text
"[Node.js] ran really efficiently in terms of its I/O
utilization, and its memory utilization is really low
[…]
You’re not really CPU-bound anymore. You’re
memory bound and I/O bound."
Kiran Prasad
senior director of mobile engineering LinkedIn
www.datacenterknowledge.com/archives/2013/12/04/paypal-groupon-go-node-js/
Slide 57
Slide 57 text
Node.js is great at building efficient web
services with lots of I/O
Slide 58
Slide 58 text
ratpack.io
Slide 59
Slide 59 text
Ratpack is a micro-framework for
building modern HTTP applications with
reactive principles in mind.
It is built on the highly performant and
efficient Netty event-driven networking
engine.
Slide 60
Slide 60 text
What's "reactive" actually mean?
Slide 61
Slide 61 text
applying backpressure from a client
non-blocking communication
Slide 62
Slide 62 text
non-blocking communication
Slide 63
Slide 63 text
By leveraging powerful concurrency
libraries from the JVM,
ratpack is built from the ground up to
support non-blocking IO.
Slide 64
Slide 64 text
ratpack hello world
RatpackServer.start do |b|
b.handlers do |chain|
chain.get do |ctx|
ctx.render("Hello World!")
end
end
end
Slide 65
Slide 65 text
ratpack streaming
RatpackServer.start do |b|
b.handlers do |chain|
chain.get("stream") do |ctx|
publisher = Streams.periodically(ctx, Duration.ofMillis(1000)) do |i|
i < 10 ? i.to_s : nil
end
ctx.render(ResponseChunks.stringChunks(publisher))
end
end
end
Slide 66
Slide 66 text
ratpack IO code
RatpackServer.start do |b|
b.handlers do |chain|
chain.get("io") do |ctx|
Blocking.get do
sleep 0.3
end.then do
ctx.render("Got response from fake db!")
end
end
end
end
Slide 67
Slide 67 text
Faban Benchmarks
Slide 68
Slide 68 text
Learn more:
hrku.co/jrubrat
Slide 69
Slide 69 text
CPU Bound
Slide 70
Slide 70 text
In 5 samples, ActiveSupport#blank? makes up 3.88% of total CPU time
github.com/rails/rails/pull/9958
Slide 71
Slide 71 text
ActiveSupport's String#blank?
class String
# A string is blank if it's empty or contains whitespaces only:
#
# ''.blank? # => true
# ' '.blank? # => true
# "\t\n\r".blank? # => true
# ' blah '.blank? # => false
#
# Unicode whitespace is supported:
#
# "\u00a0".blank? # => true
#
def blank?
/\A[[:space:]]*\z/ === self
end
end
Slide 72
Slide 72 text
CPU Bound -> Native Extensions
Slide 73
Slide 73 text
fast_blank
static VALUE
rb_str_blank(VALUE str)
{
rb_encoding *enc;
char *s, *e;
enc = STR_ENC_GET(str);
s = RSTRING_PTR(str);
if (!s || RSTRING_LEN(str) == 0) return Qtrue;
e = RSTRING_END(str);
while (s < e) {
int n;
unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
switch (cc) {
case 9:
case 0xa:
case 0xb:
case 0xc:
case 0xd:
case 0x20:
case 0x85:
case 0xa0:
case 0x1680:
case 0x2000:
case 0x2001:
case 0x2002:
case 0x2003:
case 0x2004:
case 0x2005:
case 0x2006:
case 0x2007:
case 0x2008:
case 0x2009:
case 0x200a:
case 0x2028:
case 0x2029:
case 0x202f:
case 0x205f:
case 0x3000:
/* found */
break;
default:
return Qfalse;
}
s += n;
}
return Qtrue;
}
Slide 74
Slide 74 text
Up to 20X faster
5% improvement on macro benchmarks
Slide 75
Slide 75 text
Becoming good at writing safe C is hard
Slide 76
Slide 76 text
issues even for seasoned maintainers
C Extensions are Hard
Slide 77
Slide 77 text
No content
Slide 78
Slide 78 text
Rust is a systems programming
language that runs blazingly fast,
prevents segfaults, and guarantees
thread safety.
Slide 79
Slide 79 text
If you have successfully compiled a Rust
program, it will not segfault at runtime.
mruby
mruby is the lightweight implementation of the
Ruby language complying with part of the ISO
standard. mruby can be linked and embedded
within your application.
MRI
# hello_world.rb
puts 'Hello World'
$ time ruby hello.rb
Hello World
real 0m0.041s
user 0m0.028s
sys 0m0.008s
Slide 109
Slide 109 text
MRI
# hello_world.rb
puts 'Hello World'
$ time ruby hello.rb
Hello World
real 0m0.041s
user 0m0.028s
sys 0m0.008s
# mrblib/hello.rb
def __main__(argv)
puts "Hello World"
end
$ time mruby/build/host/bin/hello
Hello World
real 0m0.003s
user 0m0.000s
sys 0m0.000s
mruby-cli
Slide 110
Slide 110 text
MRI
# hello_world.rb
puts 'Hello World'
$ time ruby hello.rb
Hello World
real 0m0.041s
user 0m0.028s
sys 0m0.008s
# mrblib/hello.rb
def __main__(argv)
puts "Hello World"
end
$ time mruby/build/host/bin/hello
Hello World
real 0m0.003s
user 0m0.000s
sys 0m0.000s
mruby-cli
Hello World Example
$ mruby-cli --setup hello
$ cd hello
Slide 119
Slide 119 text
Hello World Example
$ mruby-cli --setup hello
$ cd hello
$ docker-compose run compile
Slide 120
Slide 120 text
Hello World Example
$ mruby-cli --setup hello
$ cd hello
$ docker-compose run compile
$ docker-compose run shell
# mruby/build/host/bin/hello
Slide 121
Slide 121 text
Hello World Example
$ mruby-cli --setup hello
$ cd hello
$ docker-compose run compile
$ docker-compose run shell
# mruby/build/host/bin/hello
Hello World