The following code transforms multi-line input into the the Brainfuck equivalent. One line turns into one program. The resulting programs are split by newlines for readability.
Brainf.cpp
#include "Brainf.hpp"
int main()
{
std::vector<std::string> userInput;
std::string currentLine = "...
I was just hoping someone would be able to help me to understand how to increase efficiency of a function I believe can be done better.
Before I continue, the program this function is in downloads videos from the internet one after the other. This particular function is run in a separate thread ...
Open Computing Language (OpenCL) is a framework for writing programs that execute across heterogeneous platforms consisting of central processing units (CPUs), graphics processing units (GPUs), digital signal processors (DSPs), field-programmable gate arrays (FPGAs) and other processors. OpenCL specifies a language (based on C99) for programming these devices and application programming interfaces (APIs) to control the platform and execute programs on the compute devices. OpenCL provides parallel computing using task-based and data-based parallelism. OpenCL is an open standard maintained by the...
I have a php contact form and it isn't working. I cannot figure out the reason why. I am sure its something obvious but cannot spot the error. Here is the code on the html contact page
<form method="post" action="/mail.php">
<label for="firstname">First Name:*</label>
<input type="text" name="fi...
Ok, so I have alot of free time now since im on summer holidays, and I have made this little program which allows you to play a slot machine. This took a bit of time to develop, I hope you like it.
Code:
import random
import time
import os
print()
print('''Welcome to the Slot Machine
You'll st...
I have 3 SQL Queries and converted them to ActiveRecord Queries
(1)
I have some raw sql queries with a couple of inner joins, where and select.
query = <<-eos
select u.first_name, u.last_name, r.name region, s.name district, s.id district_id
from users u
inner join fixed_loca...
My current condition is written as follows:
.Where(m => Math.Round((m.DateAndTime - DateTime.Now).TotalMinutes, 0) <= 30 && Math.Round((m.DateAndTime - DateTime.Now).TotalMinutes, 0) > 0)
which basically says where the rounded value is less than or equal to 30 and the rounded value is greate t...
Problem
Find (a^b)%M, where
a = Nth non-fibonacci number
b = Nth fibonacci number modulo M
M = 1000000007
Consider fibonacci series 1,1,2,3,.....
INPUT
First line contains T , the number of test cases.
Each next T lines contains a number N.
OUTPUT
Print T lines of output where each lin...
I've implemented the well known Luhn Algorithm in Python. It's a simple one, so it's good for beginners.
Here's the code:
import random
from math import ceil
def Luhn(digits):
if digits >= 2:
num = random.randrange(10**(digits-2),10**(digits-1))
num_digits = list(str(num)...
I am trying to extract the data from input file and store it for plotting.
I have tested this code for a few files of same format.
I am not sure if the code works correctly with the little change in input file (like more blank spaces in between). I might have also done some terrible mistakes whi...
T-SQL is a specific implementation of a SQL(anguage). I don't like this suggestion, but I'm failing at finding a good analogy. The Python tags come to mind. We decided not to synomize the specific versions into the master tag because their syntax was significantly different. I think the same theory applies here. PL/SQL is different enough from T-SQL that it doesn't make sense to point them both at the same master tag. — RubberDuck31 mins ago
@daniel I’ve edited the code in. It is still not clear, what your actual problem or question is. Also, we don’t have enough context. What is checkout and what is $checkin? Are they Date objects? Why is there a $ before checkin? Why would you wrap your timecheck function as a parameter in the jQuery function? Do you even have a specific problem or are you asking us to review your code? Code Reviews have their own site. — Xufox18 secs ago
@Xufox This question is way too unclear and too much lacking context for Code Review as well. And based on this comment, I suspect that the current code does not work. — Simon André Forsberg12 secs ago
I have done a simple *.cshtml, that I call data from DB.
*.cshtml has different table headers;
Problem is that it show`s each time my is part od OID == 1 or OID == 2; It prints on screen after every single question.
@foreach (var o in @Model.ListTest.Cast<O_D_O>())
{
...
@Goobley: Yeah at some point you have to train rather than protect. :) Your code review practices should account for this. I understand the desire but I (a) really do think you're creating an environment wherein inexperienced folk develop a false sense of security [very dangerous!!], and (b) indeed cannot think of anything else you can do. — Lightness Races in Orbit1 min ago
I fixed it by copying the typedef into the source file and then static casting it to that type, it's no longer ambiguous, but I don't think that's the way to go
Or... are the arguments for event_listener_aux essentially the same as event_listener? (Is event for example, a typedef'd tuple with all those arguments?)
Does the event class have a constructor that takes this: std::function<void(const std::string& name,message::ptr const& message,bool need_ack, message::ptr& ack_message)>?
But you can see how that would cause ambiguity, right? Compiler isn't sure whether it should call the one that takes the raw function, or if it should construct an event and use the function that expects the event.
If there is ambiguity and both overloads do the same thing, why not comment out one or the other and see if it still compiles and does what you expect it to?
That's not the fix, but it could lead to enhanced understanding on what the problem is.
In Swift, it's possible to create ambiguity, but it's kind of difficult. The only way is if you have two functions that take the same arguments, and the functions have the same name (even the argument names), and they're only different by their return type, and you're trying to implicitly infer the return type.
But even... func foo(arg1: Double, arg2: Double) -> Double { return 42 } wouldn't create ambiguity with the Int version, because it's impossible for the input types to be ambiguous in Swift. Which is nice.
I have some tasks that I'd like to memoize because they connect to a rather slow network and have to wait for the data. Unfortunately this network can be a little finnicky and we get occasional connection issues. Thus I'd like if my memoizer could know to retry a certain number of times. This ...
I believe naming should stay. Some of us have a chronic problem with naming things (myself included). Since tags exist to either show what is done (language tags) or what the problem is (time-limit-exceeded, namespaces, etc.).
If we don't want naming around, there are more tags we should be disc...
But if you instead say "You could try this post on Code Review and please read A Guide for Stack overflow" then they HAVE to at least open the link to the page.
No more re-typing the same comments over and over!
This script adds a little 'auto' link next to all comments boxes. When you click the link, you see a popup with 6 configurable auto-comments (canned responses), which you can easily click to insert.
This script was inspired by answers to thi...
@Mast I believe there are meta questions related to those meta-tags that we have kept so far. beginner is also a meta-tag that was brought up on meta recently. I don't think it's possible to lump all meta-tags together like that and say either "keep them all" or "burn them all". Just because we burn some of them doesn't mean we need to burn all of them.
Im new to Java so any suggestions and remarks are welcome!
Here is the task:
create several classes of flowers that extend abstract flower. all fields -- random.
1) make a bunch of 20 different flowers
2) calculate the price of the bunch
3) sort bunch by freshness of flowers
4) find flowers w...
I need to parse only valid timestamp formats as below
hours followed by minutes followed by seconds ex:t=1h2m3s
minutes followed by seconds ex:t=2m3s
only hours ex: t =3h
only minutes ex: t =4m
only seconds ex: t =5s
and escape other timestamp formats like t=2m1h or t=3s2m or t=3s1h2m.
To get...
We have a decent selection of language and technology tags, but we also have many meta tags, such as refactoring. A meta tag, at least on here, specifies the OP's request(s) in a review, and not much else. It could especially become problematic if the OP has many requests and tries to apply as ...
I think that, considering the constraints of your situation (Iterable), the implementation is about as good as it's going to get.
However, that does not mean there aren't things that couldn't be improved.
Camel case is standard for method names. I find getOnlyOne to be easier to read than the ...
There are some issues with this question; Asking us what an entire block of code does is off topic because it's not written in a way that's useful to other people. No one will ever search google for "What is going on in this javascript and can it be simplified". Also, you have two questions here; 1) How do I refactor [whatever this does] and 2) what is it doing? The first can be asked on codereview.stackexchange.com, providing you meet their criteria; the second is too broad as written (and not useful because the title and body lack terms people would search for). — George Stocker ♦6 secs ago
All the strings you are replacing are single characters, and you can probably exploit this fact. I imagine that the majority of strings probably contain none of these special characters. Therefore the best approach might be to do an initial examination of the string to see if it does contain any ...
I have tried the code it took 8-9 sec for each run for input 1-1000000000
Note in the code just commented the printing of prime number.
`import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class primeBetweenTwoNumbers {
public static void main ...
I am trying to parameterize a powershell script. The only issue is that for some reason when I am calling the invoke-restmethod with a -uri of $url it seems to be choking. In fact everywhere I am trying to use this it is choking. I believe I might be trying to do this incorrectly. Is there a bett...
yes, in fact most of the comments say it was fine code, in the future if you just want a code review try codereview.stackexchange.com, SO is for questions about why something isn't working as expected — depperm55 secs ago
@rolfl so am I ;-) But I still suffer from my lacking Xsl expertise. i thought that strings I have in the code are representations of Single characters
@Marged translate is not the function you think it is.
let me explain, if you want to convert, say, a windows path name to unix format, you want to replace all \ with / ... right?
So, unix = translate(dos, "\\", "/")
But, if you were to want to translate the string value "dos" to "unix" in all strings, like the string "dos is so cool"
and you were to use translate like this:
cool = translate("dos is so cool", "dos", "unix")
then the result will replace all d-characters with u's, all o's with n's, and all s's with i's.
so you will get the string: uni ii in cnnl
If the 'replacement' string is shorted than the 'look for' string, then characters in the look for string that do not have a matching character in the replacement, are just deleted....
so, translate(value, "abc", "") will just delete all a's, b's, and c's in the value.
a string like "This is a bad name" will become "This is d nme"
I'm working a rails application that has a lot of logic in the controller that should be in the model. In the app/controllers/customers_controller.rb#create there is logic to create stripe cc info for the customer. I think this should be in the model. How can I move this logic into the model and ...
In angular, I have an input field for a user's full name. And a function called splitName which extracts the first / last name from the field. Is there a way to improve this logic?
<input type="text" name="fullName" ng-model="data.full_name" />
On the backend, on form submit I do a POST which ...
Im relatively new to python and I am making a punnett square. I have found the first punnett square, but I need some help with the second. I basically want #F2 to do the same exact thing as #F1. Here is my code. Thanks!!!!
import itertools
from collections import Counter
parent1 = 'aaGG'
parent...
tr is a command in Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.
The utility reads a byte stream from its standard input and writes the result to the standard output. As arguments, it takes two sets of characters (generally of the same length), and replaces occurrences of the characters in the first set with the corresponding elements from the second set. For example,
tr 'abcd' 'jkmn'
maps all characters a to j, b to k, c to m, and d to n.
The character set may ...
You also have a number of case where you are hard-coding things where there is not need to do so. I would suggest putting this code on codereview.stackexhcange.net to get some constructive feedback on ways you can improve your code. — Mike Brant39 secs ago
@Vogel612 because @RubberDuck is right, it is fragmented badly too.
it's a mess the way it is.
I just don't think that there is a good solution, and the current mess is probably better than the alternatives.
it's hard to recommend any course of action which is ugly.... like deciding to write a program in either COBOL, LOLCODE, or Brainfuck - hey, there are choices, which one is best?
I have the following Ruby code that's designed to update item, price and stock data for items in a MSSQL database. It's running on a Ruby 1.8.6/Rails 1.2.3 installation, in its own controller (for now)
What I'm looking for is ways to optimize performance.
Right now each item takes about 0,2 se...
Just might be something for CodeReview, sufficient many things might be improved upon. Time it, use a profiler maybe, find bottlenecks and put some thought in optimizing the data structures. — Joop Eggen33 secs ago
My meta answer suggests the t-sql -> sql synonym, which would be like a python3.0 -> python synonym
That makes a "relative" amount of sense, but I suspect the t-sql specialization is large enough to stand on its own.
people who follow sql, and not t-sql are the losers, though
it also has established a precedent, that each database has its own flavour of sql.... so we need db2-sql, and mysql-sql, access-sql, etc... those are tags which are on the wrong side of the threshold, right?
it's just a mess,a nd there's no good solution, and doing nothing is as bad as doing something, but a lot less work ;-0
Your code should do exactly the same without your condition, doesn't it?
scope.splitName = function(data, fullName) {
var formData = angular.copy(data),
nameArr;
if (fullName) {
nameArr = fullName.split(' ');
var lastName = nameArr.pop();
formData.first_name = nameArr....
Can you assess source code of my client-server program?
I would like to get an advice about design, code security etc.
Thank you very much.
The program does the following:
Show files in directories;
Download and upload files (for now, only one file at a time).
Syntax:
./client <Server IP> <