1
2
3
4
require 'rubygems'
require 'spec' 

...

Ruby On Code to detect the web browser

by dcadenas.blogspot.com, August 29, 2008 02:10

@chrismo: check that your c...

Acad2552784135c09b17c00853f5a6f8 Talk
1
2
3
def test_web_browser()
  request.env["HTTP_USER_AGENT"].gsub(/\W/, '')
end

Ruby On Code to detect the web browser

by chrismo, August 29, 2008 01:46

Whoops - shorter regexp. I ...

8fb47582197b2d50cd7d297841c8cc87 Talk
1
2
3
4
def test_web_browser()
  return translate_user_agent(request.env["HTTP_USER_AGENT"])
end
...

Ruby On Code to detect the web browser

by chrismo, August 29, 2008 01:43

Here's a more thorough vers...

8fb47582197b2d50cd7d297841c8cc87 Talk
1
2
3
def test_web_browser()
  request.env["HTTP_USER_AGENT"].gsub(/[^A-Za-z0-9]/, '')
end

Ruby On Code to detect the web browser

by chrismo, August 29, 2008 01:42

I submitted this earlier, b...

8fb47582197b2d50cd7d297841c8cc87 Talk
1
2
3
HTMLElement.prototype.disablehandlers = function () {
...

JavaScript On Setting focus after alert

by Arvid Jakobsson, August 29, 2008 00:40

This might work, haven't te...

Db2af2c0fec84c164fd179790fdee227 Talk
1
2
3
def user_agent_name
  user_agents = {
...

Ruby On Code to detect the web browser

by nachokb.blogspot.com, August 28, 2008 22:25

Nicolás' first solution is ...

0f164d278a84fd814b8f7cb228dab565 Talk
1
2
3
4
if __name__ == "__main__":
    try:
        if options.input_file:
...

Python On Your average file filter...

by Malte, August 28, 2008 22:17

I agree with most changes h...

Avatar Talk
1
2
3
4
def test_web_browser
  ["Firefox/3", "Firefox/2", "MSIE 6", "MSIE 7", "Opera"].detect do |agent|
    request.user_agent =~ Regexp.new(agent)
...

Ruby On Code to detect the web browser

by foca, August 28, 2008 22:07

Er, sorry, I rushed to post...

E2eac01661fd490189a527b41c81a91c Talk
1
2
3
4
def test_web_browser
  %w(Firefox/3 Firefox/2 MSIE\ 6 MSIE\ 7 Opera).detect do |agent|
    request.user_agent =~ Regexp.new(agent)
...

Ruby On Code to detect the web browser

by Adam, August 28, 2008 22:02

@Nicolás - I don't think th...

A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
# Joe's solution doesn't work. It will always return either "Opera" or nil, you need to put "return" 
# at the beginning of each line. *This* is one of the cases where the return statement *is* required, 
# as you want to interrupt the flow of the code and return "early" instead of returning the return 
...

Ruby On Code to detect the web browser

by Nicolás Sanguinetti, August 28, 2008 21:57 Star_fullStar_fullStar_full

Never. *Ever*, detect the u...

E2eac01661fd490189a527b41c81a91c Talk
1
2
3
4
def test_web_browser()
  ua = request.env["HTTP_USER_AGENT"]
  "Firefox3" if ua[/Firefox\/3/]=="Firefox/3"
...

Ruby On Code to detect the web browser

by Joe Grossberg, August 28, 2008 19:05 Star_fullStar_fullStar_fullStar_fullStar_full

A few additional points:

*...

F288a8afe5302a16a366d5e9d34f2fec Talk
1
2
3
4
class Normalizer < Struct.new(:string)
  REPLACEMENTS = {
    0x92 => "&#39;",
...

Ruby On simplify multiple gsub

by Adam, August 28, 2008 18:50
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
def test_web_browser
  catch(:match) do
    ["Firefox/3", "Firefox/2", "MSIE 6", "MSIE 7", "Opera"].each do |ua|
...

Ruby On Code to detect the web browser

by Adam, August 28, 2008 18:32
A8d3f35baafdaea851914b17dae9e1fc Talk
1
2
3
4
@@lookup = {}

@@lookup[0x92] = "&#39;"
...

Ruby On simplify multiple gsub

by kenr, August 28, 2008 16:45

The normalizing is really w...

60997be4fbb4f5719d6eb68a1eadee9a Talk

JavaScript On Setting focus after alert

by danielks, August 28, 2008 13:08

I disable the events becaus...

Avatar Talk
1
2
3
4
if __name__ == '__main__':
    try:
        if options.input_file:
...

Python On Your average file filter...

by Dave Cridland, August 28, 2008 07:56

Well, the finally block isn...

A33619d2388462268ea2d2517762cb81 Talk

Ruby On simplify multiple gsub

by John Sietsma, August 28, 2008 01:45

It depends what you're afte...

37ce1520d319fa8095d05aa475951616 Talk

Ruby On simplify multiple gsub

by chrismo, August 27, 2008 21:21

Thanks, John - I knew I was...

8fb47582197b2d50cd7d297841c8cc87 Talk

Ruby On simplify multiple gsub

by kenr, August 27, 2008 16:01

Thanks Adam. I should have...

60997be4fbb4f5719d6eb68a1eadee9a Talk
1
2
"\xBD + \xBC".chars.normalize.to_s
=> "1/2 + 1/4"

Ruby On simplify multiple gsub

by Adam, August 27, 2008 13:42 Star_fullStar_fullStar_fullStar_fullStar_full

Perhaps I wasn't clear with...

A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On simplify multiple gsub

by kenr, August 27, 2008 11:16

Thanks Guys!

The multibyte...

60997be4fbb4f5719d6eb68a1eadee9a Talk
1
2
3
4
  result = ""
  data.each_byte { |ch|
    result << ( subs[ch.chr] || ch )
...

Ruby On simplify multiple gsub

by John Sietsma, August 27, 2008 05:29 Star_fullStar_fullStar_fullStar_fullStar_full

Use the speed of the dictio...

37ce1520d319fa8095d05aa475951616 Talk
1
data.chars.normalize!

Ruby On simplify multiple gsub

by Adam, August 27, 2008 04:07 Star_fullStar_fullStar_fullStar_fullStar_full

Why not use ActiveSupport::...

A8d3f35baafdaea851914b17dae9e1fc Talk

Ruby On simplify multiple gsub

by chrismo, August 27, 2008 03:41

Probably then just a versio...

8fb47582197b2d50cd7d297841c8cc87 Talk
1
2
3
4
def process_orig(data)
  data = data.gsub("\xA0", " ")
  data = data.gsub("\x99", "(TM)")
...

Ruby On simplify multiple gsub

by chrismo, August 27, 2008 03:40

I took a stab at 'optimizin...

8fb47582197b2d50cd7d297841c8cc87 Talk