RedSnake: 1st Annual Philly Ruby/Python Meetup Notes
RedSnake
PhillyPUG/Philly.rb Meetup
CrtterCase.com - Angel’s awesome iPad cases. Coming soon!
Thanks to Sunguard for hosting tonight!
The PhillyPUG group is doing a mentoring meeting next month where the group will be building the PhillyPUG website together. Come check it out!
This is the first (at least) annual RedSnake meeting! W00t!
RVM
Hector Castro
Ruby Version Manager.
RVM is a command line tool written in bash that allow you to have rubies and multiple versions of ruby.
Why have this? Well, There are a LOT of different versions of ruby. RVM lets you use any one encapsulated.
The best part of RVM is gemsets. Gemsets, allow you to manage sets of gems in isolation.
rvm gemset create redsnake
rvm gemset use redsnake
gem install bundler # or whatever
You can also use RVM to run tests across multiple rubies. E.g.: this will run the following ruby script across all the rubies you have:
rvm ruby test.rb
iPython
John from Susquahanna
iPython is an extended shell for interacting with python.
iPython will allow you to have a nice bash-like python interpreter from Windows.
Tab completion works as expected, like irb.
you can view the documentation and source code as follows
math? # see the doc string for math
math?? # see the source code for math
There are magic commands that start with % which allow you to extend the syntax beyond python for useful commands.
There is a history function, just like bash, as well as ctrl-r for reverse history searches.
There is a which command that finds executables in the PATH.
a = !dir # sorts the results of the MS DOS dir function
a.grep("\.py").fields() # you can grep and do other functions to the results!
To run pyhton code with a debugger you can use the run command.
This will run test.py and stop on line 4 so you can debug with ipdb, which is a lot like gdb:
run -i -d -b 4 test.py
SASS and Compass
Thibut Assus, Milesrock
Sass is a CSS version of Haml (I write my notes in haml!)
Why use sass? Why use compass?
- It is important to have semantic html using well designed CSS class names.
- You shouldn’t name you classes things like “red” or “right.” That makes your divs as bad as the old days of inline styles.
- The problem with semantic CSS, is that CSS is not the best language for organizing your stuff. You get really verbose, really fast.
sass gives you:
- functions
- variables
- data structures
Compass is a CSS framework that uses Sass.
Sass files look a lot lie Haml. Indentation matters.
Having variables allows you to change your code in one place, instead of global find and replaces for simple things like color changes (something you cannot do in straight CSS)
$main-color: lighten(#892328, 10%)
Functions allow you to make complex CSS classes
=my-fancy-box($color)
...
/* to call */
+my-fancy-box($main-color)
Compass is a way to package common sass libraries together and use them as a group in your projects.
Sass and compass is not a verbose language, it is just a way to make CSS a little bit better!
Check out SCSS, if you want to write sass in a more CSS-style way.
VIRTUALENV
Jonh
Virtualenv is a way to create sandboxed python installs.
It was created by Ian Bicking (a really smart python guy)
So, messing around with the system python can be bad mojo, so virtualenv helps with that.
easy_install virtualenv
virtualenv mynewpython
easyinstall is the default way of installing python packages.
virtualenv also comes with pip, which is another python package installer.
pip allows you to uninstall, where easyinstall does not.
pip freeze will give you a list of packages that you can use as a requirements file to duplicate your environment, just like bundler.
it is called freeze because it shows a frozen version of your environment as it is right now.
pip freeze
easyinstall makes eggs (zip files) for packages, but pip lays out packages in the file system, like ruby gems.
You can create pristine python environment, if you want as well, aka: you can exclude the system packages, if you want.
Ruby Metaprogramming
Trotter Cashion, Mashion, LLC
Three interesting methods in ruby:
- define_method: remove that duplication!
%w(email food user).each do |meth| define_method(meth) do @data[meth.to_sym] end end - method_missing: make up functions on the fly!
def method_missing(meth, *args, &block) if meth.to_s =~ /^find_by_(.+)$/ run_find_by_method($1, *args, &block) else super # VERY IMPORTANT!!! end endThis will call run_find_by_method when you type find_by_blah
- instance_eval: execute a block within the content of another block (the code for this is craziness, it allows you to access code from one class in another class)
Concurrency with Multiprocessing in Python
Gavin, myYearbook.com
green threads in threading: When you run threads they go through the same process.
To use threading in python, you just extend the Thread class and define a run function, then you are good to go!
Threading in Python has the GIL problem. The GIL processing is a problem where you waste time with the thread switching, when you could be using that processing power for running the code you want.
So Python has a NEW Multiprocessing module that works almost exactly like the Thread module, but fixes the GIL problem.
Multiprocessing lets you do everything the threads do, as well as queues, pipes, shared states, pooling, logging, exchanging, and more.
Thread code and Multiprocess code looks almost identical, but it is much more powerful.
multiprocessing.reduction
An underlining support library that allows you to pickle information and pass it from one process to another. (i.e. reduce and rebuild information for process passing).
Cucumber
Mat Schafer
Cucumber is a testing tool that lets you write tests in human-readable English!
Writing cucumber tests allows you to focus on the feature of something.
There is a feature statement, and three commands: Given, When and Then.
This allows you, as a developer, to concentrate on the problem, instead of the solution.
Cucumber can hook into more than just web stuff. Mat has it working with RedCar and SWT, as well (super cool!)
iCuke is an iPhone mapping to use cucumber with iPhone apps.
Lettuce is the Python equivalent.
Python in System Administration
Brian Jones, myYearbook.com
Python was was made by Guido van Rossum, he was an awesome sys admin.
Why Python? Because Perl sucks.
Python has a lot of cools stuff built in for sys admins:
- sys: system calls, stdin, stdout, stderr
- os: bash calls/DOS calls, OS-agnostic
- log: logging
- and much more!
the datetime module: VERY handy for sys admins (e.g. backups)
Cool stuff:
python -m SimpleHTTPServer # spin up an HTTP server
pydoc -p 9090 # spin up a doc server
Python is easy and fun! Use it!
Ruby FFI
Angel Pizarro
FFI is the Ruby C Extension API
Use SWIG to wrap a C API, but it is non-idiomatic Ruby ;_;
So FFI is a foreign function interface that you can use across rubies, where SWIG does NOT work across rubies.
FFI allows you to wrap your C API in Ruby, and it is pretty straightforward.
FFI allows you to define enums, typedefs, etc. so that you can make your ruby wrapping close to identical to your C API.
FFI will figure out endian-ness for you!
Structs can translate directly to Classes in Ruby
Beware of libraries that use STDIN and STDOUT, they will hose your Ruby.
Multidimensional arrays are not supported.
Really, Ruby FFI is just writing in C with just a better interface.
Interfacing C and Python
Tom Panzarella, @tpanzarella
Extending is creating new python modules in C.
Embedding is creating python modules that you can access in C.
Extending is cool. It allows you to hook into C libraries!
Use ctypes, it has ALWAYS been in python. Check it out!
You can also write a C-extension module using something like SWIG, or write an extension module yourself.
(Check out Cython!)
Tom’s example creates an XBOX 360 Kinect connector withpython. V. awesome.
PEP 20 (The Zen of Python)
Hunter Blanks
import this # read it. It is deep.
Beautiful code is better than ugly code.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren’t special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Now is better than never.
If the implementation is hard to explain, it’s a bad idea.
if the implementation is easy to explain, it may be a good idea.
Namespaces are a good idea. Use them.
Check out the presentation at http://www.artifex.org/~hblanks
I hope you find my notes helpful!
Thank you for everybody for presenting!

