Questions tagged [ruby]

Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.

125 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
12
votes
0answers
210 views

Ruby chess engine gem

This is my first Ruby gem that claims to provide all the rules of the chess game. My goal was to keep this library as simple as possible via OOP principles, and I'd be glad to hear any feedback from ...
7
votes
0answers
96 views

Stable variation of built-in sort

Ruby's built-in sorts are unstable. The stable_sort gem monkey-patches Ruby's built-in library to have stable sorts which include nearly all the functionality of the built-in sorts, but with the ...
6
votes
0answers
276 views

Solve alphametics puzzles in non-brute-force, iterative manner

The goal: Trying to optimize solution for the alphametics problem on exercism. From the question text: Alphametics is a puzzle where letters in words are replaced with numbers. For example ...
6
votes
0answers
5k views

spec_helper.rb for RSpec, Capybara, FactoryGirl, Spork and Devise

Having been through hundreds of often-conflicting posts on testing with RSpec, Capybara, FactoryGirl, Spork, Guard and Devise without Cucumber, this is the spec_helper which "seems to" work. I'm ...
5
votes
0answers
184 views

Error Handling for XML parser

I have the following Ruby code, which parses an XML document sax style (it's a very simplified version): ...
4
votes
1answer
227 views

Monitoring and re-establishing a PostgreSQL connection

Within a complicated Ruby project, I need to monitor the connection to a PostgreSQL database, as answered here. I use a thread for this purpose. Every few milliseconds, I invoke "consume_input" which ...
4
votes
0answers
63 views

Identifying the missing number in an array

This is from LeetCode: Missing Number Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. Example 1: Input: [3,0,1]...
4
votes
0answers
159 views

“Ymbirtt vs The Gilded Rose” Kata

The Gilded Rose Kata is a refactoring challenge, in which some frankly disgusting code is thrown at the developer, and they're told to make a small change to it. For reference, the (truncated) ...
4
votes
0answers
203 views

Web scraping with Nokogiri

At work we have a need to know what printers are getting dangerously low on their toner, and paper consumption, etc.. So I've created a program that pulls the printer information off the websites the ...
4
votes
0answers
34 views

Monkey patch data in dictionary

The chart data is stored in a nested dictionary struct @line_charts, and I need to convert the prices to target currency with the function ...
4
votes
0answers
78 views

Creating companion classes that are `inherited` onto any sub-classes

The idea for the code I have written came about due to the acts_as_versioned gem which automatically nests a Version class onto ...
4
votes
0answers
107 views

Heterogenous tree in the application domain: How do I represent them?

The Domain I have three types of items in my domain: ItemA, ItemB, ItemC. (I can't use their real names.) ItemA has one attribute: thing_id. ItemB has 6 attributes: thing_id, name, description, ...
3
votes
0answers
49 views

Assigning raffle numbers to users in Rails

Background One part of our Rails app is running a Raffle, usually twice a month, with around 600k entrants each round. Each raffle ticket record will have at least a unique raffle number (consisting ...
3
votes
0answers
31 views

Rails route structure for managing tags

I'm hoping someone could vet my route structure as I've really been struggling with getting something that feels right. Right now I have this nested resource structure: ...
3
votes
0answers
50 views

Atbash cipher in Ruby

I implemented my own spin on the Atbash cipher in Ruby: ...
3
votes
0answers
42 views

Ruby - Core skills example project (command line vehicle registry)

There are no requirements for this project nor will it ever be used for any purpose. I used this project to cement my knowledge of basic programming skills, I got bored copying the examples and felt ...
3
votes
0answers
121 views

Script to auto-generate Markdown tables of contents

I would greatly appreciate feedback on the enclosed script, which auto-generates a Markdown table of contents for Github-flavoured Markdown, with respect to: Consistency with Ruby idiom & style ...
3
votes
0answers
84 views

Implementing secure API for use between other internal apps

My team and I are trying to implement a secure API and would appreciate some feedback on the following: If there are areas of improvement in the current code to improve security Recommendations on ...
3
votes
0answers
103 views

Retrieving data from the movie database

I am trying to retrieve the series, seasons and episodes from the movie database, however I am pretty new to Ruby on rails and I feel like what I am doing could be improved a lot. I use an ...
3
votes
0answers
134 views

Codingame: Great Escape bot in Ruby - Follow-up

This is a follow-up to Codingame: Great Escape bot in Ruby. As mentioned there, my first reasonably sized Ruby project is a bot for CodinGame's Great Escape contest (here is a sample gameplay video). ...
3
votes
0answers
220 views

Ruby on Rails portfolio website

I've been learning Ruby on Rails for the last few weeks. I've decided to do a portfolio website using Ruby on Rails to showcase all of my projects. Can you look through my code to see what you think? ...
3
votes
0answers
67 views

Space efficient revision history storage with diffs

I've written a tool to store a files history more efficiently by only generating diffs and storing them whereas whole file would otherwise have to be stored. I would like to to hear about ways to ...
3
votes
0answers
539 views

Ruby script to to check the status of a rabbitmq queue and send alert

We are using a message broker called rabbitmq. The code checks the status of number of messages in q queue and sent messages. This is achieved by a curl request to a given API.The script has a sleep ...
3
votes
0answers
49 views

Achieving thread safety in a payment service library

I wrote this code a while ago, which is an excerpt of a payment service library: ...
3
votes
0answers
151 views

Reduce encoded length of UTF-8 encoded Ruby string in C extension

I'm writing a Ruby extension in C. It's a string processing module working on UTF-8 encoded strings only. One method, full_width_to_ascii!, converts full width ...
3
votes
0answers
114 views

Custom MySQL duplicate_key update queries

The goal is to create an activity or update its counter if it's already present. And to be super accurate, the code avoids race conditions with a custom ...
3
votes
0answers
64 views

Fat Controller Action - Deep nested filters

I have this really really long controller action and would like someone to help me break it down. ...
3
votes
0answers
260 views

Multiple many-to-many filter with range using filteriffic

I should say that the code I have works. I feel like there has to be a much more efficient way to do it (especially when I just crashed my server with it). Relevant schema: ...
3
votes
0answers
119 views

Using Nokogiri to scrape Oscars winners from Wikipedia

I am scraping a Wikipedia page, getting info from that page and instantiating a new object with the information collected: ...
3
votes
0answers
117 views

Extracting dynamic behaviors of state machines to modules

This is my initial class. (I am not trying to reinvent state-flows again, just practicing) As you can see straight forward, it dynamically generates methods like .recommend,.recommend!, ....
3
votes
0answers
550 views

Rails app that scrapes forum using Nokogiri gem

I've built a website that scrapes a guitar forum's pages and populates Rails model. I'm using rake task along with heroku scheduler to run background scrapes every hour. On the homepage, the forum ads ...
3
votes
0answers
121 views

Encapsulating behavior spread across multiple event handlers

I wrote a chatbot in Ruby for turntable.fm, a chatroom where users can listen to music together. It interacts with users in a room, who can type in specific keywords and get responses from it. It also ...
3
votes
0answers
1k views

Moving from Solr (Sunspot) to ElasticSearch (Tire), Review needed

I would like a review regarding the following code in which I index and search the City model. Currently both solr (with sunspot gem) and elaticsearch (with the tire gem) are show. I am migrating from ...
2
votes
0answers
26 views

Profitwell API wrapper build as Ruby gem

I've created my first gem in Profitwell API wrapper https://github.com/eebasadre20/profitwell. I love to get some feedback, comment, or suggestion on the code structure, method implementations, and so ...
2
votes
1answer
38 views

Rails 6: Attaching Devise current_user.id to form submissions

In my Ruby on Rails 6 app: I have a User class built with Devise, and I scaffolded a List class where each List should belong_to a User. I want Lists created through my app to be automatically ...
2
votes
0answers
39 views

Ruby coin toss probability tool

I haven't been programming for a while, I wanted to do a simple project to warm myself up and get back into the game; I made this simple tool that finds the probabilities of coin toss combinations. ...
2
votes
0answers
63 views

Ruby script for automating software install on a brand new Linux OS

I have some scripts to automate software install, apply some configurations and so on after installing a new system. I used to have them as bash scripts but it was generally a poor idea. I have ...
2
votes
0answers
54 views

Validating Amazon CloudFormation templates using Rspec

I have created an open source project that uses Rspec to validate the formatting of AWS::CloudFormation::Init YAML blocks in CloudFormation templates.1 My project is here. Some general concerns: Is ...
2
votes
0answers
101 views

Esoteric programming language in Ruby

I have recently created an esoteric programming language called 01 and I will be grateful for a code review and any opinions or suggestions about the future of this language. GitHub ...
2
votes
0answers
49 views

TDD for Ruby On Rails API for group event items

I found myself working in this coding exercise for a work offer. I tried to apply TDD in the process but I didn't get any feedback from the company and I really would like to know what can be improved ...
2
votes
0answers
283 views

Drawing an ASCII grid in Ruby based on a 2D array

I'm writing a function that renders a grid using ASCII line-drawing characters, based on a provided 2D array (or array of arrays), with each top-level array representing a row, and the items inside ...
2
votes
0answers
260 views

Ruby Hash to XML

I've just made this "serialization" module in Ruby that takes a hash and outputs a XML string. ...
2
votes
0answers
56 views

Counting how many questions in each category are tagged

I have a homepage that shows how many questions are in a certain category which is done through tagging. The functionality is working great, it tells me how many of each there are. However, newrelic'...
2
votes
0answers
154 views

LeetCode Minesweeper solution in Ruby

This is my solution to this LeetCode problem. Essentially you want to get the next board state for a Minesweeper game. All test cases passed and the submission was accepted on leetcode. The ...
2
votes
0answers
726 views

Rails CRUD feature specs (RSpec and Capybara)

The following feature spec tests CRUD operations for the users resource in a Rails 4.2.8 application. It includes tests for filtering, sorting and pagination ...
2
votes
0answers
40 views

Classes to help transform “How hard is it to …?” questions into replies like “It's really hard to …”

I've written a Twitter bot, @answering_yelp, which responds to another Twitter bot, @hard_to_yelp. They scrape yelp reviews for sentences which start "How hard is it to..." and my bot answer with some ...
2
votes
0answers
464 views

Module to dynamically generate controller concerns

I'm rebuilding a Rails project from when I started developing, and I wanted to figure out how to really DRY my controllers out—without making them unreadable by doing half/all of the work in a ...
2
votes
0answers
901 views

Convert a curl command into Ruby

I had a curl command which I converted using this. This is the Ruby script: ...
2
votes
0answers
56 views

SSH rate limiting using Puppet firewall module

I used to do simple SSH rate limiting using an UFW Puppet module. To get more flexible blocking I've changed to using the official firewall module instead. Are there any significant issues with the ...
2
votes
0answers
27 views

mapping event uuids to events in ruby

I have quite an interesting challenge for you today. The following code will produce a map with events as values and event uuids as keys. I've also listed out the spec for it. I would like to know ...