Skip to content

Instantly share code, notes, and snippets.

View demental's full-sized avatar

Arnaud Sellenet demental

  • enerfip.eu
  • france
View GitHub Profile
<?php
/**
* Table Definition for admintype
*/
class InvalidMatrixException extends Exception
{
}
class EventCanvas::Base
class << self
attr_reader :matrix
def context *context_classes
@context_classes = context_classes
end
def subscribers *subscribers_classes
@context_classes.each do |kls|
class ReviewsController < ApplicationController
def edit
@review = Reviews::Submitter.new(params).model
end
def update
submitter = Reviews::Submitter.new(params)
@review = submitter.model
submitter.on(:success) { |review| redirect_to success_reviews_path }
# #+TITLE: Macros and Modules
# #+SETUPFILE: ../defaults.org
# Our client, the colonial fleet command, has asked us for a Ruby
# library to help them use the Observer pattern in tactical
# software. Here's how they'd like it to work: given a class =Dradis=
# which includes the module =Eventful=, they'd like to be able to
# declare an =#event= named =:new_contact=. They should then be able to
# instantiate an instance of the =Dradis= class and add listener objects
@demental
demental / pre-push
Last active December 30, 2015 18:49
Pre push hook to avoid focused: true pushed in repo
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
Dir.glob("spec/**/*_spec.rb") do |file|
results = `cat #{file} | grep -E "(\:focused => true)|(focused\: true)"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
if $? == 0
puts file
class HashMemoize
def memoized_value key
@memo_hash ||= Hash.new { |hsh, new_key| hsh[new_key] = some_heavy_computation new_key }
@memo_hash[key]
end
private
def some_heavy_computation key
puts "heavy duty for #{key} !"
key * 2
Feature: interfaces in Ruby
As a developer that wants to use interfaces in Ruby,
I want a DSL that emulates the following features:
* interfaces are constantized
* you cannot inherit from an interface
* you cannot instanciate an interface
* classes that implement interfaces MUST implement the methods defined in the interface
* instances of classes that implement interfaces are of the kind of the interface names.
Background:
1.8.7 :001 > string = "Bacon, lettuce and tomato"
=> "Bacon, lettuce and tomato"
1.8.7 :002 > string[1]
=> 97
********************************************************************
2.0.0p0 :001 > string = "Bacon, lettuce and tomato"
=> "Bacon, lettuce and tomato"
@demental
demental / fock.php
Last active December 18, 2015 16:39
<?php
class ActionListTest extends PHPUnit_Framework_TestCase
{
public function setup()
{
$this->subject = $this->getMock('MOfficeActionLister',array('allActions'));
$this->subject->expects($this->any())
->method('allActions')
= simple_form_for resource, as: resource_name, url: registration_path(resource_name), html: { class: 'form-horizontal'} do |f|
%fieldset
= f.input :email
= f.input :password, label: t('users.choose_password')
= f.input :password_confirmation
= f.input :terms_of_service, as: :boolean, wrapper: :fullwidth_checkbox
.form-actions
= f.button :submit, t("devise.shared.sign_up"), class: 'btn btn-primary btn-large'