Skip to content

Instantly share code, notes, and snippets.

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'
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
class Person < ActiveRecord::Base
include Backburner::Performable
queue_priority 500
def self.make_person(name, options = {})
self.create name: name, guid: options[:guid]
end
def self.work
my_page_data = @pages.collect(&:to_s)
my_signed_on_data = my_page_data.group_by{|t| t.match /((?:[A-Z]|-| )+EXTRA BOARD|BLK|RUN)/;$1.strip unless $1.nil?}.reject{|k,v| k.nil?}
my_signed_on_data.inject({}) do |memo,obj|
obj[1] = obj[1].join "\n"
obj[1] = case obj[0]
when "BLK"
obj[1].scan(/^\s*((?:(?:C|M)_)?\d{4})\s+\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|(.*?)\|.*?\$(\d{4}\.\d{2})\s*\$(\d{4}\.\d{2})/).collect{|blks| Hash[[[:block_number, :saturday, :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :cap_id, :name, :bi_weekly_pay_school, :bi_weekly_pay_non_school],blks].transpose]}
when "RUN"
@advorak
advorak / toggle_led_bitmath.c
Created August 25, 2016 06:34
Uses bitmath to assess an 8 bit register of switches and notes any recently-depressed switches to toggle LED lights on a separate register of 8 bits...
/*
* toggle_led_bitmath.c
* Description: Uses bitmath to assess an 8 bit register of switches
* and notes any recently-depressed switches to toggle
* LED lights on a separate register of 8 bits...
*/
#define F_CPU 16000000UL //Define the speed the clock is running at. Used for the delay.h functions
#include <avr/io.h> //Include the headers that handles Input/Output function for AVR chips