I wrote an email syncing program in my asp.net mvc website that syncs e-mails from multiple e-mail accounts to my database.
Each e-mail account has to be independend from other accounts and they have to run asynchronously.
Are there are any issues with my code such as efficiency, bugs or can th...
I'm working on some simple console game and I'm starting to get stranded in my modelling. There is some fragmentation and tight coupling going on!
In this version I would just want to be able to move my paddle over the screen (but this needs te be extended to multiple players, ill get back to t...
My code, which generates Cartesian product of all lists given as arguments:
public static <T> List<List<T>> cartesianProduct(List<T>... lists) {
List<List<T>> product = new ArrayList<List<T>>();
for (List<T> list : lists) {
List<List<T>> newProduct = new ArrayList<List<T>>();
...
Computed 1100771 values with 0 sumdiff and -38.818% Base 7.739ms -> Fast 4.735ms
Computed 1100771 values with 0 sumdiff and -28.031% Base 7.649ms -> Pimgd 5.505ms
Computed 1100771 values with 0 sumdiff and -39.467% Base 7.711ms -> Fast 4.667ms
Computed 1100771 values with 0 sumdiff and -29.522% Base 7.754ms -> Pimgd 5.465ms
Computed 1100771 values with 0 sumdiff and -40.457% Base 8.058ms -> Fast 4.798ms
Computed 1100771 values with 0 sumdiff and -28.875% Base 7.733ms -> Pimgd 5.500ms
Computed 1100771 values with 0 sumdiff and -38.530% Base 7.764ms -> Fast 4.773ms
Pimgd code:
final int q = day;
final boolean isJanOrFeb = month < 3;
final int m = month + (isJanOrFeb ? 12 : 0) + 1;
final int calcyear = year - (isJanOrFeb ? 1 : 0);
final int K = calcyear % 100;
final int J = calcyear / 100;
int offset = q;
offset += (13 * m) / 5;
offset += K + (K / 4);
offset += (J * 5) + (J / 4);
return ((offset + 5) % 7) + 1;
'Fast' code:
final int isJanOrFeb = month < 3 ? 1 : 0; //(8 - ((month - 1) >> 1)) >> 3;
final int m = month + isJanOrFeb * 12 + 1;
final int calcyear = year - isJanOrFeb;
final int K = calcyear % 100;
final int J = calcyear / 100;
return ((day + (13 * m) / 5 + K + (K >> 2) + J + (J << 2) + (J >> 2) + 5) % 7) + 1;
'Base' code is as per my question. I have removed validation of inputs from all versions.
Regardless, your version is consistently >25% faster, and mine is about 40% faster... and 15% faster than yours.... These numbers are more than I was expecting... I was figuring there may be a % or two in there, not as much as 40%.
A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's Congruence.
Zeller's congruence is a neat calculation because it involves a mathematical approac...
I used the example on http://msdn.microsoft.com/en-us/library/system.security.cryptography.tobase64transform%28v=vs.110%29.aspx,but with little changes in order to write a base64 encoder method. I have a few points about the code,
1) I would like to use "using" statement, but I do not want to us...
I'm still learning PHP OOP. So I'd like to seek for some expert advice or criticism regarding this code I created.
In this script, I created the objects I need to process the user input from a form. While the $homepage object is responsible for displaying the whole webpage.
My questions are:
I...
0001-01-01T00:00 MONDAY TUESDAY MONDAY is MONDAY
Exception in thread "main" java.lang.IllegalStateException: Unable to correlate our calculation 1 to the system 1
I have implemented a class that has a method to wait until "something else" has happened. When this has happened, the current thread stops waiting and returns from the method. This is my current code:
public class InMemoryAviReadyNotifier implements AviReadyNotifier, MessageListener<UrlAviMessage>...
I'm new to Python, but have a lot of experience with C and C++. I would appreciate some feedback on my implementation of a packer for this archive format. (Specifically, any feedback on how idiomatic this code is for Python, and any suggestions about the algorithm used).
VPK is a relatively simp...
I've seen a lot of people but didn't bump into the guy! I've seen more people speaking French than not! There were a lot of Francophone (probably tourist like me :P )
@rolfl I will take another look at this later. some good stuff in the links too. lot's of fun stuff here. but I will have to take out the comments so I can follow the code better now that I have read the comments....lol
I have started making a game using C# and I'm looking for a code review to help point me in the right direction or give ideas as to better ways of doing some things.
The requirements - these are pretty flexible at this point:
Players must be able to:
Equip Items
Unequip Items
Attack Monsters ...
I have a function that takes all items in a queue and increments their order (used to allow insertion earlier in the queue).
private function incrementAllQueueItemsWithOrderLargerThan($order_larger_than) {
return $this->queue()
->where('order', '>=', $order_larger_than)
->
A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's Congruence.
Zeller's congruence is a neat calculation because it involves a mathematical approac...
So let's take this code which increments a Javascript text field value:
<div id="counter">1</div>
var counter = $(".counter")
counter.html( parseInt(counter.html()) + 1 )
It can be made shorter by using the Unary operator + which behaves like Number():
<div id="counter">1</div>
var counter = ...
> Stupid joke aside, I think you shouldn't worry about this so much. There's probably other places in your code where you're spending far more resources.
I'm getting back into HTML and looking at source code for some pages we maintain... I found one with this pattern all over it should this be avoided in favor of... maybe CSS?
I have been trying to fully implement my hashing table, but I don't really understand exactly how the code works. I have my header file setup fine, I am just missing implementing the following:
V * find(K key) - which I want to return a pointer to the value I am looking for, or null obviously.
...
Back Story
I created arguments for this question: Is it possible to write reusable method that only some of its parameters are different? It has since been brought up that this may not be a good tag. I am here to present my arguments for arguments and get the community's feedback on the matter.
...
Welcome to Code Review! Unfortunately questions seeking help in writing new code, rather than seeking a review of code that is already written, are off-topic for code review. If you wish to have your working code reviewed, rather than new code written, please rephrase your question to indicate that. — Phrancis15 secs ago
Back Story
I created arguments for this question: Is it possible to write reusable method that only some of its parameters are different? It has since been brought up that this may not be a good tag. I am here to present my arguments for arguments and get the community's feedback on the matter.
...
Not a question that fits CR well. This is clearly short, untested sample code. You need $("#counter"), not $(".counter").
var counter = $("#counter")
counter.html( parseInt(counter.html()) + 1 )
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id...
We have both hash-map and hash-table in the system. I have been trying to keep from having language-specific constructs in the tags.
Not sure how this one slipped through... again.
I propose creating a synonym from hash-map to hash-table. This is better than burnination because new questions ca...
For practicing purposes, I created an application that attempts to find an optimal route between given points.
The algorithm is:
Connect two randomly selected points
Select a point that's still unconnected (let's call it A)
Find it's nearest connected neighbor (let's call it B, where C => B =>...
Field expects a decimal currency value, but doesn't sanatize, so if you put a $ in there (or anything else but numerals and decimal point) you get NaN ;-)
You need to get rid of these try/catch statements, they are everywhere.
Use one Try Catch Statement
Instead of what you have
public static bool ConvertToBase64(string inputFile, string outputFile)
{
try
{
using (FileStream inputFileStream = new FileStream(inputFile, FileMod...
@RubberDuck I don't think we are done passing Rebecca around yet...
i'm trying to create a dynamic gallery with infinite scroll with infinity.js . The plugin load the first 12 items but when i scroll, it can't attach the rest of the items or attach them in strange way.
For now i'm not working with a database.
my php code:
<div id="product-list">
<div class="row">
Okay guys. I'm beginning to take everyone's silence on this as indifference. I will assume indifference as approval. I have some time tomorrow that I'd like to put to good use, so let me know.
I recently created the coordinate-system tag and created a wiki for it. It made sense and I feel like it's a good tag. What I didn't realize is how many questions could potentially be tagged with it. I created a search for it and discovered that there are over 200 candidate questions. While I cou...
Finally, Parameterised Constructors are possible in VBA.
Background:
One rainy day, I came up with an idea: take a static class and expose one property as default (like it was done in the Reverse for each loop for the .Item() property. This time however, I thought I'll make a PieceOfMe() Get Pr...
Finally, Parameterised Constructors are possible in VBA.
Background:
One rainy day, I came up with an idea: take a static class and expose one property as default (like it was done in the Reverse for each loop for the .Item() property. This time however, I thought I'll make a PieceOfMe() Get Pr...
I am creating pac man for a project, but i've ran into trouble moving around my character. Specifically implementing wall collision, I can move the character fine just not when I try to put in wall collision... Clearly I am doing something wrong
When I try to move around i cant, it detects the a...
The code isn't completed, just part written. I clarified that I was not understanding three specific methods, with one method I was unsure about...what else am I suppose to do? — TheCrownedPixel28 mins ago
So the goal for this project was to:
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
Write a program that continues to asks the user to enter any number other than 5 until the user e...
Computed 1100771 values with 0 sumdiff and -40.541% Base 7.397ms -> Fast 4.398ms
Computed 1100771 values with 0 sumdiff and -25.040% Base 7.586ms -> Pimgd 5.686ms
Computed 1100771 values with 0 sumdiff and -39.255% Base 7.377ms -> Fast 4.481ms
Computed 1100771 values with 0 sumdiff and -22.482% Base 7.553ms -> Pimgd 5.855ms
Computed 1100771 values with 0 sumdiff and -42.716% Base 7.692ms -> Fast 4.406ms
Computed 1100771 values with 0 sumdiff and -25.785% Base 7.713ms -> Pimgd 5.724ms
Computed 1100771 values with 0 sumdiff and -41.751% Base 8.221ms -> Fast 4.789ms
Computed 1100771 values with 0 sumdiff and -44.548% Base 7.672ms -> Fast 4.254ms
Computed 1100771 values with 0 sumdiff and -29.363% Base 7.665ms -> Pimgd 5.414ms
Computed 1100771 values with 0 sumdiff and -44.019% Base 7.674ms -> Fast 4.296ms
Computed 1100771 values with 0 sumdiff and -29.589% Base 7.688ms -> Pimgd 5.413ms
Computed 1100771 values with 0 sumdiff and -44.271% Base 7.695ms -> Fast 4.288ms
Computed 1100771 values with 0 sumdiff and -28.862% Base 7.725ms -> Pimgd 5.495ms
Computed 1100771 values with 0 sumdiff and -38.031% Base 7.656ms -> Fast 4.744ms
Significantly..... faster.
mind you, so are your times this time... hmmm something odd.
>>> is also a right shift, but it always rotates a 0 in to the high bit.
I have the following wx.Window:
class SketchWindow(wx.Window):
def __init__(self, parent):
wx.Window.__init__(self, parent, -1)
self.SetBackgroundColour('White')
# Window event binding
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_IDLE, self.OnIdle)
# run
...
Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the compiler will generate an error when it can't guarantee the alignment or at least give a warning.
To solve these errors and warnings I'm...
I made this question which later I recognized the mistakes but wasn't allowed to change them because of a weird policy: Increment a text field value
the mistakes are I used the wrong selector and the answer wrongly based on that wrong selector too. now does this make sense for you? sense for the...
While solving a problem from Hacker rank though easy one, i wrote this big program. Not sure if recursion is applicable and hold good but to me it looked like it doesn't. However when i run the program i see my code executed fairly well. Here is problem statement:
Print the largest decent number...
I've implemented a dummy class that implements IDisposable.
public class Toilet : IDisposable
{
object mutex = new object();
byte[] waste = new byte[10000000];
~Toilet()
{
Dispose();
}
public void Dispose()
{
lock(mutex){
Console.Write...
@Jamal well, if you moderators made him understand why it is the way it is in another way, then I agree that it's not needed anymore. If you didn't however, I think it will be seen by the OP as "censoring" / "moderator-policing" which is definitely not what we want.
In my previous Watir question I was making a module with session_FF accepting a block.
Now I want to make the same but via RSpec. Here is my try:
require "rspec"
require "watir"
module Session_FF
def method_missing m, *args, &block
@browser.send m, *args, &block
end
def element *args
...
I have this Image class that I've been using for some time now on personal
projects and games I eventually write. It was written in C++98 style and it
is now starting to show its age. Over time, I added a few C++11 elements here and there,
but I think it is now time for a major refactoring. Follo...
@bazola managed to understand quite a bit about how I have created the server simply by going through the code and adding some documentation to it, I'm sure you'll be able to understand it as well @Marc-Andre.
We currently have two .NET interface tags (as far as I can see):
ienumerable (8 questions)
idisposable (1 question)
They are both language-specific and seem to relate to more general things. The former is about enumeration and the latter is about resource-management. We do seem to have tags...
I've got a slight problem with my program.
Simply put, what I do is this:
1. Choose the option to "Add a new Student record".
2. When I try to display the newly added values (First Name, Last Name, Course), it all comes back as null.
I can't wrap my head around what's wrong, but I'll try to post...
I've got a slight problem with my program. Simply put, what I do is this:
Choose the option to "Add a new Student record".
When I try to display the newly added values (First Name, Last Name, Course), it all comes back as null.
I can't wrap my head around what's wrong, but I'll try to post th...
@Phrancis I've played enough to know I'm not good at remembering and planning things in advance! I'm better with reflexes and executing rotations ! But I like playing gmaes like TGC HS and RTS because it make a good change !
Can this method be improved?:
public static Session getHibernateSession() throws SQLException{
synchronized(dbSessionMutex){
if(session == null || !session.isOpen()){
session = HibernateUtil.getSessionFactory().openSession();
}
else{
final Sess...
The power of the aggregation framework is it's ability to iterate over the dataset in various useful ways without incurring extra round trips between the database and the app.
Your code uses one stage for aggregation (grouping by id1), and then jumps out of aggregation to iterate over the entire...
I have several buttons and I want to toggle between them like radio buttons.
The way I have it set up now is that each button have this same code but the buttonValue varies depending on which button they click on.
Here's a snippet of my code:
ToggleButton one;
one = (ToggleButton) view.fin...
Speed optimization tools ask that all image sizes be specified, to speed up rendering.
I have an image that's called through JavaScript, it's an SSL logo that MUST be served through JS, otherwise it won't pass verification.
What is the correct syntax to add the image dimensions (width="100" hei...
I have an SSIS package for SQL Server 2008. In this package, I need to verify that a file exists. If the file does not exist, I need to fail the package before using the built in "For each file loop" task.
It's a pretty simple bit of code, but it has a huge smell. I'm catching Exception. I think...
I'd like to change the word substr to "left":
String.prototype.left = function(n) {
return this.substr(0,n)
}
Is this ok, or should I just get over it?
Next, I'm going to write a .right(), a .mid(), a .val() and a .int()
Project Euler Problem 27
I used Sieve of Eratosthenes for finding primes. I also used a HashSet for fast searching.
My Implementation:
static void Main()
{
HashSet<int> primes = Primes(10000000);
Func<int,int,int,int> f = (a,b,n) => n * n + a * n + b;
int maxCount = int.MinValue...
@janos I am often hesitant to posting more than one answer per question, but I felt that in this case it might be better with two. I just merged my two answers though.
If you're going to demand a comment from a downvoter, at least hear them out first instead of just saying that they're wrong and then lashing out. If someone stops commenting on their downvotes because of this reason, well, tough luck.
@Malachi - not sure which message you mean, but you can never star your own messages. As an owner, or mod, you can pin any message, including your own, and that does count as a star too. So, for example, I can pin, but not star this, and the first star will make it +2
2
But, that's a crappy message to pin, so depinning now.
I've made a simple program that moves the mouse and do other silly stuff ;) I want you to look at it and tell me what can I do better/less space and also what can I add? I want to prank my friends ^^ This is what I've done so far:
#include <cstdio>
#include <windows.h>
#include <conio.h>
#include <