Skip to content

Instantly share code, notes, and snippets.

View mvrilo's full-sized avatar
🌳

Murilo Santana mvrilo

🌳
View GitHub Profile
@mvrilo
mvrilo / cep.rb
Created September 21, 2011 20:41
cep search scrapping
require 'rubygems'
require 'nokogiri'
require 'net/http'
require 'uri'
target = 'http://www.buscacep.correios.com.br/servicos/dnec/consultaEnderecoAction.do'
if ARGV[0].nil?
puts "USAGE:"
puts " ruby cep.rb xxxxxxxx"
@mvrilo
mvrilo / gist:1209845
Created September 11, 2011 17:21
nil or empty
require 'test/unit'
class Object
def blank?
if self.respond_to?(:empty?)
if self.class == String then self.strip.empty? else self.empty? end
else
self.nil?
end
end
@mvrilo
mvrilo / gist:1114504
Created July 29, 2011 19:09
infinite scroll
$(window).scroll(function(e) {
if ($(window).scrollTop() === $(document).height() - $(window).height()) {
// ajax!
}
});
require 'eio/eventmachine'
TMPFILE = File.expand_path(File.join(File.dirname(__FILE__), "test"))
EM.run do
EIO.eventmachine_handler
EIO.open(TMPFILE, EIO::RDWR) do |fd|
EIO.read(fd) do |buf|
data = "#{buf} ok"
EIO.write(fd, data) do |data|
@mvrilo
mvrilo / gist:725274
Created December 2, 2010 13:18 — forked from mrdoob/gist:718743
<!DOCTYPE html>
<html>
<head>
<title>html5 javascript canvas</title>
</head>
<body>
<script>
var canvas, context, mouse = { x: 0, y: 0 };
function onDocumentMouseDown(event) {
require 'rubygems'
require 'eventmachine'
class Example < EventMachine::Connection
def receive_data data
send_data "EventMachine minimal server\n\n-----\n#{data}-----\n#{request(data).inspect}"
puts request(data).inspect
close_connection_after_writing
end
mvrilo@ruf-home:~$ ssh -vvv node@mvrilo.no.de
OpenSSH_5.3p1 Debian-3ubuntu4, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to mvrilo.no.de [72.2.126.114] port 22.
debug1: Connection established.
debug1: identity file /home/mvrilo/.ssh/identity type -1
debug3: Not a RSA1 key file /home/mvrilo/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
# simple example with Sinatra
require 'rubygems'
require 'sinatra'
class Example
get '/' do
haml :index
end
end
var buffer = require('buffer').Buffer;
function base64(str) {
new buffer(str).toString('base64');
}
#!/usr/bin/env node
console.log("output string 'test' encrypted");
var crypto = require('crypto');
function md5(str) {
var hash = crypto.createHash('md5');
hash = hash.update(str);
hash = hash.digest('hex');