Skip to content

Instantly share code, notes, and snippets.

View josevalim's full-sized avatar

José Valim josevalim

View GitHub Profile
@josevalim
josevalim / client.js
Created January 4, 2011 08:29
Improve file uploads with Zombie
// Improvements to file uploads with Zombie.
//
// Just start the Sinatra server below and run this file with node.
// Depending on the server used with Sinatra, it will fail upfront or forward
// a bad request to the app. The source code in zombie is in the link below
// (you will need Zombie from git, you can check it out and use `npm link`):
//
// https://github.com/assaf/zombie/blob/master/src/zombie/history.coffee#L93
//
var zombie = require("zombie");
Tree = {function,1,foo,1,
[{clause,1,
[{var,1,self}],
[],
[{op,1,'+',{integer,1,1},{integer,1,2}}]}]}.
% Thanks to N_Ox on #erlang for pointing erl_syntax:abstract out.
{value, Tree, _ } = erl_eval:expr(erl_syntax:revert(erl_syntax:abstract(Tree), [])).
# Assuming you mounted it as attachment...
def update_attributes(attributes)
@previous_attachment = self.attachment
super
end
after_update do
if @previous_attachment && @previous_attachment.file != attachment.try(:file)
@previous_attachment.remove!
end
I am trying to run Mochiweb and I have decided to start with the https_store example:
https://github.com/mochi/mochiweb/blob/master/examples/https/https_store.erl
When I start it through the shell:
$ erl -pa ebin
1> https_store:start().
And then I use curl, everything works fine. Now, when I start it using -s, it simply does not work:
diff --git a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
index e40b328..c891178 100644
--- a/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
+++ b/activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb
@@ -19,10 +19,10 @@ module ActiveRecord::Associations::Builder
name = self.name
model.send(:include, Module.new {
class_eval <<-RUBY, __FILE__, __LINE__ + 1
- def destroy # def destroy
- super # super
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb
index 66a1f88..2bd5c48 100644
--- a/railties/lib/rails/application.rb
+++ b/railties/lib/rails/application.rb
@@ -141,35 +141,17 @@ module Rails
@assets ||= build_asset_environment
end
+ protected
+
@josevalim
josevalim / elixir.md
Created April 5, 2011 07:12
Object Model

In Elixir, you can only have methods in modules. An object is made of two groups of modules: mixins and protos. Mixins specify how the current object behaves, protos specify how the children of the current object will behave. This would be the canonical object definition in Elixir:

object Person
  module Mixin
    % What would be class methods in Ruby
  end

  module Proto
    % What would be instance methods in Ruby

end

# With explicit parens, explicit self and semi-colons
class UsersController < ApplicationController
self.before_filter(:authenticate_user!);
def index()
@users = User.all();
self.respond_to() do |format|
format.html();
format.xml() { self.render({:xml => @users}) };
Imagine the following route:
Rails.application.routes.draw do
match "/foo", :to => "posts#foo"
end
If we remove autoload, when the route try to load "PostsController",
it needs to be already there (and not autoload it). One options it to
load all controllers at the beginning of your route file:
class NamespacedGeneratorTestCase < Rails::Generators::TestCase
def setup
Rails::Generators.namespace = TestApp
end
end