Skip to content

Instantly share code, notes, and snippets.

hash = Hash.new
data = @page.parser.css('tbody.white tr')
headers = data.shift.css('th')[2..-2].collect { |t| t.text.downcase.to_sym }
for row in data
values = row.css('td')[1..-2].collect {|t| t.text.strip.gsub(/(\u00A0|:)/, "").downcase }
key = values.shift.to_sym
hash[key] = Hash.new
#!/usr/bin/env ruby
# I am trying to replicate the successful connection granted by issuing the following command:
# openssl s_client -dtls1 -cipher DHE-DSS-AES256-SHA -connect 209.87.112.215:34135
# http://stackoverflow.com/questions/12836847/how-to-establish-a-ssl-enabled-tcp-ip-connection-in-ruby
require 'socket'
require 'openssl'
#!/usr/bin/env ruby
# http://stackoverflow.com/questions/12836847/how-to-establish-a-ssl-enabled-tcp-ip-connection-in-ruby
require 'socket'
require 'openssl'
socket = TCPSocket.open('crew-access-data.ual.com', 34135)
ssl_context = OpenSSL::SSL::SSLContext.new
ssl_socket = OpenSSL::SSL::SSLSocket.new(socket, ssl_context)
ssl_socket.sync_close = true
u = User.create
id = u.id
# The above should and does essentially do u.sessions.create()
# I expect after initializing this for it to test !session_valid? == false && !new_record? == false
u = User.find(id)
# I expect after initializing this for it to test !session_valid? == false && !new_record? == false
# I am executing a program 'umessage' and piping output to this
# ruby script ...
#
# The problem is that I'm noticing my program isn't receiving all
# of the output I expect it to receive from STDOUT to STDIN......
# It is consistently skipping data... any hints as to what I'm
# doing wrong?
DEBUG = true
@current_data = ''
while(data = @current_data.to_s + STDIN.read(100).to_s)
@current_data = ''
messages = data.lines.slice_before(/^\d{2}\/\d{2}/).collect(&:join)
messages.each do |message|
if message.join.match(/\n$/)
UnimaticMessage.create user_id: ENV['DB_USER_ID'], data: message
class CardsController
def create
render params.inspect
end
end
# Submitted, this yields:
# { "cards" => [ { "black" => ["Edit this new black card text..."] } ] }
# I want to yield this:
@advorak
advorak / andy.rb
Last active August 29, 2015 13:58
is it appropriate in a class, for a getter method of an instance variable which happens to be an array, to dup the variable so that such things as getter#push cannot be called on them?
class Andy
def initialize
@andytest = []
end
attr_reader :andytest
end
__END__
require 'active_support/all'
require 'active_record'
class WordpressConnection < ActiveRecord::Base
end
WordpressConnection.establish_connection adapter: 'mysql2', username: 'root', password: 'password', host: 'localhost', database: 'wordpress_wordpress'
class WordpressConnection::User < WordpressConnection
self.table_name = 'wp_users'
source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.4'
group :development do
gem 'sqlite3', '1.3.8'
end