Skip to content

Instantly share code, notes, and snippets.

@Sylvain303
Sylvain303 / delegate_class.rb
Created August 9, 2015 14:47
ruby delegate DelegateClass removing global scope
require 'delegate'
def test_that?(n)
return n < 12
end
class MyID < DelegateClass(Integer)
def initialize(num)
@small = false
if test_that?(num)
@small = true
@Sylvain303
Sylvain303 / issues_helper.rb
Last active August 29, 2015 14:08
modified render_email_issue_attributes() redmine helper
def render_email_issue_attributes(issue, user, html=false)
exclude = %w{category fixed_version}
items = email_issue_attributes(issue, user)
# filter items outputed
items = items.select {|i| ! exclude.include?(i) }
output = []
# content_tag() will escape if it recieve string not block
items.each do |i|
if html
@Sylvain303
Sylvain303 / gist:49faa811bb33ba82b65e
Last active August 29, 2015 14:08
rails helper content_tag escaping html not same behavior
# from rails console
# foo is defined https://gist.github.com/Sylvain303/5899c453579871bfbfc4
# here redmine issue helper
foo = ActionView::Base.new
foo.extend IssuesHelper
foo.extend CustomFieldsHelper
@Sylvain303
Sylvain303 / gist:5899c453579871bfbfc4
Created October 31, 2014 09:41
load helper in rails console
# here redmine issue helper
foo = ActionView::Base.new
foo.extend IssuesHelper
foo.extend CustomFieldsHelper
issue = Issue.find_by_id(770)
user = User.find_by_id(748)
foo.render_email_issue_attributes(issue, user, true)
@Sylvain303
Sylvain303 / change name ActiveRecord
Last active August 29, 2015 14:08
change name ActiveRecord can be used in migration to rename required records, here for redmine
def change(type, old_name, new_name)
case type
when :role
klass = Role
field = :name
when :group
klass = Group
field = :lastname
else
raise "unsupported type:#{type}"
@Sylvain303
Sylvain303 / get_number_mailman_member.php
Last active August 29, 2015 14:01
mailman get number of subscribers from the web interface (without shell access)
<?php
include('liste_conf.php');
/*
$adminpw = 'secret';
$LIST_URL = 'https://mailman.server.url/cgi-bin/mailman/';
*/
if(count($_GET) > 1)
{
$list = $_GET['l'];