Skip to content

Instantly share code, notes, and snippets.

View vpereira's full-sized avatar

Victor Pereira vpereira

View GitHub Profile
var LDAPConnection = require("LDAP").Connection;
var LDAP = new LDAPConnection();
if (LDAP.open("ldap://localhost", 3) < 0) {
throw new Error("Unable to connect to server");
}
LDAP.simpleBind("cn=bigshot,dc=test,dc=com","opensesame",function(msgid,err){
if(err)
console.log(err);
@vpereira
vpereira / simple.rb
Created June 20, 2011 16:59
simpleBind with ruby
require 'rubygems'
require 'ldap' #gem ruby-ldap
conn = LDAP::Conn.new('localhost', 389)
conn.set_option(LDAP::LDAP_OPT_PROTOCOL_VERSION,3)
r = conn.bind "cn=bigshot,dc=test,dc=com","opensesame"
puts r.inspect
@vpereira
vpereira / em_pipe_reader.rb
Created August 12, 2011 12:13
Eventmachine based named pipe reader
require 'fcntl'
require 'eventmachine'
#what is needed
#mkfifo mypipe
#that everything written thru the pipe have a "\n"
#ex: echo "foobar\n" > mypipe
#HPO = Handle Pipe Output
module HPO
@vpereira
vpereira / gist:2158259
Created March 22, 2012 13:07
map.include? x any.respond_to?
require 'ostruct'
require 'benchmark'
net_objs = []
class NetworkObject < OpenStruct
·
end
0.upto(1000) { |n| net_objs.push NetworkObject.new(:name=>"foo #{n}",:removed=>[true,false].sample) }·
@vpereira
vpereira / gist:2342609
Created April 9, 2012 09:52
elasticsearch
class Author < ActiveRecord::Base
has_many :books
end
class Book < ActiveRecord::Base
belongs_to :author
include Tire::Model::Search
include Tire::Model::Callbacks
mapping do
indexes :title,
@vpereira
vpereira / qos-opendpi.sh
Created August 5, 2012 21:18 — forked from thomasbhatia/qos-opendpi.sh
Basic QoS with iproute2 and OpenDPI Netfilter wrapper
#!/bin/bash
# Basic QoS script that uses OpenDPI (http://www.opendpi.org/)
# Netfilter wrapper to identify packets by the protocol.
#
# This script enqueues packets in three queues, each one
# with a different priority:
#
# The first queue has the higher priority and gets the TCP SYN
# packets, ACKs, ICMPs and packets with Minimize-Delay TOS.
class Foo
include Mongoid::Document
field :enabled, :type=>Boolean, :default=>false
scope :on, where(:enabled=>true)
scope :off, where(:enabled=>false)
end
irb> Foo.on.count
0
@vpereira
vpereira / gist:3814297
Created October 1, 2012 20:43
R open data with encoding
sp_censo2010 <- read.csv("~/R/sp_censo2010.csv", header=T, skip=2, dec=",",fileEncoding="ISO-8859-1", nrows=64)
library('stringer') # probably you will have to install it with install.packages('stringer')
mulheres = subset(sp_censo2010,str_detect(sp_censo2010$Unidade,"mulheres"))
homens = subset(sp_censo2010,str_detect(sp_censo2010$Unidade,"homens"))
class(homens$Valor)
[1] "factor"
as.numeric(as.character(homens$Valor))
[1] 53 51 47 61 19 31 42 36 45 50 44 39 30 24 22 15 12 7 64 59 35 11 56 6 16