Skip to content

Instantly share code, notes, and snippets.

test in http://validator.w3.org/check
==
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
crit = [:firstname, :lastname]
User.all.sort_by do |u|
crit.map{|c| u.send(c).downcase }
end
##I want the named_scope_first to return the first Article in the Database
class Article < ActiveRecord::Base
named_scope_first :test, :conditions => ["id > ?",0]
named_scope :test2, :conditions => ["id < ?",999953125641]
end
module ScopedObject
def named_scope_first(name, options = {}, &block)
name = name.to_sym
scopes[name] = lambda do |parent_scope, *args|
Scope.new(parent_scope, case options
when Hash
options
when Proc
options.call(*args)
end, &block).first
#!/usr/bin/env ruby
# Petit script permettant de regarder quel login s'est récemment connecté au
# serveur FTP et combien d'IP différentes ont été utilisé afin de détecter
# les personnes ayant fait un peu trop tourner leurs logins.
# Le format d'une ligne de log est le suivant :
# Sun Aug 24 10:08:52 2008 [pid 2949] [jblanche] OK LOGIN: Client "88.99.11.22"
require 'date'
require 'net/smtp'
#Small method in order to create an URL from a string
#Support accents (replace them by the same character without accent)
class String
def urlize(separator = '_')
url = ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(self,:d).split(//u).reject { |e| e.length > 1 }.join #replace accents
url.gsub(/[^[:alnum:]\-\s\_]/, '').split(/[\s\-\_]+/).delete_if{|i| i.empty?}.join(separator).downcase # urlize seriph GITHUB version
end
end