Skip to content

Instantly share code, notes, and snippets.

#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
#!/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'
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
##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
crit = [:firstname, :lastname]
User.all.sort_by do |u|
crit.map{|c| u.send(c).downcase }
end
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>
# The main class
class League < ActiveRecord::Base
belongs_to :season
belongs_to :country
has_many :teams
has_many :games
def classify
teams.sort_by([:points, :goalaverage]).reverse
end
/* fontAvailable Prototype Plugin, v1.0
*
* Copyright (c) 2009, Jonathan Blanchet
* Licensed under the MIT License
* http://github.com/jblanche/prototype-fontavailable/tree/master
*
* Based on jQuery fontAvailable plugin:
* http://code.google.com/p/jquery-fontavailable/
* and Edward H. Trager and gCSSCapabilities plugin :
* http://eyegene.ophthy.med.umich.edu/fontface/javascript/gCSSCapabilities.js
475 ~ % irb
>> require 'rubygems'
=> false
>> require 'trim_api'
=> true
>> require 'tweetstream'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cgi.rb:279: warning: already initialized constant CR
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cgi.rb:282: warning: already initialized constant LF
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cgi.rb:285: warning: already initialized constant EOL
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/cgi.rb:287: warning: already initialized constant REVISION
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEApOciAKtFun1As+oX3gnNvNF9mLae3FaVHpZxz/ildzYhX9F4yUJWlyQowk5mFOg6LBCVHqfeOoS2AHGLSj3g4S4Ye5vmacxK1lcnsA+DXy9CuEgDs7MWK5DTmD3TsBmeqVNJxGBdHUquSE197Sw77DXW1M5YNMkcc2hcXIWyedaOWvkhjyXXo5j1A7S7NBWbPovfGgBZi3j0882GRjwfNFjTYqLmDrq9nMgwe2MbsMm7JvG+ncn6LzMECjspfeltCPBkXQ5+yooWXL78yE55f4IMzKF92tPqXIGXab6ozW5nwVC+Rv5F21tTHm3gX8twlF56hTf6E0mWB/ThMSI4mQ== jonathanblanchet@MacBook-de-Jonathan-Blanchet.local