20 topics in 20 minutes

57
20 Topics in 20 Minutes Eric Wastl @topaz2078 Software Architect Synacor BarCamp Buffalo 2013

Upload: kimn

Post on 23-Jan-2016

36 views

Category:

Documents


0 download

DESCRIPTION

20 Topics in 20 Minutes. Eric Wastl @topaz2078 Software Architect Synacor. BarCamp Buffalo 2013. (Synacor). (Buffalo). (Canada). Git. CSS3. Ruby. Perl. Hadoop. Bash. MySQL. VMWare. ActiveMQ. PHP. Kafka. Java. jQuery. JavaScript. Apache. Cassandra. Lua. HTML5. Linux. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: 20 Topics in 20 Minutes

20 Topics in 20 Minutes

Eric Wastl@topaz2078

Software ArchitectSynacor

BarCamp Buffalo 2013

Page 2: 20 Topics in 20 Minutes

(Synacor)

Page 3: 20 Topics in 20 Minutes

(Buffalo)

Page 4: 20 Topics in 20 Minutes

(Canada)

Page 5: 20 Topics in 20 Minutes

PHP

CSS3 Perl

JavaJavaScript

Linux

Apache

MySQL

Git

HTML5

Ruby

Lua

Bash

ActiveMQ

Kafka

Hadoop

Cassandra

VMWare

jQuery

Page 6: 20 Topics in 20 Minutes

Graphviz

digraph G { a -> b b -> c b -> d c -> e c -> f}

Page 7: 20 Topics in 20 Minutes

Graphvizdigraph G { concentrate = true; labeljust = r; subgraph cluster_internet { label = "internet" client_a; client_b; client_c } subgraph cluster_internal { label = "internal" node [shape=box] loadbalancer -> server01 loadbalancer -> server02 loadbalancer -> svr_spare [style=dashed] database [shape=box3d] server01 -> database server02 -> database svr_spare -> database [style=dashed] } client_a -> loadbalancer client_b -> loadbalancer client_c -> loadbalancer}

Page 8: 20 Topics in 20 Minutes

Graphviz

Page 9: 20 Topics in 20 Minutes

Graphviz

Page 10: 20 Topics in 20 Minutes

Graphviz

Page 11: 20 Topics in 20 Minutes

Perl: userland syntax sugar

sub forever { my $code = shift; while (1) { $code->(); }}

forever(sub { print "round and round...\n";});

Page 12: 20 Topics in 20 Minutes

Perl: userland syntax sugar

sub forever (&) { my $code = shift; while (1) { $code->(); }}

forever { print "round and round...\n";};

Page 13: 20 Topics in 20 Minutes

Perl: userland syntax sugar

sub if2 (&@) { while (@_) { my $cond = shift; my $code = shift; if ($cond->()) { $code->(); last; } }} sub then2 (&@) { @_ }

sub elsif2 (&@) { @_ }sub else2 (&) { sub{1}, $_[0] }

Page 14: 20 Topics in 20 Minutes

Perl: userland syntax sugar

my $x = 3;

if2 { $x == 1 } then2 { print "x was 1\n";} elsif2 { $x == 2 } then2 { print "x was 2\n";} else2 { print "x was something else\n";}

Page 15: 20 Topics in 20 Minutes

Polar coordinates

y

x

r

t

x = r * cos(t)y = r * sin(t)

t = atan2(y, x)r = sqrt(x*x + y*y)

Page 16: 20 Topics in 20 Minutes

Operators: Arity

To how many things does the operator apply?

! x <- 1: unarya + b <- 2: binaryc ? t : f <- 3: ternary

Page 17: 20 Topics in 20 Minutes

Operators: Precedence

Given different operators, which goes first?

1 + 2 * 3

1 + (2 * 3) <- * is higher(1 + 2) * 3 <- + is higher

Page 18: 20 Topics in 20 Minutes

Operators: Associativity

Given operators of the same precedence, in what order do they apply?

a – b – c

a – (b – c) <- right-associative

(a – b) – c <- left-associative

Page 19: 20 Topics in 20 Minutes

Operators: Fixity

To which operands does the operator apply?

! a <- prefix (unary)a ++ <- postifx (unary)a + b <- infix (binary)a b + <- postfix (binary!)+ a b <- prefix (binary!)

Page 20: 20 Topics in 20 Minutes

Array mapping in PHP/JS/Perl

$input = array(1, 2, 3, 4, 5);

function square($v) { return $v*$v; }$output = array_map("square", $input);

// $output is array(1, 4, 9, 16, 25)

Page 21: 20 Topics in 20 Minutes

Array mapping in PHP/JS/Perl

input = [1,2,3,4,5];

output = input.map(function(v){ return v*v; });

// output is [1, 4, 9, 16, 25]

Page 22: 20 Topics in 20 Minutes

Array mapping in PHP/JS/Perl

@input = (1, 2, 3, 4, 5);

@output = map { $_*$_ } @input;

# @output is (1, 4, 9, 16, 25)

Page 23: 20 Topics in 20 Minutes

Array mapping in PHP/JS/Perl

function square($v) { return $v*$v; }$output = array_map("square", $input);

output = input.map(function(v){ return v*v; });

@output = map { $_*$_ } @input;

Page 24: 20 Topics in 20 Minutes

PHP: Comparison Operators

$a < $b $a > $b

Page 25: 20 Topics in 20 Minutes

PHP: Comparison Operators

$a < $b $a > $b

Page 26: 20 Topics in 20 Minutes

PHP: Comparison Operators

Page 27: 20 Topics in 20 Minutes

$ cat circular.php<?php

$a = INF;$b = array();$c = (object)array();

var_dump($a < $b);var_dump($b < $c);var_dump($c < $a);

$ php circular.phpbool(true)bool(true)bool(true)

Page 28: 20 Topics in 20 Minutes

$array = array( INF, array(), (object)array(),);

sort($array);

is_sorted($array); //false

Page 29: 20 Topics in 20 Minutes

Git Basics

$ git init$ git clone git://...

$ git add stuff.c thing.php pants.pl$ git commit –am “new stuff”

$ git push$ git pull

Page 30: 20 Topics in 20 Minutes

CAP Theorem

A distributed system cannot simultaneously be consistent, available, and partition-tolerant.

consistent – only returns correct answeravailable – always returns an answerpartition-tolerant – works during network failure

Node 1

x = 0

Node 2

x = 0x = 1 x = 1 x = 1✓✓

✓✓✗

Page 31: 20 Topics in 20 Minutes

CAP Theorem

A distributed system cannot simultaneously be consistent, available, and partition-tolerant.

consistent – only returns correct answeravailable – always returns an answerpartition-tolerant – works during network failure

Node 1

x = 0

Node 2

x = 0x?x = 1

?

??✓

Page 32: 20 Topics in 20 Minutes

Perl Inline::* Modulesuse Inline Java => <<'END';class Java_Class { public Java_Class() {}

public int sum(int a, int b) { return a + b; }}END

my $java_class = new Java_Class();print "Java: ".$java_class->sum(19, 23) . "\n";

Page 33: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline Python => <<'END';def python_sum(a, b): return int(a + b)END

print "Python: " . python_sum(19, 23) . "\n";

Page 34: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline Lua => <<'END';function lua_sum(a, b) return a + bendEND

print "Lua: " . lua_sum(19, 23) . "\n";

Page 35: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline CPP => <<'END';class Cpp_Class { public: Cpp_Class() {} //nothing to construct ~Cpp_Class() {} //nothing to destruct int sum(int a, int b) { return a + b; }};END

my $cpp_class = new Cpp_Class();print "CPP: " . $cpp_class->sum(19, 23) . "\n";

Page 36: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline C => <<'END';int c_sum(int a, int b) { return a + b;}END

print "C: " . c_sum(19, 23) . "\n";

Page 37: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline Basic => <<'END';10 DEF FNBASICSUM(A,B) = A + BEND

print "BASIC: " . FNBASICSUM(19, 23) . "\n";

Page 38: 20 Topics in 20 Minutes

Perl Inline::* Modules

use Inline ASM => <<'END', AS => 'nasm', ASFLAGS => '-f elf', PROTO => {asm_sum => 'int(int,int)'};

GLOBAL asm_sum SECTION .textasm_sum: mov eax,[esp+4] sum eax,[esp+8] retEND

print "ASM: " . asm_sum(0, 23) . "\n";

Page 39: 20 Topics in 20 Minutes

Perl Inline::* Modulesprint "Sum: " . $java_class->sum( asm_sum( python_sum(4, 7), $cpp_class->sum(6, 3) ), c_sum( FNBASICSUM(5, 8), lua_sum(0, 9) ) ) . "\n";

Page 40: 20 Topics in 20 Minutes
Page 41: 20 Topics in 20 Minutes

Vanilla JS Speed Advantages

Page 42: 20 Topics in 20 Minutes

Vanilla JS Speed Advantages

Page 43: 20 Topics in 20 Minutes

Screen Basics

• Keep running console programs if you log out or get disconnected!

• Run several things at once from one connection!

• (A billion other reasons I don't have time to talk about!)

Page 44: 20 Topics in 20 Minutes

Screen Basics

Start a new session$ screen

List sessions$ screen –ls

Reconnect to a session$ screen -dr

Page 45: 20 Topics in 20 Minutes

Screen Basics

^A (ctrl-A) talks to screen

^A c New window^A ^A Switch to previous window^A 1 Switch to specific window^A " List windows^A A Rename window^A d Detach from screen^A a Send literal ^A

Page 46: 20 Topics in 20 Minutes

Fractals in your Terminal!

+- .-

-. -+-.+-. .---

++=... .-+-.- -==+.-- -..

.... .....+=--...+.--.....+++-. +&+

+=--+--.. +.-.+-..---+=+..+-+....-+---.

+++-++ .-..--+*. -. -=.-.---.*+ . .

. -- --+.-.-- +&..*-+=*#+.+

. .....+ .. .--+-- - +-.--++.

--*&=+.- .---.- +*-.-.-.=

----+.--.-.- . .+.+-

... . .....=-+*+- -.---..-. ---++=*+..

- . -. --.. .-- +-.. ...=. ==+---+=- .+

++. ......-....-=+.. .-. -. +.-.=..

- .--+=+*-... -.. .+==. =+-..= .-

..-+*=++-.=. .-.-+- .+-*-.- --..+..-+=*=.

..-.-+--.-..-+**-+- &=--.-..-.-++.=--- .+

.. . .. .-.--- . .-==- ++-=+-. .

. *... --.- -.- . .--

++ +.---... -

.+ -+....--&.+-

- .-.-- .-.

----.. -..- .

https://github.com/topaz/perl-mandelbrot

$ ./mandelbrot.pl -x -.7435669 -y .1314023 -w .003 -q --lines=24 --cols=80 -v -d 600

Page 47: 20 Topics in 20 Minutes

Perl Symbol Table Hackery

package Greeter;sub greet { print "Hello, $_[0]!\n";}

# elsewhere, deep in some call stackGreeter::greet("Fred");

Hello, Fred!

Page 48: 20 Topics in 20 Minutes

Perl Symbol Table Hackery

my $old_greet = \&Greeter::greet;*Greeter::greet = sub { print "$_[0]? Nope!\n"; return $old_greet->("pants");};

# same elsewhere as beforeFred? Nope!Hello, pants!

Page 49: 20 Topics in 20 Minutes

Perl Symbol Table Hackery

BEGIN { *CORE::GLOBAL::time = sub { return 42; };}

print "It is ".localtime(time)."\n";

It is Wed Dec 31 19:00:42 1969

Page 50: 20 Topics in 20 Minutes

Easy Bash Tips

• You can search your history for a command by typing ctrl-R and any substring.

• You can iterate over lists:$ for f in dir/*.log; do grep -i error $f | wc -l; done

• You can expand multiple similar words:$ cat {access,error}.log -> $ cat access.log

error.log$ mv pants{,.ext} -> $ mv pants pants.ext

Page 51: 20 Topics in 20 Minutes

PHP: Adding () can change meaning

function &r(&$v){return $v;}

$b = array("c");array_pop( ( r($b) ) ); print_r($b);array_pop( r($b) ); print_r($b);

Array( [0] => c )Array( )

Page 52: 20 Topics in 20 Minutes

Color-grapheme Synesthesia

A B C D E F G H IJ K L M N O P Q RS T U V W X Y Z 12 3 4 5 6 7 8 9 0! @ # $ % ^ & * <

Page 53: 20 Topics in 20 Minutes

Color-grapheme Synesthesia

A B C D E F G H IJ K L M N O P Q RS T U V W X Y Z 12 3 4 5 6 7 8 9 0! @ # $ % ^ & * <

Page 54: 20 Topics in 20 Minutes

Color-grapheme Synesthesia

Page 55: 20 Topics in 20 Minutes

Color-grapheme Synesthesia

function square($v) { return $v * $v; }$output = array_map("square", $input);

output = input.map(function(v){ return v*v; });

@output = map { $_*$_ } @input;

Page 56: 20 Topics in 20 Minutes

Color-grapheme Synesthesia

function square($v) { return $v * $v; }$output = array_map("square", $input);

output = input.map(function(v){ return v*v; });

@output = map { $_*$_ } @input;

Page 57: 20 Topics in 20 Minutes

Eric Wastl@topaz2078

[email protected]

phpsadness.comvanilla-js.com