Skip to content
View guruce-api.md

“APIs, you're doing it wrong!”

What is an API?

From Wikipedia, we have “a set of Routines, protocols and tools for building software applications”.

Web API

REST

Re presentation S tate T ransfer is a software architecture style consisting of guidelines and best practices for creating scalable web services. REST is a coordinated set of constraints applied to the design of components in a distributed hypermedia system...

RESTful

View lazy_benchmark.rb
require 'benchmark/ips'
Benchmark.ips do |x|
x.report("with lazy") do
(1..1_000_000).lazy
.select(&:odd?)
.map(&:to_s)
.take(1000)
end
View configure-apache.txt
Please edit your Apache configuration file, and add these lines:
LoadModule passenger_module /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/passenger-4.0.57/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/ubuntu/.rvm/gems/ruby-2.1.1/gems/passenger-4.0.57
PassengerDefaultRuby /home/ubuntu/.rvm/gems/ruby-2.1.1/wrappers/ruby
</IfModule>
After you restart Apache, you are ready to deploy any number of web
applications on Apache, with a minimum amount of configuration!
View string.rb
require 'benchmark'
n = 1000000
Benchmark.bm(15) do |x|
x.report("assign single") { n.times do; c = 'a string'; end}
x.report("assign double") { n.times do; c = "a string"; end}
x.report("concat single") { n.times do; 'a string ' + 'b string'; end}
x.report("concat double") { n.times do; "a string " + "b string"; end}
end
View das.rb
module ClassMethods
def self.method2
end
end
module InstanceMethods
def method1
end
end
View speaker.md
View example.rb
#in real life this is going until column 98
@my_variable = MyVeryLongClassName.method("three", "arguments", "method") || default_value_method
# or
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
@my_variable ||= default_value_method
# or
@my_variable = MyVeryLongClassName.method("three", "arguments", "method")
View test.rb
module Bar
def self.method1
end
def method2
end
end
class Foo
include Bar
View tune_postgres.sh
#! /bin/bash
#with your postgresql setup up, with you postgres user too, let's do this o improve your postgresql performance
cd ~
wget http://pgfoundry.org/frs/download.php/2449/pgtune-0.9.3.tar.gz
tar -zxvf pgtune-0.9.3.tar.gz
cd pgtune-0.9.3
#first parameter is where your postgresql.conf is
./pgtune -i /etc/postgresql/9.0/main/postgresql.conf -o ~/postgresql.conf.pgtune --type Web
cp /etc/postgresql/9.0/main/postgresql.conf /etc/postgresql/9.0/main/postgresql.conf.bkp
View brakeman.sh
bash -l -c 'rbenv local 1.9.3-p125 &&
gem install brakeman --no-ri --no-rdoc &&
brakeman -o brakeman-output.tabs --no-progress --separate-models &&
rbenv local --unset'
Something went wrong with that request. Please try again.