Skip to content

Instantly share code, notes, and snippets.

View rafaeljesus's full-sized avatar

Rafael Jesus rafaeljesus

  • Berlin, Germany
View GitHub Profile
@rafaeljesus
rafaeljesus / gist:5850123
Created June 24, 2013 13:40
Active Record Lifecycle
#The following is the order of the callbacks for a call to save (and save!) on a
#record that has never been saved before:
before_validation
before_validation :on => :create
after_validation
after_validation :on => :create
before_save
before_create
after_create
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<target name="building">
<echo>
---------------------------------------------------
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@rafaeljesus
rafaeljesus / gist:7931445
Last active December 31, 2015 03:59
Module Pattern JS
var UserPurchases = (function() {
function UserPurchases(Q, UserSession, PurchaseModals) {
this.Q = Q;
this.UserSession = UserSession;
this.PurchaseModals = PurchaseModals;
}
UserPurchases.prototype.purchase = function(video) {
this.video = video;
/**
* Autowire Quartz Jobs with Spring context dependencies
* @see http://stackoverflow.com/questions/6990767/inject-bean-reference-into-a-quartz-job-in-spring/15211030#15211030
*/
public final class AutowiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
private transient AutowireCapableBeanFactory beanFactory;
public void setApplicationContext(final ApplicationContext context) {
beanFactory = context.getAutowireCapableBeanFactory();
}
@rafaeljesus
rafaeljesus / enforce_dependencies
Created February 2, 2014 20:54
Check for dependencies constructor in backbone
function enforceDependencies(klass, options, deps){
deps = _.filter(deps, function(depName){
if( !options[depName] ){
throw new Error('Missing required dependency: '+ depName);
}
return !!klass[depName];
});
_.extend(klass, _.pick(options, deps));
}
@rafaeljesus
rafaeljesus / Gemfile
Created February 14, 2014 01:49 — forked from flomotlik/Gemfile
gem 'foreman'
gem 'puma'
@rafaeljesus
rafaeljesus / README.md
Created February 18, 2014 02:47 — forked from mloughran/README.md
OO Design with Event Machine

Getting started

First add your twitter username and password. Then server.rb and once it's started open websocket.html in your browser. You should see some tweets appear. If not take a look at the javascript console.

public class Calculadora {
private static final Prova _ = of(Prova.class);
public double mediaDeProvas(List<Prova> provas) {
return mediaPonderada(provas, function(_.getNota()), function(_.getPeso()));
}
public <T> double mediaPonderada(List<T> lista, Function<T, Double> valor, Function<T, Double> peso) {
double soma = 0.0;
double somaPesos = 0.0;
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')