background preloader

Mojombo's jekyll at master - GitHub

Mojombo's jekyll at master - GitHub

Criando sua própria RubyGem Todo mundo já deve ter usado pelo menos uma vez na vida as famosas gems. Elas ajudam muito na hora distribuir e usar bibliotecas Ruby, sem dúvida nenhuma. Mas o que nem todo mundo sabe é que criar uma gem é muito mais fácil do que parece. Neste artigo você verá como criar e distribuir sua própria gem. Entendo a gem Uma gem nada mais é que um arquivo .tar.gz. $ tar -ztvf bundler-0.9.26.gem -rw-r--r-- 0 wheel wheel 47579 Dec 31 1969 data.tar.gz -rw-r--r-- 0 wheel wheel 993 Dec 31 1969 metadata.gz Neste arquivo, você encontra o código Ruby propriamente dito (data.tar.gz) e os metadados (metadata.gz), que é a gem specification (ou apenas gemspec) em formato YAML. Uma gem é composta por uma estrutura mais ou menos definida de arquivos e diretórios, como você pode ver abaixo. O diretório lib é de longe o mais importante. O RubyGems substitui o método Kernel#require com sua própria implementação, que faz uma busca pela gem que você precisa utilizando os diretórios adicionados ao GEM_PATH. Ótimo!

o um único desenvolvedor Rails fez para escalar um site com 10 milhões de requisições por dia Publicado por Rafael Rosa em 11 de October de 2009 O Ravelry é uma comunidade on-line de tricô e crochê gerida pelo casal Casey e Jessica Forbes. Há algumas semanas, eles foram entrevistados por Tim Bray onde revelaram que seu site tem mais de 400.000 usuários registrados e consegue 3,6 milhões de pageviews por day - que geram 10 milhões de requisições por dia no Rails, já que recebem muitas chamadas de API, RSS e AJAX. Todd Hoff do HighScalability.com coletou todos os detalhes que conseguiu sobre o Ravelry e escreveu o artigo " Como a Ravelry Escalou para 10 Milhões de Requisições Usando Rails. " (em inglês), que é uma excelente análise sobre a estrutura do site, mas se você preferir a versão resumida, eles estão usando: Xen para virtualização HAProxy Nginx Tokyo Cabinet (para armazenamento de objetos grandes) Nagios New Relic Amazon S3 Amazon Cloudfront (for CDN) Sphinx Memcached

Roadmap for Learning Rails | techiferous Accelerating Your Learning If you have no prior development experience, one of the worst things you can do when learning Rails is to just dive in. Some of the concepts build on each other, so jumping in would be like signing up for a calculus class before you’ve learned algebra. Sure, you could muddle through it, but most of your time would be spent trying to figure out why things aren’t working. Another difficulty for a beginner is figuring out what to learn. Another mistake is spending too much time mastering a concept when you only need a basic understanding. Therefore, to accelerate your learning, learn the right things in the right order at the right depth. The following roadmap will help you do exactly that. But First Some Ground Rules… It takes a significant investment of time to learn Rails. Otherwise, you will waste your time learning Rails when all you really needed was WordPress. Roadmap for Learning Rails Ruby Ruby is the most important technology to know when learning Rails. Tools

[ADVANCED] MRI Memory Allocation, A Primer For Developers | Engine Yard Ruby on Rails Blog 1.8.61.8.7memprof Memory allocation in the MRI 1.8.x series of Ruby is seen by many developers to be a black box. A developer writes code and the interpreter just does some magic to make sure that the memory for the code is allocated, and more importantly, eventually garbage collected. You don't have to think about, it or even care about it all that much. And generally... that attitude is a productive one. It's very useful to have a general understanding of the mechanics involved, as they can sometimes steer you towards making better design choices in applications where your memory footprint matters; it's also very useful if things start going wrong with the memory footprint of the code. There are two types of memory allocations that occur in MRI 1.8.x. The second type of allocation is when Ruby allocates memory off of the C heap to provide storage for the actual data contained within an object. foo = 'x' * (1024 * 1024 * 10) You see that allocation as an immediate increase in RSS. Tagged:

meme » jésus lopes A API do Meme pode user acessada utilizando o YQL (Yahoo Query Language) que permite usar uma sintaxe similar ao SQL para recuperar os dados do Meme, um exemplo seria: SELECT * FROM meme.info WHERE name='jtadeulopes'; Diante disso, durante o Yahoo! Open Hack Day Brasil 2010 resolvi escrever uma gem para acessar a API do Meme utilizando Ruby. O desenvolvimento ainda esta no início, mas já é possível realizar as seguintes ações: Buscar um usuárioFollowers e FollowingBuscar postsBusca os posts mais populares do momento Instalando A instalação é bem simples, basta executar o comando sudo gem install meme Usando Localizando um usuário É possível localizar um usuário e suas informações desta maneira Buscando posts posts = Meme::Post.find('brhackday') post = posts.first post.content => "RT @codepo8: And I am off - plane leaves BR for London. Você pode especificar o tipo de mídia que deseja localizar, as opções são: photo, video, audio ou text. posts = Meme::Post.find('meme rocks', :type => :photo)

RISCfuture's dropbox at master - GitHub dcrec1's inploy at master - GitHub Ruby dynamic method calling - Khaled alHabache’s official blog (benchmark) I’m pretty sure that you have heard lots about ruby, specially as being a dynamic language, you can create methods on the fly, add instance variables, define constants and invoke existing methods dynamically , and that’s what this post is all about : As you know in ruby you can call a public instance method directly ,ex : s= "hi man" p s. length #=> 6 p s. include ? "hi" #=> true One way to invoke a method dynamically in ruby is to send a message to the object : p s. send ( :length ) #=> 6 p s. send ( : include ? A second way is instantiate a method object and then call it: method_object = s. method ( :length ) p method_object. call #=> 6 method_object = s. method ( : include ? And the third way is to use the eval method: eval "s.length" #=> 6 eval "s.include? Well, when to use what? look at this script, it will be used to benchmark the 3 ways of calling : Well as you can see, instantiating a method object is the fastest dynamic way in calling a method, also notice how slow using eval is.

Live Validations - Plugin rails para validação client-side Em meus últimos projetos utilizei o plugin live-validations que me facilitou trabalhar com as validações no lado do cliente. A lógica do plugin é passar a validação de seus models para js evitando assim posts desnecessários. Este funciona com jQuery ou Prototype No meu caso utilizei a jQuery e vou mostrar abaixo como é simples fazer isso. Pra começar vamos fazer o download do validate e colocar o arquivo jquery.validate.min no diretório public/javascripts e então basta instanciar a jQuery e o plugin. Agora vamos instalar o live-validations pra facilitar a nossa vida e fazer a validação automática. script/plugin install Então adicione a linha abaixo no seu environment.rb ou dentro de um intializer (que eu prefiro) LiveValidations.use :jquery_validations Agora basta adicionar o código :live_validations => true nos formulários que pretende usar validação. <% form_for(@user, :live_validations => true) %>

Related: