This is a question from careercup.com. Given a word w and a number k.Find k words in the file occurring before occurrence of w.Assume that the average word size is m in the file
eg.
aaa
bbb
ccc
booking
alpha
beta
gamma
for k=3 and w = booking
the output should be [aaa,bbb,ccc,booking] ...
I am working on my programming style and want some advice.
Here is a sample program I have written to convert numbers to words:
ONES = [None, 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine']
# Empty string for zero will be replaced in main function
TEENS = ['ten...
@CarySwoveland look more closely. The grades are averaged before being passed to letter_grade(). I fully expect that this is just a toy example though, and ties won't matter so much. Think 100 students with 20 grades each, and taking the top 10%. With that said though, it would really be better to take the top students by average, then convert to letter grade for display purposes. However, that is more of a topic for Code Review than here. — Zack13 secs ago
I have to add some extra logic to a couple of similar stored procedures (~80) on my DWH server.
I thought that it would take pretty much the same time if I do it with Python and lots of googling (I have no python experience) or if I do it manully. So I decided to do it "the interesting way".
My...
The Function Block Diagram (FBD) is a graphical language for programmable logic controller design, that can describe the function between input variables and output variables. A function is described as a set of elementary blocks. Input and output variables are connected to blocks by connection lines.
Inputs and outputs of the blocks are wired together with connection lines, or links. Single lines may be used to connect two logical points of the diagram:
An input variable and an input of a block
An output of a block and an input of another block
An output of a block and an output variable
T...
WARNING: Please, do NOT give answer.
Hello, all. I'm in a coding boot-camp and I have been assigned some HW but the instructions seem really unclear. It's late here, and I can't contact my teacher. Below are the instructions.
"def array_delete(arr, delete_value)
# Your code goes here
# Directio...
My goal is to grab some data inside asp.net core app on server from external source via wcf service. In future i would like wcf responses to be cached on server and provide asp.net app clients "normal" errors if they appear.
Some things to notice: I'm using .net core 2.0 and generated wcf service...
This is technically off topic for SO (it's too broad, too opinion based). Perhaps you'd be better coding up a demo/prototype and trying the code review stack exchange site? — Joe59 secs ago
Thanks for the tip. I am not a regular user and did not know of that specific "review" forum. It is now posted there link — duanerf54 secs ago
I would like to improve my code and organization of JS files so I'm wondering if you guys could tell me what I could do better. I've included a small but typical example of how I typically use components. With this component I'm able to show different kind of notifications to the user, which then...
One of my professionel software i use everyday provides analysis results in *.csv format from which i need to extract data. I have written a script that first converts from text to columns, and then takes out the data i need rearranging it the way I want. My problem is that it is not very fast wh...
I am trying to solve knight-tour problem using Racket. It seems to be working but it is taking a long time and I have not been able to get even one solution using this code.
Essentially, the steps are:
Make list of lists to get NxN matrix Start from each square one by
one; Main fn: (pro...
I am trying to find object from an array of the object but its take much time. Could someone look my query and tell me how can i optimize and do it in the faster way.
book.chapters.select {|c| c.id == current_chapter_id } .first
Hint: tell the person giving such (sorry) insane instructions to get a grip on reality. Pushing all code into a single method is the absolute opposite of good practice. Of course, you want one method as entry point to the functionality, but that one method should happily use many other smaller helper methods. Rest assured: your code is not human comprehendable as it stands right now - and trying to force all of that into a single method is a good way to drive you crazy. In other words: if you would present the above in a code review, I would send you home ... — GhostCat17 secs ago
I'm using Visual Studio 2013, which doesn't have "magic statics" feature implemented yet, so local static variables initialization isn't yet thread-safe. So, instead of
Foo& GetInstance()
{
static Foo foo;
return foo;
}
I do something like this:
std::unique_ptr<Foo> gp_foo;
std::once_...
I've written a script using python to grab different categories from a webpage. I used "grequests" in my scraper to perform the activity. My intention here was to perform the action swiftly making asynchronous HTTP requests. My scraper is running flawlessly and collecting data as it should. Howev...
Hi I have a problem with a query on sql server in c #, this part of the queue prepares a query to print with microsoft report, my problem is that when it is hit (checkedListBoxCosaStampare.SelectedIndex == 1) I get the error listed below: How can I fix it ?
ERROR:
CODE:
//Stampa completa con...
I am writing a proxy class, that will fetch a certain property (say propertyA) by calling an underlying service.
Currently we use Service A to get propertyA, but there is a chance that in the near future, we might migrate to service B to get propertyA instead.
Approach 1:
I wanted to make Servi...
An example where you put multiple constraints on a single type variable is maybeSucc :: (Enum a, Eq a, Bounded a) => a -> Maybe a.
maybeSucc :: (Enum a, Eq a, Bounded a) => a -> Maybe a
maybeSucc x = if x == maxBound then Nothing else Just (succ x)
Note that GHC would infer that type automatically due to (==)'s, maxBound's and succ's types (succ :: Enum a => a -> a, maxBound :: Bounded a => a, (==) :: Eq a => a -> a -> Bool).
Something I haven't often seen in FizzBuzz implementation is a focus on making it flexible and maintainable. I have attempted to create a version that prioritizes these, such as by making it easier to change the conditions and add more conditions. What else could I do to work towards these criter...
I have a long text (about 6,000,000 chars) and a short text (about 6,000 chars). The long text contains the short text, but not exactly - a small number of words are missing, abbreviated or just erroneous. So I want to do an approximate search.
There are several Python libraries that do fuzzy s...
If StackCodeReview is only for code review, then no. I want to find a solution on how to write a custom converter for JSON to XML that respects / mimics the currently used one by Newtonsoft. — Jacks10 secs ago
You've got code that works, albeit not permorning to your needs, but that is where code review will help you and you can ask that question with less fear of reprise. SO is not a code writing service for you — Code Warrior47 secs ago
I have the following query:
SELECT
t.id as u_id,
IF(tn.state = 'P',tna.name,tn.name) as name,
t.version,
tn.state
FROM tag AS t
INNER JOIN tag_name AS tn ON tn.tag_parent = t.id
LEFT JOIN tag_name_audit AS tna ...
I have a List of Objects. Each Object has it's own, unique ID. Here's how I do it:
List<Alarm> AlarmList = new ArrayList();
public void createAlarm(String newName, int newHour, int newMinute, List<String> newDaysList){
String alarmId = "";
Alarm tempAlarm;
boolean loopBool = false; ...
you need to provide the code to know what is the problem. Then try to create a Minimal, Complete, and Verifiable Example, and post it at codereview.stackexchange.com — LethalProgrammer30 secs ago
"Your post appears to contain code that is not properly formatted as code".
There is no code in my post, only text and links.
Here is a link to my question - Limit Drive Starts with Function Block Diagram
The following is a copy-paste of the edit I am trying to apply.
I have a drive (mod...
Why would you assume that whatever is listening on port 29418 is using the same authentication as what is running on the default ssh port? Port 29418 is usually gerrit, and there are many guides out there to help you configure it properly. — larsks7 secs ago
I created ticket view which has holes and dashes in it then i draw border according to result shape. Two things are bothering me.
I created a bitmap and another canvas to draw the shape thinking it'd be faster.
I used the same code with different paint to just draw border around holes. Sounds ...
I want to compute the shortest distance between a position (x,y) and a rectangular box defined by (x_min, y_min) and (x_max, y_max). See picture below with some examples. I know that in two dimensions there are eight cases I have to take into account.
Since this part of my code is used very of...
Simple question. Lets say we have a lot of classes, which check internet connection and show dialog to the user if connection is not available, something like this:
if (!NetworkConnection.IsAvailable)
{
await DialogService.DisplayAlert(TranslationPopups.NoInternetConnectionLabel, TranslationP...
First time submitting code for review. Thanks for taking the time to look it over, any criticism is welcome.
Just a very basic Wav parser only handles the riff, fmt, and data chunks and has some basic error messaging. I'd like feedback mostly on the writeData method in WAVFile.h, the way I kind ...
I'm voting to close this question as off-topic because it is asking for a code review (and this thus too broad / opinion based). It could probably be adjusted to be on topic for the code review stackexchange. — Quentin34 secs ago
I took a shot at making a binary search tree to show off on my portfolio but I'm having some issues with the answer of my search appearing in the View. I think the issue is with the onclick="" function call or the placement of the .innerhtml line but I'm not sure. Any suggestions on how to clean ...
I am trying to create an Inter-Thread messaging queue to run a quadcopter control system on a SBC (Raspberry Pi model 3). The messaging queue should be as lightweight and robust as possible, eventually implementing some sort of failsafe method to restart in case of crash and avoid losing messages...
I have a database, with some history data for a lot of tags (ie. measurement points in the plant).
Users supply a calculation script, and get the result of the calculation as a result. The main function looks like:
Private Function _ExecuteCalculation(calcScript As String, BeginTime As Date, En...
Given a textbox in which I expect the user to type the name of a city.
<TextBox x:Name="InputCity" ... Text="{Binding City, Converter={StaticResource CityConverter}, Mode=TwoWay}" />
My ViewModel has a property City
private City _city = null;
public City City
{
get => _city;
...
This schema is just plain wrong on so many levels. Using TEXT for identifiers is an automatic fail in any sane code review. If these are numerical, use INT, if not, VARCHAR(6). — tadman5 secs ago
hmm ... I wonder why a permission error when trying to open a file in write-mode results in an UnsupportedOperationException instead of an IOException...
My code below is working fine but I know it can be done more efficiently using a loop. I struggle with loop logic for some reason so I could use some help.
I'm checking the VAL (such as description, ingredient2, etc.) which are Strings from my SQL lite Db to see if they are Null or Empty. If ...
I began working on a Javascript project, and the first fundamental building block is a data structure that mimics Java's java.util.HashMap, since Javascript {} works for only string keys, as far as I know. Without further ado, here is my code:
function HashMapNode(key, value) {
this.key = ...
I am currently doing some tutorials on OOP. For one of these, I need to create a class called Wheel that will perform the function of a Roulette Wheel. One of the functions of this class is to select bins at random, which, of course, mimics the toss of the ball into the roulette.
To test this cl...
As given in this question and the most up-voted answer, it's suggested that PLC-related questions may be on-topic. However, upon reading the tour, it points out this meta question, which indicates that only consumer-computer related systems are on-topic.
I have a question specifically regarding ...
I needed a method to test whether a given file is in use. Is the code below up to the task?
Public Function IsFileInUse(path As String) As Boolean
If IO.File.Exists(path) Then
Try
Using fs = IO.File.OpenWrite(path)
'If stream can write to the file, it sugg...
You might want to post this on Code Review Stack Exchange, there's a lot that could be done to make this code more DRY. Particularly using collections rather than individual properties for each of your views. It could cut your code down considerably and make it more readable, maintainable, and less error-prone. — ColGraff12 secs ago
@Mast Well I want to come up with a vertical linear drive, preferably using a servo or encoder motor, not sure what hardware might be best because it would need to support 2500-4000lbs (1200-2000kg) moving a vertical distance of ~25ft (a little more than 7.5m).
@MonZon: First, all you did was take your earlier comment and copy it into a new question. That is a bad way to ask questions, and you didn't provide any useful/new details, so it is not answerable in its current state. Second, you asked two separate questions, one about the crashing and one about the broadcast receiver. I said only the broadcast receiver portion should be a new question. And even then, it is actually off-topic for StackOverflow, since you are asking for a recommendation or code review. If the receiver you already have works, use it. If not, ask specific questions about it — Remy Lebeau52 secs ago
I am coding a program which involves the manipulation of athletes and events with Databases.
However, I have encountered a problem with my Combobox input, where whatever element the user selects, it always selects the first element.
Here is the block of code which has to do with the Combobox S...
You would be better off posting this on the code review website. That being said you can shorten your coat a lot if you used some arrays or some other sort of collection. That is normally the case when you end up with variables that have incrementing numbers appended to them. — csm_dev14 secs ago
I have written some Java code for a school assignment. It is a game, and it works as follows:
The game makes 4 random numbers, all different, as the users ticket.
It then generates 4 other random numbers, again all different, to compare it to. If they match, you win. If they don't match, then yo...
I have a quick script I came up with and I was wondering if this is a bad idea.
First let me explain what I want to do, I want to create a dynamic script which will add custom AJAX calls for whatever tab element I need it to. For instance if the user clicks on Profile, then I want to load profi...
I have spent hours on this code, and truthfully need some better expert opinion.
Column A on Sheet 1 has dynamic list of data, typically IP address, but for this it is simply a number. There can be duplicates or not.
I need to find all identical data in column A, select it, and run specific cod...
This is perhaps more of a code review answer than an explanation of why you're having this issue. But my feeling is a SparkSesssion should probably be created once, in one place, and passed around as a constructor or method argument to all of the other places it is used. This has the added benefit of decreasing tight coupling and making the code much more easily testable. But without knowning a lot more about how your code is structured and why you're using a SparkSession in so many places and from different threads, it's hard to say if this is the best path for sure. — Joe K55 secs ago
I'm the new product manager for the DAG team. I’m excited to announce that the top bar design that has been on Stack Overflow for several months is coming soon to the Stack Exchange network. Details are below, but the short version is the changes will roll out on meta.se first this week. Assuming...
So, I have a function which checks if a user is logged, but it's a long chain of if/else statements.
public static function isLoggedIn(){
Session::openSession();
if(isset($_SESSION['userId'])){
return true;
}
if(isset($_COOKIE['authToken'])){
list($selector, $to...
-1
down vote
favorite
I wrote a REST controller for message management https://pastebin.com/XuHgNLVW .I would like to ask you about your opinion on the names of addresses, the number of objects and the whole controller. Do you think that such a REST controller is OK or should it be improved?
@Ge...
I am new to C# and am trying to understand if there is a very simple way to rewrite this code.
List<Vertex<string>> vertices = new List<Vertex<string>>
(
new Vertex<string>[]
{
new Vertex<string>("Los Angeles"),
...
I have windows 10 Home- It does not contain "msg" with cmd.exe. Would this work?
SET /P victim=Uername to pwn:
SET mSg="error 404: user ID 1201234356713 not found!"
echo. 2>victims.txt
>"victims.txt" echo(%victim%
echo. 2>msg.txt
>"msg.txt" echo(%mSg%
:pwn
cmd /k msg @victims.txt <msg.txt
goto @...
I have an ansible playbook that checks out a GitLab private repository. It utilizes the GitLab Users API to generate an SSH key for the target host and adds it to my GitLab user's SSH keys.
This works, but I'm wondering how I can make it better. In particular, each ssh key is titled based on the...