Ruby is a multi-platform, open-source, dynamic, object-oriented, interpreted language created by Yukihiro Matsumoto (Matz) in 1993.
2
votes
0answers
25 views
Generating an attendance spreadsheet
I have written a Ruby script to generate an attendance spreadsheet. The below part of the code queries data and after few manipulation is saved in a nested hash. I had to implement switch case to ...
4
votes
2answers
178 views
Ruby Interrupted Bubble Sort
Working through CodeEval's Interrupted Bubble Sort, I have a working algorithm, but there's a speed issue. I'm trying to do this with Ruby and I keep getting an error that it's timing out after 10 ...
1
vote
1answer
31 views
One hash with params populate two objects
I have a JSON API where a user can update a post and related details to that post. To simplify the process the user just fills in one hash and we don't expose our architecture. What I did here works ...
8
votes
1answer
54 views
Novice implementation of Tic-Tac-Toe
After reading a lot of tutorials, I was finally able to code my version of a Tic-Tac-Toe game. I would like to have some honest review of the code to see what I can do to better my coding.
...
2
votes
1answer
42 views
6
votes
2answers
57 views
Letter-scoring Scrabble class
I wrote Ruby code (copied below) but was told that the code does not compile (it does on my computer) and that it does not answer the question:
Create a class called Scrabble that implements a ...
3
votes
1answer
51 views
Twisting words! (boustrophedon formatting)
I decided to implement properly the Code Golf challenge about twisting strings. I report the assignement verbatim for convenience:
Twisting Words!
Given a string and a positive integer. You ...
3
votes
2answers
38 views
One element only subarray max length
Task description
You are given a list and an item, find the length of the longest consecutive subsequence of the list containing only the item.
Testcases
...
7
votes
1answer
48 views
Summing the size/count of associations for multiple records
I'm working on a plain Ruby class within a Rails application.
For the total_leg_count method---is that the best way to go about achieving what I want? I feel like ...
2
votes
1answer
30 views
Skinny model, fat controller in Rails managing user IP addresses
As part of learning Rails framework, I have small app in progress. Basically idea is, user can create IP address, define is it in use, to which server is assigned, which user is it using and role of ...
5
votes
1answer
49 views
Caesar Cipher encryptor using ASCII
I have built a Caesar Cipher in Ruby that utilizes ASCII for the encryption. I am not sure whether or not this was the best way to go about the task but this way made the most sense to me. Please give ...
3
votes
3answers
48 views
Palindrome Validator
This code returns true if the sentence is a palindrome, and false otherwise. Is there a better way of doing this?
...
3
votes
0answers
15 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 ...
3
votes
1answer
35 views
Stock picker that tells when to buy and when to sell
The task of this project was to create a method that takes in an array of stock prices, one for each hypothetical day. From there, the method should return the best day to buy and the best day to sell ...
4
votes
1answer
48 views
Prefix Sum in Ruby, Genomic Range Query from Codility
I'm currently going through some lessons on Codility. I've just spent a couple of hours with GenomicRangeQuery, which is intended to demonstrate the use of prefix sums.
The task description is here. ...
4
votes
2answers
38 views
Custom delete method refactoring
I'm new to Ruby and don't know all the methods, so I was thinking there would probably be and easier way to do something like this. I'd love any input on how to refactor this.
...
5
votes
0answers
42 views
Converting ASCII to an image
So after I finished my fractal generator, I decided that text is ugly, at least compared to pictures. So I made a text-to-picture converter:
...
3
votes
2answers
62 views
Insertion sort in ruby
The code is correct, passes all testcases, I am looking for input on cleaning it, readability etc
...
10
votes
0answers
48 views
Generalized 2D cellular automata simulator
This is a simple Game of Life implementation, with one neat gimmick: You can specify the rules that the simulator uses to decide whether cells should live or die. Congrats, God!
I'd especially like ...
2
votes
5answers
98 views
Sudoku solver in Ruby
All the test cases pass except one of the test case which runs > 10 seconds. What can I do to make my solution faster?
...
4
votes
3answers
36 views
Max contiguous slice in Ruby
I need to compute the max contiguous slice in an array. I wrote this function, but I am not sure if it is correct or I am missing edge cases. I ran several cases.
...
1
vote
0answers
14 views
Collaborative filtering to group similar users and products
I'm doing product recommendation module based on collaborative_filtering.
The recommendation will be generated by users, ...
11
votes
0answers
77 views
Fractal generator
Refer to the help message and title of this post for what the code does.
I'm looking for tips on:
Efficiency: While the find-and-replace approach I have works perfectly fine and does so in a ...
0
votes
1answer
47 views
Find unconnected nodes of a graph
It is a set of edges of a graph given. An edge is given as an array of its endpoints, e.g. [:a, :b]. The array can contain an arbitrary amount of endpoints. ...
5
votes
2answers
83 views
LikesControler for a Post
I have this controller that I call via Ajax, where I update the likes of a post.
I have two methods in the user model:
already_like_post?: Where I pass the ...
3
votes
3answers
44 views
Searching purchase records, with or without a vendor criterion
I'm trying to figure out a better way to have one query here. I want to be able to send something to last where statement a wildcard so I can select all vendors. Right now if I don't include that line ...
4
votes
0answers
36 views
Sub-classing a class and recreating nested class on the subclass
I've written some code that creates a pair of classes. The second of the pair sub-classes the first, is nested within the first, and only has the addition of being an ...
2
votes
2answers
58 views
Locating existing records
In order to reduce redundancy in my app, I have added the method self.find_or_keep(object) to many of my models in order to find existing records with the same ...
4
votes
2answers
35 views
Multiple DB record creation after a successful operation
I am working on a payment process. Upon a successful payment process, I have to create multiple records. For that, I have made this class:
...
5
votes
0answers
36 views
Implementing a (small) full-text search in Ruby
I'm trying to implement a small full-text search in Ruby. I feel like I've laid down the foundation but I've encountered a blocker that has gotten me thinking that something with the design is ...
1
vote
2answers
56 views
Managing course enrollment
I have written some code to suspend someone's enrollment to a course. A course may have multiple presentations.
...
4
votes
2answers
113 views
Choosing a magic number between 0 and 9
I wrote a little script that asks the user to choose a number between the 0 and 9. Wile he/she is entering a choice, the program tells him/her if the number is too high and too low.
Nothing fancy, ...
3
votes
2answers
52 views
0
votes
1answer
36 views
Simplicity decider
I was interested in the Code Golf challange about simple text. The spec is:
Write a function that from a text returns the non-common words.
I assumed non clean input so I cleaned it before ...
6
votes
1answer
41 views
Sentence maker with thesaurus
I'm teaching myself Ruby by rewriting PHP solutions, such as this one. The program should match words in a sentence with a dictionary of synonyms and then make combinations with them.
...
3
votes
1answer
35 views
Small BM25+ implementation for probibalistic result ranking
I came up with this small implementation of an Okapi BM25+ ranker using Ruby. I cooked it up in a very short time so it's very simple but I'm trying to think whether there's a better way to write it. ...
4
votes
2answers
52 views
Longest lines of file descending
This is a challenge question from codeeval.com:
Write a program which reads a file and prints to stdout the specified
number of the longest lines that are sorted based on their length in
...
3
votes
3answers
69 views
Matrix class with lots of tiny methods
I have been following the advice to make tiny methods that does just one thing and does it well. I also have been keen on reducing or eliminating duplication as much as possible.
But when a very ...
5
votes
2answers
45 views
The Geppy String: Regex vs Iteration
We'll say that a lowercase 'g' in a string is "happy" if there is another 'g' immediately to its left or right. Return true if all the g's in the given string are happy.
...
4
votes
1answer
37 views
Ruby script that deletes servers from Red Hat Satellite
This script uses the Red Hat Satellite v5.4 API to delete servers which are read in from a file. The servers are listed in the file by hostname but the Satellite API deletes servers by ID number. The ...
1
vote
0answers
27 views
Monoalphatic and Polialphabetic cipher in Ruby
This code encrypts a text with mono-alphabetic and poli-alphabetic substitutions ciphers.
For further info see:
Mono-alphabetic/Caesar Cipher
Poli-alphabetic cipher
...
3
votes
1answer
39 views
Method that reserves a reservable entity and charges the user
This method works for what I need it to do, but I just don't think it's extremely readable, and could be abstracted into different methods. I have a feeling I'm going against some best practices. ...
10
votes
1answer
190 views
Robot toy simulator
I have already flunked the test with this code so don't feel bad for cheating any employer. I didn't get any feedback though just wondering what could have gone wrong.
You don't need to get into the ...
5
votes
1answer
64 views
Balancing words
A word is balanced at the index if the sum of the alphabet positions of all the chars multiplied by the distance to the index is zero.
This description is equivalent to the one given by ...
0
votes
0answers
35 views
Saving record payment data to respective tables
I have following action in the controller and am wondering how I can refactor it.
...
7
votes
5answers
780 views
Most common letter in string
Problem: Write a method that takes in a string. Your method should return the most common letter in the array, and a count of how many
times it appears.
Note: I solved it with Ruby, but the ...
4
votes
1answer
65 views
Markov chain-based word salad generator
I like Markov chains. Last time I used one, I made one that generates words. This time, I made one that generates sentences, given a set of words and valid connections. This time, it's not weighted ...
2
votes
2answers
66 views
Parsing JSON string from HTTP request
HTTP request is made, and a JSON string is returned, which needs to be parsed.
Example response:
...
4
votes
2answers
182 views
Calculating sum of smallest prime factors for 2 < n < 10**12
I am trying to calculate the sum of the smallest prime factors of n, where 2 < n < 10**12, and get the remainder of this ...
3
votes
1answer
42 views
Arrow test Ruby gem
I wrote my first Ruby gem, which is for testing code in the shortest way possible.
Here's a usage example:
require 'arrow_test'
1 + 1 # -> 3
arrow_test
The ...