@skiwi Yeah, I'm leaning towards Java and Spring-MVC, as I have some previous experience with that. But they're not ready to start just yet either way so we'll see.
I got sick and tired of writing certain functions over and over again, so I made a module that has those functions whenever I need them. I don't use it for code I plan on sharing, so I don't need to worry about portability. I do code in Python 2 and Python 3, so I used a bit of hackery to make it...
I can run more stuff on an ubuntu computer that has less power than on a windows machine with more processing power and more Memory and more everything....
Recently I have discovered one thing, which makes me feel frustrated. The Perl is lack of syntax sugar for strings, to do the same things, those are applicable to lists. The implementation I posted here would require to be rewritten to work for lists.
Thus, I had to re-write the code to Python t...
I am working on an HTML5/jQuery todo list app and here is my code so far: http://jsfiddle.net/rdesai/csTS7/19/
As you might notice, there are some functions called at the beginning of the JS code. These functions work perfectly right now. My question is - Is it OK if I declare these functions in...
After posting my previous question about this Job Queue, I decided I wasn't actually very happy with it. I am embarrassed to admit that upon further testing it did not function properly in all situations. I received some awesome feedback about it, and I have made extensive changes to the classe...
Given two linkedlist, merge them. Looking for code review, optimizations and best practices.
The code is influenced by feedback here.
public class MergeLinkedList {
private Node first;
private Node last;
private int size;
MergeLinkedList(List<Integer> items) {
for (Integ...
It's a weird thing with a comparison. We are processing appointment files, and we want to remove duplicates that are later in the day.
We are using the SELECT command available through datatable.select()
the one in question has appointments at 5:30p and 6:30p.
Here's the select criteria for the dupe removal:
7/8/2014 11:07:06 AM: Search Expression: phone = '0000000000' AND txtname='SOMENAME' AND time > '17:30:00' AND deleted=false AND dr <> 'X'
7/8/2014 11:07:06 AM: Search Expression: phone = '0000000000' AND txtname='SOMENAME' AND time > '18:30:00' AND deleted=false AND dr <> 'X'
Neither one of those returns any rows. However, if you change the first criteria to be less than, rather than greater than, it finds and deletes earlier appts leaving you with the latest one.
if ((bool)currentRow["deleted"] == false && currentRow["dr"].ToString() != "X")
{
string expression;
expression = "phone = '" + currentRow["phone"].ToString() + "' AND txtname='" + currentRow["txtname"].ToString() + "' AND time > '" + currentRow["Time"].ToString() + "' AND deleted=false AND dr <> 'X'";
LogOut("Search Expression: " + expression);
DataRow[] drsearch = dsPassInfo.Tables["RawAppts"].Select(expression);
In that form, it never returns a match. Flip the > to < and it works.
Is there a faster way to get all primes between 0 - n
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
namespace myPrime
{
public class simplePrimer
{
public List<BigInteger> primeList;
public void findVersion(...
I have seen various tweaks for quicksort and to establish their usefulness, I designed a program that randomly generates arrays and times how long quicksort takes to sort them. Right now I'm focusing on how the pivot is chosen. I'm comparing choosing the first element as the pivot versus choosing...
Let me explain my thinking - each code is an independent piece as mentioned, becuase in interview ( not in real life ) i have to write linkedlist or tree only once on white-board so I guess code duplication concern can be discarded. — JavaDeveloper8 mins ago
I understand what you mean here, but if you would do this in an interview it would be a bad idea to have one class only. I think your code would be better if you could separate the data structure from some methods operating on them.
Of course your BinaryTree could have methods such as remove and add and stuff, but I would not expect to see a findNodesWithoutASibling method inside the BinaryTree. It's way too specific for that.
Regarding your concern for hiding internal details, yes that is a good thing, but your could still provide methods to modify the BinaryTree. Such as getChildsFor(int nodeValue) and addChildTo(int nodeValue)
@JavaDeveloper Your node class can be hidden inside your BinaryTree class, just like you do now. You do need to, however, provide proper methods to do work on your BinaryTree.
@JavaDeveloper The java.util.LinkedList class does a good job in hiding the internal details (the Node), but it still provides sufficient methods to modify the List.
@rolfl @JohnP Haha, I really never knew pulling questions from geeksforgeeks would be a concern, well each question belonge to somewhere, none of the questions Ive asked were invented by me.
The Swedish Gold Coast () was a Swedish colony founded in 1650 by Hendrik Carloff on the petroleum and natural gas rich Gulf of Guinea in present-day Ghana in Africa. It lasted until April 1663 when the whole Swedish Gold Coast was seized by Denmark, and integrated in the Danish Gold Coast.
Geography
The colony consisted of only a few forts and trading posts scattered around Cabo Corso (present-day Cape Coast) along the coast on the petroleum and natural gas rich Gulf of Guinea in what later would become the British Gold Coast then Ghana.
The colony consisted of fortifications and trad...
@JavaDeveloper It's perfectly fine to pull questions from geeksforgeeks or other sites, most of us (or at least I) just had no idea from where you were pulling your assignments. It is good that we know now.
Anyway, @JavaDeveloper - you will find, that there is this whole chat side to Code Review, also, you are one of the site's most value-generating people. As the site's most prolific asker, you come up quite a lot in various places including some public newsletters and such
BlockingQueue<Message> messages = new LinkedBlockingQueue<>();
new Thread(() -> Converter.socketToMessages(socket, messages)).start();
while (!messages.isEmpty()) {
@rolfl have a job, but very frankly my interview success-ration is near negligible. It takes ( hopefully took ) scores of interviews to land a job. Thus I realized I need to keep practicing them routinely.
I do feel selfish to never contribute back to community, but I hope questions I ask and feedback are useful to other people.
@JavaDeveloper Well you have achieved some very notable popular questions. But I think you would get even more experience from reading and working with other people's code.
This python code feels fairly long for python code. How can I improve it?
class List:
def __init__(self, list):
self.first = list
def __repr__(self):
element = self.first
elementsList = ''
while (element != None):
elementsList += str(element) ...
I want to cythonize a code in python to speed up the code. In the following you can see my attempt to make it understandable for cython:
import numpy as np
cimport numpy as np
ctypedef np.double_t DTYPE_T
cpdef double std_G,v_c
std_G=4.3e-9 # Newton's const in Mpc (km/s)^2 M_sol^{-1}
v_c = 299...
I'm using multiple jQuery filter functions to affect the background color of select objects based on the selected option and it works, but it seems bulky/redundant. Does anyone know how these filter statements could be simplified/combined? I have a JSFiddle here.
Thanks.
<!-- Load minimum ...
I've written a decorator for easily creating multiple dispatch functions:
from functools import wraps
def multi_dispatch(for_function):
"""
Returns a multiple dispatch version of the function.
The returned function doesn't allow keyword arguments.
>>> @multi_dispatch
... d...
@SimonAndréForsberg does this implementation sound right ? Its exposing internal structure of Node. There is not method to even construct a linkedlist ?
@SimonAndréForsberg I understand but that would need to another set of feedback - why are u exposing stuff that should be internal. Most of the answers on the net as similar to what you suggested, but they somehow seem to come with their own issues.
@SimonAndréForsberg what I am strugging to understand here is how can I have a Linkedlist class datastructure that can be passed to another static class to do operation on it ?
@SimonAndréForsberg what should ll.getNext() return ? how does ll.getNext() follwing it keep track what where was the last pointer ? ( NOTE: I am not trying to refute you, its just that I am not getting clear idea of how other way really works, I want to hide internal structure as well as use a Static utility class they way you suggested )
@JavaDeveloper In that code they don't have a BinaryTree class, they only have the TreeNode, which doesn't make the TreeNode internal anymore. But I would not write it like they have done there.
@JavaDeveloper LinkedList has an iterator, remove, add, and a whole bunch of other methods. You use the things you can. The java.util.LinkedList class is made in such a way that you don't need to access it's internal Node structure.
I'm much more fluent in JS, but I needed to sort a lot of dates, ages, genders, etc. from a tab-delimited text file so I wrote this. Could I get some tips on how to make this more efficient and more Pythonic? The more Python I write the more I like it, but I definitely need some help.
One thing ...
@SimonAndréForsberg but for so many of my interview questions, I need to access them. I need to swap pointers, reverse, merge bla bla bla
@SimonAndréForsberg I am trying to fuse your suggestion without disadvatanges of exposing internal structure, pretty sure, you understand my dilemma here.
We are getting hypothetical. Maybe it is just me, and it won't work for everyone, but, in an interview, if someone asks me to reverse a list, I would ask why i can't use the standard tools.
@JavaDeveloper For merge: Call the public add method (possibly the add of the listIterator for better speed), for sort: Depends on what sort you are doing. Call add and remove, set, or whatever you'd like. For swap: Call set.
They'd need a reason about why you need to 'waste' time to implement something that already exists. In interview questions there are many legit reasons for that.
If they insist that I have to implement the list from scratch, then I would say, Hmmm.... that's odd, and contrived, are you sure the use case requires it?
@SimonAndréForsberg @rolfl let me make my question generic, lets ignore reverse for a second, many of linkedlist questions need me to play with pointers of internal data-structure, and only two ways around it are 1. make Node public rather than private and use a Util class 2. keep Node private and implement methods within data structure
@rolfl I use it a fair amount in my Card-game classes. I might also have used it in my Minesweeper code. And I can't remember having received bad reviews from that.
@JavaDeveloper When separating things into separate classes, you have to think about what methods are publicly available on those classes. As @rolfl mentioned in a recent answer to one of your questions, you might completely miss adding a get method and other important methods.
I'm working on a proxy service that will run on top of a Java application in order to manipulate some headers. I've just completed the first step and that is intercepting the request message and storing them.
This code features only the storage part, and not the edit and send part.
Some informa...
@rolfl I might understand just now what you meant by package-private vs. private static inner class. Were you thinking about BinaryTree & TreeNode? Because I was more thinking about CardGame & CardZone (which really should be two separate classes)
@SimonAndréForsberg totally agree, and in my latest code i did improvise on it. but, my mindset is a bit interview obsessed, and in interview they are only going to care about the single function that does its job 'merge / reverse" etc followed by some edge cases. Thus I happened to skip it
@JavaDeveloper I don't think that they are "only going to care" about anything. I think they are going to look at the overall impression they get from you.
I'm working on a proxy service that will run on top of a Java application in order to manipulate some headers. I've just completed the first step and that is intercepting the request message and storing them.
This code features only the storage part, and not the edit and send part.
Some informa...
@SimonAndréForsberg Right. I don't use Java much and forget which things are interfaces and which things are real classes. C++ doesn't make that distinction in that way.
I have a class that I use to represent a distance called Dimension.
Here is its four constructors:
/// <summary>
/// Accepts any valid architectural string value for input.
/// </summary>
public Dimension(string passedArchitecturalString)
{
storeArchitecturalStringA...
I would like a complete Threshing of this code so that I can see what I did wrong and what I am using incorrectly.
I did this super simple, trying to learn a little bit about List<T> while I was doing this. I have never actually tried to do this before, so I thought it would be a good learning ...
I have been unable to find any other way to update a user config file than the following method.
public class SettingServices : ISettingServices
{
public UserSetting GetUserSetting()
{
XmlSerializer reader = new XmlSerializer(typeof(UserSetting));
StreamReader file = new...
I would like a complete Threshing of this code so that I can see what I did wrong and what I am using incorrectly.
I did this super simple, trying to learn a little bit about List<T> while I was doing this. I have never actually tried to do this before, so I thought it would be a good learning ...
I need assistance as I am having the following error and cannot understand what I am doing wrong.
The error is: error: '{' expected public class PanelTop()
These are my first weeks of java therefore your feedback is much appreciated
import java.awt.BorderLayout;
import java.awt.Color;
import jav...
@Malachi - You introduce your own inefficiency. When you build the initial list, you can automatically discard any even number, that way you don't have to test it.
@Malachi - Although, it seems that the code as edited runs in about the same timeframe, and takes up 3 megs more of memory than your original. At least according to .netfiddle.
What you write here is plain incorrect. Actually each line of code, except for about 8 in that 80LoC method has their full reason for existence. after I spent two hours dissecting the code and having a rename-orgy I know! Actually I am sure your code will not produce the same output for a few test cases I have come up with. I will post an answer tomorrow to prove — Vogel6125 mins ago
@JohnP I believe @rolfl haven't seen it. Or at least he told me earlier to don't tell him the score. I'm not sure if he's aware of the result or not though.
Certain interactions within a $scope of my application require side-effects that happen in other $scopes. For example, a registration event should trigger changes in the top navigation and content but I want to keep the navigation and content entities safely decoupled from the registration code. ...
I'm not sure if that title is correct as English isn't my first language. Let's get straight to it:
So let say a user has a 575 post and i want to give access base on post level.
In order to be user Level 1, that user have to have more than 200 post, level 2 = 300 post more (500 in total).
I n...
I tried writing alternative functions to Java's BigInteger.add(BigInteger.ONE), BigInteger.add(BigInteger), and BigInteger.subtract(BigInteger):
public static BigInteger increment(BigInteger x)
{
int i=0;
while(x.testBit(i))
x=x.clearBit(i++);
x=x.setBit(i);
return x;
}
public st...
I thought BDD was about testing behaviors like asserting that foo.Bar("baz") is called rather than testing state like foo.Bar == "baz". The given/when/then naming style came along for the ride, but it's an orthogonal concept you can still apply to state-driven tests.
My goal is to create a memory-efficient (immutable) collection of strings. The imagined use-case is checking for valid words in a Scrabble-like game. The approach is based on the paper Incremental construction of minimal acyclic finite-state automata.
namespace Mjolka.Collections
{
using Sys...
@DanLyons hmm, could be... although in a stateful application, isn't testing state a good way to make sure that it's behaving the way it's supposed to?
iow if you want to test that foo.setBar("baz") behaves correctly, shouldn't you call it and then check the state of foo.bar?
i mean, just testing that foo.Bar("baz") is called isn't good enough, is it, you need to make sure it actually did the right thing don't you?
maybe I'm confused about how it's supposed to work
For example. if you have a view with a Save button that ultimately persists data to a file, there may not be anything in your presenter(MVP)/viewmodel(MVVM) you can look at during testing.