18 out

Ruby – Backup automático (phpMyAdmin)

#!/usr/bin/ruby
#phpMyAdmin 2.11.4
 
require 'rubygems'
require 'mechanize'
 
agent = Mechanize.new
agent.user_agent_alias = 'Mac Safari'
page = agent.get('http://meuservidor/')
 
form = page.forms[1]
form['pma_username'] = "usuario"
form['pma_password'] = "senha"
 
agent.submit(form)
 
page2 = agent.get('http://meuservidor/server_export.php')
 
dump_form = page2.form('dump')
 
 
dump_form.checkboxes_with(:name => 'asfile')[0].check
dump_form.radiobuttons_with(:name => 'compression')[1].check
 
page3 = agent.submit(dump_form, dump_form.buttons.first)
 
d1=Date.today.to_s
filename= "#{d1}-meu_banco.sql.zip"
 
page3.save_as(filename)

Referências:

15 out

Ruby – WebCrawler / webbot / Spider

#!/usr/bin/env ruby
require 'net/http'
require 'net/https'
require 'nokogiri'
require 'open-uri'
require 'rubygems'
 
ano = ARGV[0]
de_dia = ARGV[1]
de_mes = ARGV[2]
ate_dia = ARGV[3]
ate_mes = ARGV[4]
nome = ((ARGV[5]).to_s).gsub(' ','+')
 
http = Net::HTTP.new('www.in.gov.br')
path = '/imprensa/pesquisa/pesquisa_resultado.jsp'
 
resp, data = http.get(path, nil)
cookie = resp.response['set-cookie']
 
data = 'texto_todas=%22'+nome+'%22&rbfonetica=0&idJornal=1&idJornal=2&idJornal=3&idJornal=5&dataPublicacaoInicial='+de_dia+'%2F'+de_mes+'&dataPublicacaoFinal='+ate_dia+'%2F'+ate_mes+'&ano='+ano
 
headers = {
  'Cookie' => cookie,
  'Referer' => 'http://www.in.gov.br/imprensa/pesquisa/pesquisa_resultado.jsp',
  'Content-Type' => 'application/x-www-form-urlencoded'
}
resp, data = http.post(path, data, headers)
doc = Nokogiri::HTML(data)
doc.xpath('//div/table[@id="ResultadoConsulta"]/tbody/tr/td/table[@bordercolor="#FFFFFF"]/tr/td[1]/span<pre lang="c">/div/a').each do |link|
puts ARGV[5]+","+ link['onclick'].gsub("redirecionaSelect('","").gsub("');","")
end

Use assim:

ruby DOU.rb 2011 15 10 15 10 "SEU NOME COMPLETO"

Referências:

15 out

OpenCV – Webcam Sobel

#include 
#include 
#include 
 
int main(int argc, char *argv[]) {
int delay = 0, key=0, i=0;
char *window_name;
CvCapture *video = NULL;
IplImage  *frame = NULL;
IplImage  *grey  = NULL;
IplImage  *edges = NULL;
 
/* check for video file passed by command line */
if (argc&gt;1) {
video = cvCaptureFromFile(argv[1]);
} else {
printf("Usage: %s VIDEO_FILE\n", argv[0]);
return 1;
}
 
/* check file was correctly opened */
if (!video) {
printf("Unable to open \"%s\"\n", argv[1]);
return 1;
}
 
/* create a video window with same name of the video file, auto sized */
window_name = argv[1];
cvNamedWindow(window_name, CV_WINDOW_AUTOSIZE);
 
/* Get the first frame and create a edges image with the same size */
frame = cvQueryFrame(video);
grey  = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
edges = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 1);
 
/* calculate the delay between each frame and display video's FPS */
printf("%2.2f FPS\n", cvGetCaptureProperty(video, CV_CAP_PROP_FPS));
delay = (int) (1000/cvGetCaptureProperty(video, CV_CAP_PROP_FPS));
 
while (frame) {
/* Edges on the input gray image (needs to be grayscale) using the Canny algorithm.
Uses two threshold and a aperture parameter for Sobel operator. */
cvCvtColor(frame, grey, CV_BGR2GRAY);
cvCanny( grey, edges, 1.0, 1.0, 3);
 
/* show loaded frame */
cvShowImage(window_name, edges);
 
/* load and check next frame*/
frame = cvQueryFrame(video);
if(!frame) {
printf("error loading frame.\n");
return 1;
}
 
/* wait delay and check for the quit key */
key = cvWaitKey(delay);
if(key=='q') break;
}
}

Compile desta forma:

gcc -I/usr/include/opencv  -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann   -o webcam_sobel webcam_sobel.c -lm

Referências:

  • http://silveiraneto.net/2009/12/04/opencv-edge-detection/
15 out

Fedora 15 – PlayStation Media Server

#!/bin/bash
yum install -y wget gunzip ld-linux.so.2 libfreetype.so.6 ffmpeg mplayer mencoder unrar
cd /usr/tmp
wget ftp://ftp.mdvrb-factory.de/mandriva/2010.1/i586/release/tsmuxer-1.10.6-1.i386.rpm
yum localinstall -y tsmuxer-1.10.6-1.i386.rpm
wget https://ps3mediaserver.googlecode.com/files/pms-generic-linux-unix-1.30.1.tgz
tar -vzxf pms-generic-linux-unix-1.30.1.tgz
wget http://www.ps3mediaserver.org/forum/download/file.php?id=1588&amp;sid=482fbf497f9e6da8f4e1f7b247ad621a &lt;&lt; EOF
mv file.php\?id\=1588 samsung_allshare_v.1.1.zip
unzip samsung_allshare_v.1.1.zip
mv samsung_allshare.conf /usr/tmp/pms-linux-1.30.1/renderers/
#Executando
sh /usr/tmp/pms-linux-1.30.1/PMS.sh

Referências:

  • http://ps3mediaserver.blogspot.com/