Skip to content

Instantly share code, notes, and snippets.

advorak

Block or report user

Report or block advorak

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View openssl.rb
#!/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'
View gist:ec229c08750cc4ca660f
#!/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
View sample_script.rb
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
View udata.rb
# 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
View EVEN_BETTER_WAY.rb
@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
View cards_controller.rb
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 Aug 29, 2015
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?
View andy.rb
class Andy
def initialize
@andytest = []
end
attr_reader :andytest
end
__END__
View wordpress_connection_users.rb
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'
View demoappGemfile
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
View test.rb
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}
You can’t perform that action at this time.