Slide 1

Slide 1 text

It's Not Ruby, But… Miami Ruby Brigade March 19, 2018

Slide 2

Slide 2 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 3

Slide 3 text

Polyglot Culture vs. Contempt Culture

Slide 4

Slide 4 text

Polyglot Culture Programming languages are cool and it's good there are like a million of 'em

Slide 5

Slide 5 text

Polyglot Culture • Some are fun and are good to learn and crib concepts and ideas from • Some are really useful for a specific task • Some are pretty good at lots of things

Slide 6

Slide 6 text

Polyglot Culture • No one programming language is good at everything • When a language is the best at one thing it's frequently really bad outside that

Slide 7

Slide 7 text

Polyglot Culture So just learn lots

Slide 8

Slide 8 text

Contempt Culture • it's real bad • makes people feel bad about their valuable time spent learning "contemptible" languages

Slide 9

Slide 9 text

Contempt Culture • disproportionately targets languages used by people in more-marginalized groups

Slide 10

Slide 10 text

Polyglot Culture vs. Contempt Culture • i've done php, java, and javascript professionally • and i enjoyed and learned from them all

Slide 11

Slide 11 text

Polyglot Culture vs. Contempt Culture • it's okay to not like or avoid languages • but your reasons aren't everyone's reasons and your choices aren't everyone's choices

Slide 12

Slide 12 text

Value and honor peoples' decisions to use what they do

Slide 13

Slide 13 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 14

Slide 14 text

Skills Programming is hard

Slide 15

Slide 15 text

Skills • Getting a handle on a single programming language is a difficult proposition • Learning a second language is also hard • Being able to switch languages on the same project is even harder

Slide 16

Slide 16 text

Skills • so gj everyone that can switch from ruby to js without forgetting: • parens around arguments • return statements • how prototypes work

Slide 17

Slide 17 text

Skills • the more languages you learn, the easier it gets • especially if those languages are related somehow

Slide 18

Slide 18 text

Tools • lots of stuff in ruby is available for other languages • package managers • syntax highlighting for your editor

Slide 19

Slide 19 text

Tools • sometimes it's not great, depending on how fresh the language is • sometimes it's not great because the language just grew differently

Slide 20

Slide 20 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 21

Slide 21 text

Python • it's an interpreted object-oriented language from the '90s • Inspired Ruby!

Slide 22

Slide 22 text

Python • scientific computing • program analysis • "computer hacking"

Slide 23

Slide 23 text

Python • angr • binary ninja • pwntools

Slide 24

Slide 24 text

import angr 
 import simuvex 
 import binaryninja 
 
 bv = binaryninja.BinaryViewType['ELF'].open('magic') 
 bv.update_analysis_and_wait() 
 
 sum_string = "sum is %ld\n" 
 strings = bv.get_strings() 
 sum_ref = [r for r in strings if 
 sum_string == bv.read(r.start, r.length)][0] 
 code_ref = bv.get_code_refs(sum_ref.start)[0] 
 main_start = bv.get_previous_function_start_before(code_ref.address) 
 main_func = bv.get_function_at(main_start) 
 main_return = [o for o in main_func.low_level_il.basic_blocks[0] if 
 binaryninja.enums.LowLevelILOperation.LLIL_RET == o.operation][0] 
 
 
 proj = angr.Project('magic', 
 load_options={'auto_load_libs': False}) 
 add_options={simuvex.o.BYPASS_UNSUPPORTED_SYSCALL} 
 path_group = proj.factory.path_group(threads=1) 
 path_group.explore(find=main_return.address) 
 
 print path_group.found[0].state.posix.dumps(0) 
 print path_group.found[0].state.posix.dumps(1)

Slide 25

Slide 25 text

Why Python? • Libraries that aren't available in Ruby • Or aren't as good in Ruby • Documentation to do a thing that doesn't exist for Ruby

Slide 26

Slide 26 text

Big Changes in Python • mandatory good indent style • without parens you get the function as a value instead of calling it • you need to return to return a value

Slide 27

Slide 27 text

Big Changes in Python • global functions that call awkwardly-named methods instead of just methods • len(collection) or collection.__len__() • instead of collection.length()

Slide 28

Slide 28 text

Big Changes in Python • Python package management developed parallel but independent from Ruby's • octopus eyes work a lot like human eyes but they evolved 'em completely differently

Slide 29

Slide 29 text

Big Changes in Python • python 2 vs. python 3 • use python 3 when you can

Slide 30

Slide 30 text

Small Changes in Python • nil is None, true is True, false is False • it's already installed with a whole pile of libraries • a lot of Linux distros use it

Slide 31

Slide 31 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 32

Slide 32 text

Elixir • erlang-like language with ruby syntax • made by Rails users

Slide 33

Slide 33 text

Elixir • i already knew Ruby and Erlang so i picked up Elixir in a weekend

Slide 34

Slide 34 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 35

Slide 35 text

Rust • Mozilla made Rust because C++ doesn't do everything they need to • new by PL standards, first showed up in 2010

Slide 36

Slide 36 text

Rust • a lot of the tooling was built by Ruby users

Slide 37

Slide 37 text

Rust • you will hear people complain about the compiler being really picky • working as intended

Slide 38

Slide 38 text

In most browsers, it would be hard to get this right. Parallelism is a known hard problem, and the CSS engine is very complex. It’s also sitting between the two other most complex parts of the rendering engine — the DOM and layout. So it would be easy to introduce a bug, and parallelism can result in bugs that are very hard to track down, called data races. […] With Rust, you can statically verify that you don’t have data races. This means you avoid tricky-to-debug bugs by just not letting them into your code in the first place. The compiler won’t let you do it. https:/ /hacks.mozilla.org/2017/08/inside-a-super-fast-css-engine-quantum-css-aka-stylo/

Slide 39

Slide 39 text

Rust Projects I've Done • sinatra-like webapps that call shell scripts • programs that get hacked but only the right way

Slide 40

Slide 40 text

use std::net::UdpSocket; 
 
 fn main() { 
 let socket = UdpSocket::bind("0.0.0.0:1337"). 
 expect("failed to bind udp socket"); 
 
 socket. 
 set_read_timeout(None). 
 expect("couldn't set forever timeout"); 
 
 loop { 
 let mut buf: [u8; 32] = [0; 32]; 
 
 let (amt, src) = socket. 
 recv_from(&mut buf). 
 expect("failed to recv"); 
 
 assert!(amt == 32, "recvd {}, wanted 32", amt); 
 
 let expectation = [56, 55, 53, 53, 49, 99]; 
 
 if buf == expectation { 
 let reply ="nice!".as_bytes(); 
 
 socket. 
 send_to(reply, &src). 
 expect("failed to reply, rats"); 
 } 
 } 
 } 
 


Slide 41

Slide 41 text

Rust stuff worth looking at • Helix: use rust (instead of c) to write ruby modules

Slide 42

Slide 42 text

Twitter to Mastodon • Nintendo Switch posts screenshots and videos to twitter and facebook • I want those on my Mastodon account

Slide 43

Slide 43 text

Twitter to Mastodon • watch my tweets for #NintendoSwitch on the twitter streaming API • pick the best media version to post to mastodon • download the media • upload it to mastodon • post the toot

Slide 44

Slide 44 text

Twitter to Mastodon • honestly it'd be a ruby program • want to fit it in spare memory on an ec2 instance • and not think too hard about it

Slide 45

Slide 45 text

switch-tweet-copier • got to the media picker before i got tied up in types and compiler errors • JSON's type system vs. Rust's type system

Slide 46

Slide 46 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 47

Slide 47 text

Crystal • what if ruby but compiled to native bytecode

Slide 48

Slide 48 text

private def process_media(tweet) 
 blank = [] of ::Mastodon::Entities::Attachment 
 extended_entities = tweet.extended_entities 
 return blank if extended_entities.nil? 
 media = extended_entities.media 
 return blank if media.nil? 
 
 media.map do |medium| 
 pp medium.type 
 
 case medium.type 
 when "video" 
 process_video(medium) 
 when "photo" 
 process_photo(medium) 
 else 
 nil 
 end 
 end.compact 
 end 


Slide 49

Slide 49 text

Crystal • I finished the project :3 • Only had to update a bunch of libraries "shards" by hands

Slide 50

Slide 50 text

Changes in Crystal • "ruby" is "crystal" • "gems" are "shards" • "bundler" is built in

Slide 51

Slide 51 text

Changes in Crystal • type annotations • Not a huge community

Slide 52

Slide 52 text

It's Not Ruby, But… • Polyglot Culture • Skills & Tools
 • Python • Elixir • Rust • Crystal

Slide 53

Slide 53 text

Conclusions • learn more languages • don't hate • lots of good languages for different tasks