Skip to content

Instantly share code, notes, and snippets.

View rodrei's full-sized avatar

Rodrigo Pavano rodrei

  • Mendoza, Argentina
View GitHub Profile
@rodrei
rodrei / subscriptions.rb
Created November 8, 2012 20:34
Subscriptions auditory
begin
free = []
non_free = []
subs_nil = []
User.all.each do |u|
if u.subscription.nil?
subs_nil << u
elsif u.subscription.plan.name == "free"
free << u
@rodrei
rodrei / github_export.rb
Created November 5, 2012 16:09
Github Issues export to Assembla CSV
require 'github_api'
components = %w{ tag1 tag2 tag3 tag4 }
users = {
'github-username' => 'new-system-username'
}
assembla_issues = []
client = Github.new login: 'user', password: 'password'
@rodrei
rodrei / gist:3706509
Created September 12, 2012 13:12
Migration
Call.where(:state.in => [:to_bill, :free]).all.each do |c|
c.billing_state = c.state
c.state = :scheduled
c.save!
end
Call.where(:billing_state => nil).each do |c|
c.update_attributes!(:billing_state => "unprocessed")
end
@rodrei
rodrei / rubyntlm_with_net_http.rb
Created June 14, 2012 20:11
Example: NTLM Authentication with NetHTTP
uri = URI('https://host.com/ews/exchange.asmx')
user = ''
passwd = ''
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new(uri.request_uri)
t1 = Net::NTLM::Message::Type1.new()
request['Authorization'] = 'NTLM ' + t1.encode64
response = http.request(request)
uri = URI('https://host.com/ews/exchange.asmx')
user = ''
passwd = ''
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new(uri.request_uri)
t1 = Net::NTLM::Message::Type1.new()
request['Authorization'] = 'NTLM ' + t1.encode64
response = http.request(request)
@rodrei
rodrei / exchange_usage.rb
Created May 24, 2012 20:56
Exchange basic usage
credentials = Autodiscover::Credentials.new('<e-mail address>', '<password>')
client = Autodiscover::Client.new
services = client.get_services(credentials)
ews_url = services.ews_url
Viewpoint::EWS::EWS.endpoint = ews_url
Viewpoint::EWS::EWS.set_auth 'username','password'
#believe this fetches the primary calendar. Still need to figure out how to get the list of all calendars.
calendar = Viewpoint::EWS::Folder.get_folder(:calendar)
@rodrei
rodrei / gist:2777467
Created May 23, 2012 20:10
Calls are being deleted
# e is a Google::Event with valid phone_numbers
irb(main):011:0> e.create_call_from_attrs
RESQUE SCHEDULED: Call 4fbd42c46eee0c0007000002 at 2012-05-31 17:53:00 UTC
=> #<Call _id: 4fbd42c46eee0c0007000002, _type: nil, created_at: 2012-05-23 20:04:20 UTC, updated_at: 2012-05-23 20:04:20 UTC, deleted_at: nil, google_event_id: BSON::ObjectId('4fbd35802697550007000003'), bridge_number: "6193262700", pin: "4031741", starts_at: 2012-05-31 17:53:00 UTC, ends_at: 2012-05-31 18:53:00 UTC, state: "scheduled", user_id: BSON::ObjectId('4f8f0e44f67a78000a00000a'), provider_id: BSON::ObjectId('4f8ce23a011b4d0007000002')>
irb(main):012:0> e.call
=> #<Call _id: 4fbd42c46eee0c0007000002, _type: nil, created_at: 2012-05-23 20:04:20 UTC, updated_at: 2012-05-23 20:04:20 UTC, deleted_at: nil, google_event_id: BSON::ObjectId('4fbd35802697550007000003'), bridge_number: "6193262700", pin: "4031741", starts_at: 2012-05-31 17:53:00 UTC, ends_at: 2012-05-31 18:53:00 UTC, state: "scheduled", user_id: BSON::ObjectId('4f8f0e44f67a78000a00
num = Math.abs(num)
// Java code
num = -1234
positive = num.abs
# => 1234
@rodrei
rodrei / FlatteableHash
Created July 12, 2011 17:56
Hash class with flatten method added
class FlatteableHash
def flatten(ancestor_names = [])
flat_hash = {}
each do |key, value|
names = Array.new(ancestor_names)
names << key
if value.is_a?(Hash)
value = FlatteableHash.new(value)
@rodrei
rodrei / .janus.rake
Created June 17, 2011 23:10
Personal .janus.rake file
vim_plugin_task "unimpaired", "git://github.com/tpope/vim-unimpaired.git"