My result in Photoshoped quiz

I’ve got 70% in photoshop image recognition.

Photoshop Quiz
Created By TheirToys novelties

Leave a comment

Create nice looking blockquote with jquery and css

EDIT: you can now do the same with just css, here is a demo

If you want to create nice looking blockquotes on your web page here is simple plugin.

nice looking blockquote

First basic css

.quote {
    font-size: 2em;
    font-family: Times New Roman, times, serif;
    position: relative;
}
.quote p {
    margin: auto;
    text-align: justify;
}
.quote span {
    font-size: 4em;
}
.quote span.open {
    position:absolute;
    top:-0.35em;
    left:0;
}
.quote span.close {
    position:absolute;
    bottom: -0.8em;
    right: 0;
}

code for the plugin

$.fn.quote = function(params) {
    $(this).addClass('quote');
    var width = params && params.width ? params.width : 400;
    $(this).css('width', width);
    $(this).html('<p>' + $(this).html() + '</p>');
    $(this).find('p').css('width', width - 120);
    $(this).append('<span class="close">&rdquo;</span>');
    $(this).prepend('<span class="open">&ldquo;</span>');
};

create basic html

<blockquote>Lorem ipsum dolor sit amet, consectetur 
adipiscing elit. Nulla sed dolor nisl, in suscipit justo. 
Donec a enim et est porttitor semper at vitae augue.
</blockquote>

And run the plugin

$(document).ready(function() {
    $('blockquote').quote({'width': 500});
});

The default width is 400 px

lt

, ,

Leave a comment

Script for reconnect adsl in d-link router

In work I have wireless network with D-Link router “DSL-2640B”, and I need to reconnect ADSL service to change IP adress, so I write this ruby script, which use telnet standard libary.

#!/usr/bin/ruby
require 'net/telnet'
require 'optparse'

opts = ARGV.getopts('h:p:')

passwd = opts['-p']
host = opts['-h']

server = Net::Telnet::new('Host'=>host,
                          'Port'=> 23,
                          'Timeout'=>25,
                          'Prompt'=> />/)
server.waitfor(/ogin:/)
server.print("admin\n")
server.waitfor(/ssword:/)
server.print("#{passwd}\n")
server.cmd("adsl connection --down")
server.cmd("adsl connection --up")
server.cmd("logout")

You can use it in terminal by typing:

reconnect.rb -p <password> -h <host>

You must wait couple of seconds before your d-link router connect to ADSL.

, ,

Leave a comment

Script for searching files on rapidshare

This is a script in Ruby, that I wrote, which use filestube.com to search files on rapidshare (It don’t use filestube API — it just fetch and parse html).

#!/usr/bin/ruby

require 'net/http'
require 'uri'
require 'optparse'
require 'rexml/document'

def get(url, data=nil)
  url = URI.parse(url)
  http = Net::HTTP.new(url.host)
  if data
    data = data.map{|k,v| "#{k}=#{url_escape(v)}"}.reduce {|a,b|
        "#{a}&#{b}"
    }
    path = url.path + '?' + data
  else
    path = url.path
  end
  res = http.get(path, {'Cookie' => 'usr_timeoffset=0'})
  res.body
end

def url_escape(o)
  if o.class == ''.class
    o.gsub(/([^ a-zA-Z0-9_.-]+)/n) {
      '%' + $1.unpack('H2' * $1.size).join('%').upcase
    }.tr(' ', '+')
  else
    return o
  end 
end

def filestube_urls(query, page=nil, sort=nil, size=nil)
  url = "http://www.filestube.com/search.html"
  data = {
    'q' => query,
    'select' => 'All',
    'hosting' => 1
  }
  if size
    data['size'] = size
  end
  if sort
    data['sort'] = sort
  end
  regex = /<a href="([^"]*)" class="resultsLink">.*?<\/a>/
  if page
    data['page'] = page
  end
  get(url, data).scan(regex).map {|i| i[0]}
end

def extract_urls(page)
  if page =~ /<pre id="copy_paste_links"[^>]*>(.*)<\/pre>/m
     $1.strip.split("\n").each{|url|
       yield url
     }
  end
end

def rapidshare_urls(query, num=nil, sort=nil, size=nil)
  if num
    if num / 10 > 1
      result = []
      (2..num/10+1).each {|page|
         filestube_urls(query, page, sort, size).each {|url|
            extract_urls(get(url)) {|url|
              yield url
            }
         }
      }
    else
      filestube_urls(query, nil, sort, size)[0..num-1].each {|url|
        extract_urls(get(url)) {|url|
          yield url
        }
      }
    end
  else
    filestube_urls(query, nil, sort, size).each {|page|
      extract_urls(get(page)) {|url|
       yield url
      }
    }
  end
end


def usage()
  puts "usage:"
  puts "rapidsearch.rb [-n number] [-o order] [-s size] [-h]"
  puts 
  puts "-n number of url packages"
  puts "-h this help screen"
  puts "-s size:"
  puts "      1 - <20MB"
  puts "      2 - 20MB - 200MB"
  puts "      3 - 200MB - 1GB"
  puts "      4 - >1GB"
  puts "-o sort by (default relevance):"
  puts "      pd - popularity"
  puts "      dd - date"
  puts "      sd - size"
end

params = ARGV.getopts('n:o:s:h')
if params['h']
  usage
  exit
elsif params['o'] and !["pd", "dd", "sd"].include?(params['o'])
  puts "Bad parameter -o #{params['o']}"
  usage
  exit
elsif params['s'] and ![1,2,3,4].include?(params['s'].to_i)
  puts "Bad size #{params['s']}"
  usage
end

query = ARGV.join(' ')
begin
  if params['n']
    rapidshare_urls(query, params['n'].to_i, params['o'], params['s']) {|url|
      puts url
      $stdout.flush
    }
  else
    rapidshare_urls(query, nil, params['o'], params['s']) {|url|
      puts url
      $stdout.flush
    }
  end
rescue Interrupt, Errno::EINTR
  exit(0)
end

You can use this like this:

rapidsearch.rb -n 10 Matrix

this will display urls for 10 packages containgin word “Matrix”.

-o option is for size of packages (1 – 4)

-s option is for sorting it must be one of (dd – by data, pd – by popularity, sd – by size)

You can download this script from here.

You can combine this script with for validating rapidshare links.


rapidsearch.rb -n 5 -s 3 Matrix | rapidtest.rb -f -

, ,

2 Comments

Script in Ruby for validating rapidshare links

This is script which I wrote for testing if file exist on rapidshare hosting service, it use Rapidshare API

require 'net/http'
require 'uri'
require 'optparse'

class FalseException < Exception
end


def check(file, quiet=nil)
  file.each_line {|url|
    begin
      url = url.stript
      #skip blank lines, comments and invalid urls
      if url =~ /^\s*$/ or url =~ /^\s*#/ or
         not url =~ /^http:\/\// or 
         not url =~ /files\/([0-9]*)\/(.*)/
        next
      else
        fileid = $1
        filename = $2
        query = "?sub=download_v1&fileid=#{fileid}&filename=#{filename}"
        apiurl = URI.parse('http://api.rapidshare.com/cgi-bin/rsapi.cgi')
        page = Net::HTTP.new(apiurl.host).get(apiurl.path + query).body
        if page =~ /File deleted/ or 
           page =~ /This file is marked as illegal/ or
           page =~ /Filename invalid./ or
           page =~ /File not found/
          if quiet
            raise FalseException
          end
          if RUBY_PLATFORM =~ /(:?mswin|mingw)/i
            puts "#{url} [FAIL]"
          else
            #display red FAIL on n*ix system
            system("echo \"#{url} [\x1b[31m\x1b[1m\"FAIL\"\x1b[0m]\"")
          end
        else
          if quiet == nil
            if RUBY_PLATFORM =~ /(:?mswin|mingw)/i
              puts "#{url} [OK]"
            else
              #display green OK on *nix system
              system("echo \"#{url} [\x1b[32m\x1b[1m\"OK\"\x1b[0m]\"")
            end
          end
        end
      end
    rescue Timeout::Error, Errno::ETIMEDOUT
      puts "Timeout Error, try again"
      redo
    end
  }
end

def usage()
  puts "rapidtest.rb [-f (filename | - )] [-h]"
end

opts = ARGV.getopts('f:hq')

if opts['h']
  usage
  exit(0)
end

filename = opts['f']
if filename
  begin
    if filename == '-'
      check(ARGF)
    else
      File.open(filename) {|file|
        check(file, opts['q'])
      }
    end
  rescue Interrupt, Errno::EINTR
    exit(1)
  rescue FalseException
    exit(1)
  end
end
exit(0)

It will display url and [FAIL] or [OK] (on unix like system it display in color), or return true or false when used with -q option.

You can use it with -f option which must be filename with urls or – to read from stdin

If you using linux you can use xclip program to get data from clipboard.

If you have some urls in clipboard you can use:

xclip -o -sel clip | rapidtest.rb -f -

You can download it from here.

you can test if all files are valid with:

xclip -o -sel clip | rapidtest -f- && echo 'all fine' || echo 'some are invalid'

You can put this script in panel and display GUI message dialogs with zenity

function ok() {
  zenity --info --title "rapidtest" --text "all links are valid"
}
function error() {
  zenity --error --title "rapidtest" --text "some links are invalid"
}
xclip -o -sel clip | rapidtest.rb -q -f- && ok || eror

,

Leave a comment

I just got 666 reputation on stackoverflow.

666 reputation on stackoverflow

Leave a comment

Great T-Shirt Design.

This is the best T-Shirt design ever.

.ninja { color: black; visibility: hidden; }

, ,

1 Comment

%d bloggers like this: