Skip to content

Instantly share code, notes, and snippets.

@advorak
advorak / test.rb
Last active August 29, 2015 13:58
require 'active_support/all'
module Asdf
def self.new(connection_name, options)
classified_connection_name = connection_name.to_s.classify
self.class_eval <<-EOF
class #{classified_connection_name}
end
%w(aaa bbb ccc ddd).each do |letters|
class #{letters.classify} < #{classified_connection_name}
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
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'
@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__
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:
@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
# 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
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
#!/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
#!/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'