Is there any better solution to this problem?
//(a,b) and (b,a) are allowed
#include<map>
#include<iostream>
int main()
{
std::multimap<int,int> A;
int num[4]={2,4,5,6};
for(int i=0;i<4;++i)
{
for(int j=0;j<4;++j)
...
Below is the code that implements sequence abstraction using type abstraction class Sequence(in Java)
/**
*
* @author mohet01
*
* @param <T>
*/
public class Sequence<T>{
/**
* Abstract data type constitutes constructor and selector functions
* written below under representa...
I've just started iOS development and learning swift. My code below works. But I'm interested to know in ways I can improve it having no experience in iOS Swift prior to this attempt.
import UIKit
class NewsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var table...
So I wonder:
Is there a better way other than assigning ID's manually and creating separate lists for each model the way I have? (for this particular scenario).
If so, how? (Still taking the conditions into account).
The conditions are:
Through an external source get a list of unique book...
Code should display
Radius: 0.000000 volume: 0.00000
Radius: 0.200000 volume: 0.0335103
Radius: 0.400000 volume: 0.268082
Radius: 0.600000 volume: 0.904778
Radius: 0.800000 volume: 2.14466
Radius: 1.000000 volume: 4.18879
all the way to Radius= 4.0 but 4.0 isn't showing and some of the decima...
Sort a stack in ascending order. You may only use one additional stack to hold items.
Any comments on my solution?
Worst case complexities:
Memory complexity: O(n)
Runtime complexity: O(n^2)
Also, I implemented the Stack class as having Object items and then cast these into Integers to be more...
The purpose of this code is to generate the CSR and the Private Key.
The scenario is that we have some clients for whom we run websites and for the SSL component we want to have a page on our site where they can input the fields like domain name, company name etc and then the system will generat...
There are definitely some things to say about this. As far as I can tell you're making things harder than they should be and by changing some things you can make your code a lot more readable. I'll work through your code first and look at your approach afterwards (mainly because I haven't read th...
I'm not exactly sure if this is technically an "arena allocator" but it serves a similar purpose: providing a fast way to allocate a lot of objects that can all be freed at once.
#include <type_traits>
#include <utility>
#include <new>
template <std::size_t BlockSizeIn = 1024>
struct BlockProvi...
I'd like to use JavaScript to generate HTML.
I've made a JavaScript function object that has two parameters; a string and generic object. The string is used to specify the type of HTML element you want to generate and the generic object is a container for key value pairs specifying the element's...
Does python + mysql actually make a good database website(in the sense that I want a website where you can interact with things that modifies a database and prints things from the database)
MariaDB is a community-developed fork of the MySQL relational database management system intended to remain free under the GNU GPL. Being a fork of a leading open source software system, it is notable for being led by the original developers of MySQL, who forked it due to concerns over its acquisition by Oracle. Contributors are required to share their copyright with the MariaDB Foundation.
It intends to maintain high compatibility with MySQL, ensuring a "drop-in" replacement capability with library binary equivalency and exact matching with MySQL APIs and commands. It includes the XtraDB storage...
Since most of the original mysql devs now work on mariadb, it is likely that mariadb will "happen"
The following function works fine. However, deleting 1 mail takes about 4 seconds (from start of operation to the firing of the completion handler). Currently, using mailcore2, copying mails on the Gmail server.
Any significant issue spotted by any guru? Or am I just making a mountain out of a m...
How can i make a link downloadable using anchor tags?
example:
<div>
<video src="videos/cat_video.mp4 controls loop preload width="600" height="300"></video>
<a href="videos/cat_video.mp4"> Download</a>
</div>
There is a job interview question, and the source of the question is here.
The solution is pretty simple. We just need to split the input string by + and then by *. Then we compute products in a nested loop and sum up all the products.
Here is the code:
public class Main {
// http://www....
due to been unable to ask a C programming language expert or
advanced user in person I'm posting this simple question
about my C code, today I was refreshing my C with exercise
5.4 of the C programming Language 2nd Edition by K&R,
which is a very simple exercise, the question is:
do you think t...
The following JS code object displays the time and updates whenever it changes.
If a timestamp URL is supplied, this will be the source of time so that it doesn't have to rely on the client's unreliable date (which can be changed anytime and affect the result). Else, there is unfortunately no ot...
The following XML is the ideal XML for my code that I need to achieve.
<ARequest xmlns="http://test.com/AClass/2015" TimeStamp="2015-01-01T06:39:09">
<Authentication UserName="ex" Password="*@#ME"/>
</ARequest>
But I get the following XML
<ARequest xmlns:xmlns="http://test.com/AClass/2015" Ti...
I've got a list of object in python which i want to sort based on a attribute.
I have done it using:
list.sort(key=attrgetter('ColumnName'))
I have found using profiling my python script that it takes more execution time for the sort().
Can anyone suggest a better and faster way to sort l...
Compile time checking of printf-like format strings
Inspired by this open ticket on boost, this seeks to complete the work there
Given a printf-style format string and associated arguments, a static_assert is performed on whether the format string and arguments are valid.
I'm particularly inte...
I'm trying to do a code which works with arrays, the thing is that I need to do a method delete(Object e) which has to delete all the objects in the array that equals "e", the thing is that I can't use any of the methods in java.util, and I can't use List or ArrayList, I can only use "for" and ha...
I'm trying to transition from JavaScript to PureScript (a Haskell spinoff that transpiles to JavaScript). For starters I coded this:
getAt :: [String] -> Number -> Number -> String
getAt strings x y = case strings !! y of
Nothing -> " "
Just line -> case charAt x line of
Nothing ->...
Input
^#%foo.bar#%#%canhaz%#
Output
foo.bar#%#%canhaz
Function (attempt 0)
#!/usr/bin/env python
from string import punctuation
strip_special = lambda s: ''.join(c for c in s
if c not in (char for char in punctuation
...
I've put together an algorithm for an assignment. I've done my best to try and keep it to a professional and readable standard. I'm posting it here so that I can get some feedback and suggestions on what it's like and whether I could improve the algorithm in some way.
/***** Algorithm
...
I'm using a Python script to run a particular program that occasionally may need to be terminated (by receiving a SIGINT or SIGTERM) in which case a clean up process needs to be invoked (before killing the original process).
To test it I start the program in question and then I send a SIGINT to ...
This problems link is http://www.spoj.com/problems/SCUBADIV/.
It is basically a 0-1 knapsack problem only. The logic I have implemented is Bottom up :) and so far I have found it perfectly correct.
But it give WA in spoj. Could some one help me with this.
#include<iostream>
using namespace ...
I was reading some gameprogrammingpatterns (Awesome book, by the way, would reccommend) and was very excited when I learned that unions are a thing that exists, so I decided to implement an object pool as outlined there.
I'm looking for a review of the usual culprits. Poor readability, not makin...
There's quite a lot to address here, but I'm going to start with my absolute largest concern--one that will cause problems for anyone who uses this:
func getData(completionHandler: ((NSArray!, NSError!) -> Void)!) -> Void
There are places where it's okay to use the implicitly unwrapped optiona...
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
public class TestClass1 {
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter No of e...
i'm newbie in java, learning to do some staff with collection, etc. My task is, add list of student's which i've input from keybroad to group. And dont have any idea, how to realize it. So, shall i've use iterator to some how input my students list to group or i need to use foreach loop for it? G...
I've written a Data Access Layer for an MVC app I'm working on. Several Controller methods call several functions from the Data Access Layer. If more than one function is called, I initiate the connection in the Controller and pass it to the DAL, like so
public ActionResult MyView(MyModel model...
If the code is already working, then the question is better suited for Code Review. Meanwhile - generating all permutations gives a combinatorial explosion, so think about better algorithms. — S.L. Barth9 secs ago
Consider a Trading Card Game that is currently available for play in digital format only, the game in question would be HEX: Shards of Fate, but this question is intended as a general question about all Trading Card Games.
Now my idea is to create an AI player for that game and see how good it p...
You need to contact the owner of the copyright and get permission in writing or contact lawyers.
Everything written in the answers to that question also applies to your situation. When you want to ask about nuances of copyright law, you would be well advised to ask an actual lawyer, because this website is a website for game developers, not for legal professionals. But he will likely tell you the same: Using someone elses IP without permission is illegal, and you would be very ill-advised to try building a business on it. — Philipp8 mins ago
The following function works fine. However, deleting 1 mail takes about 4 seconds (from start of operation to the firing of the completion handler).
Currently, using mailcore2, copying mails on the Gmail server.
Are there any significant issues?
func deleteOnServer (indexSet: MCOIndexSet) {
...
I needed several classes with methods performing network requests which should be executed asynchronously (with callbacks). To get rid of repetition, I added a mixin and a helper class:
module Asyncable
def async(&callback)
AsyncHelper.new(self, &callback)
end
end
class AsyncHelper
at...
I'm voting to close this question as off-topic because there's nothing wrong with the code shared in this question. This question belongs to codereview.stackexchange.com — Farid Nouri Neshat1 min ago
<?php
namespace Compact\SiteBundle\Controller;
use Compact\AdminBundle\Document\Page;
use Symfony\Component\HttpFoundation\Request;
use Compact\SiteBundle\Cache\RedisCache;
use Compact\SiteBundle\PageHtmlCompiler;
use Compact\SiteBundle\ComponentHtmlCompiler;
use Symfony\Component\HttpFoundati...
If you're code works, but you want to improve the quality(which includes efficiency) of it, then codereview.stackexchange.com is the right site for you I believe. If you're code doesn't work, then state the problem, what happens and what should happen. — Farid Nouri Neshat46 secs ago
It's not a good idea to post a duplicate of a bad question when that original bad question was closed. Please visit out help center to see how to ask a question here. Then edit your original question so that it may possibly be reopened. — RubberDuck41 secs ago
Should be a minimum 6 hrs between posting questions with same language tag.
Or 24...
Because there are usually some generic enough points in the first that could be applied to your other code in that same language... So don't waste time
This is a script I use on a Google sheet for parsing data that has been pasted from various other softwares and getting it into the correct format and columns on another sheet.
function SendToWorkLogCL() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
sheet where data is entered:
var ...
New to writing question titles and I'm not sure if mine is as good as it could be. Could Jamal take a look at my CodeReview question title? @captainobvious
Overloaded is actually what I'm using now. I thought that was kind of a more beginner thing to do. I want to run with the big dogs! Is it okay to overload so much? I don't want to be laughed at in a code review. — John Jenkins39 secs ago
I'm kinda new to Java (<1 year) but have some background in C and Python.
I've come up with a working solution to Project Euler Problem 4 - Largest Palindrome Product. However, I'm not confident this is "Effective Java"...
All suggestions for improvement are welcome. I'd especially like feedbac...
Created for a console application that will be run in the background on a linux system, giving me a nice way to gracefully shut it down by simply deleting a file (which can be done via script/etc.)
public class BlockOnRunFile {
private File watchedFile;
private Path path;
private Wa...
I have a programming assignment where I need to build a Webserver which can handle GET and HEAD requests. My webserver is working as it should but since I'm still a newbie at Java I'm not sure about my structure or quality of my code so if you have some criticism/tips I would appreciate it :)
Ma...
I am implementing a code for ALU. Now the question is My code is running for the op=2'b00,2'b01,2b10.But the fa module for adding 4 bits numbers AI and BI is not changing it's value. My problem is I can't reflect the value of sum in OUT variable.
Here is my code -
module ha(en,a,b,s,cout);
input...
I'm new to Java and wanted to present to you my latest project: Ulam Numbers
/**
* This class consists of some instance variables a constructor and some getter and setter methods
* It is supposed to implement the Ulam numbers which are named after Stanislav Ulam
* Furthermore we will make u...
Finally got our debug panel working so testers can manually run SPs without needing management studio and so they can do a bit more on the debugging end with certain bugs.
Background: I'm building a dynamic in-house on-call roster that will be displayed on a web page. The end user will be displayed a list of people who are currently (at the time of the database call) on-call for various organizations, departments within the organization, and offices within the dep...
I am using the following source code in order to extract sparql queries results. As results for S._V._Krishna_Reddy I am getting:
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.6.2</center>
</body>
</html>
...
Kindly help me find out if the approach I took to generate random string here is correct to be able to return appropriate short urls.
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
/**
*
...
> This team is going from a .Net to a java platform. The purpose of this resource is to be able to hold the fort down on the .Net side of the house while the team transitions and gets trained up on the java platform.
There's no way you can convince me that Java is C#'s equal. All it has are some fancy enums and broader cross-platform support which is going to fade now
speaking of Java
Tonight in 2 hours I have a skype meeting with some tutoring service. If all goes well, I'll likely be tutoring dos chicas in Java for a few lessons
@Jeroen - your comment about C#/Java is uncharacteristic.... it is my observation that there are four types of software development: mobile, desktop, enterprise, and cloud. In mobile, the largest growing sector (android), is Java and Javascript based. In desktop, it is actually Javascript based more than C# - although the backends are done in a mix of C#, Java, and others (most desktop functions are now down through the browser, not a custom app).
In enterprise, the bulk of dev is done in Java, with a significant C# chunk as well. But, in the biggest growth market, cloud, almost all servers are Linux, so, you are working in everything other than C# (and .NET, etc.).
Bottom line, is that C# limits you to a small, shrinking area of IT developments.
I don't think C# will turn into COBOL though, not with the native cross-platform support, open-sourcing initiatives and emergence of things like Xamarin
There is something about being a business, and looking at the price of spinning up 100 virtual machines for a job, and what it costs in Linux, vs. what it costs in Windows.
Cloud computing is all about the very low margins on resources, and the rapid availability of scale.
being able to provision a new machine in a few seconds, for a few seconds, is what it is about.
It costs $0 to do that with Linux.
(other than the hardware resource... which, would be more with Windows anyway).
There is not much context given, is this the only code you're looking to have reviewed? Typically a question on this site will have several relevant classes rather than just one method... — Phrancis13 secs ago
I have downvoted this question, holding off on a close vote for now. If your question is "what's the best practice regarding X?", per our help center it's explicitly off-topic on this site. Good CR questions involve your real actual working code, that answerers usually review against best coding practices. — Mat's Mug3 mins ago
@Phrancis I see we have similar taste in good CR questions :)
I am using opencv 2.410 to implement a project. My project allows to segment head from video sequence which get from camera. First, I detect the head region and then apply segmentation method for that ROI region. For high accurate segmentation, I have chosen Grabcut method. However, it is very sl...
So i've been making a trivia game with SFML and c++ for quite a while now for my school project and i would like to get some constructive criticism, anything helps from best practices to overall correctness.
Everything on github for readability
Here goes main.cpp:
#include "Trivia.hpp"
int ma...