Skip to content

Instantly share code, notes, and snippets.

View mvrilo's full-sized avatar
🌳

Murilo Santana mvrilo

🌳
View GitHub Profile
@mvrilo
mvrilo / gist:1114504
Created July 29, 2011 19:09
infinite scroll
$(window).scroll(function(e) {
if ($(window).scrollTop() === $(document).height() - $(window).height()) {
// ajax!
}
});
@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 / 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 / sleep.sh
Created October 19, 2011 11:49
put mac os x to sleep
#!/bin/bash
osascript << EOT
tell application "System Events"
sleep
end
EOT
@mvrilo
mvrilo / gist:1455340
Created December 10, 2011 14:53
defining a function
var ben = require('ben');
var fn = ben(100000, function() {
var test = function() { return "test"; };
test();
});
var newFunction = ben(100000, function() {
var test = new Function('', 'return "test"');
test();
var i = 6,
list = {};
console.log('base: 16px');
console.log('-----------------');
while (i < 50) {
var px = i + 'px',
em = String(i/16) + 'em';
list[px] = em;
>> Resolv::DNS.new.getresources("gmail.com", Resolv::DNS::Resource::IN::MX).map { |dns| dns.exchange.to_s }
=> ["alt3.gmail-smtp-in.l.google.com", "alt4.gmail-smtp-in.l.google.com", "gmail-smtp-in.l.google.com", "alt1.gmail-smtp-in.l.google.com", "alt2.gmail-smtp-in.l.google.com"]
# separating emails by the host
hash = {}
%w{ [email protected] [email protected] }.each do |mail|
id, host = mail.split("@")
hash[host] ||= []
hash[host] << id
end
@mvrilo
mvrilo / gist:3814857
Created October 1, 2012 22:29
getting ruby and gemset from .rvmrc
sed -e 's/^rvm \(.*\)/\1/' .rvmrc | grep '@'
@mvrilo
mvrilo / gitlab
Created October 23, 2012 17:36
gitlab init
#! /bin/bash
# GITLAB
# Maintainer: @randx
# App Version: 2.9
# from: https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server