/*=====================================Next=====================================
**Returns: An int [0..maxValue)
**Arguments: maxValue -- One more than the greatest legal return value.
**Exceptions: None.
==============================================================================*/
public virtual int Next(int maxValue) {
if (maxValue<0) {
throw new ArgumentOutOfRangeException("maxValue", Environment.GetResourceString("ArgumentOutOfRange_MustBePositive", "maxValue"));
Grand Central Dispatch (GCD) provides a simple and robust mechanism for concurrent and asynchronous operations in iOS, Mac OS X, and FreeBSD. ... "simple"... I'm not completely certain...
Do you like Shakespeare? If so, how about "A rose by any other name would smell as sweet", or, shorter these days, "A rose is a rose is a rose."
If you're not a big fan of the Bard, consider "If it walks like a duck and quacks like a duck ...".
If my superview is a box measuring 10 units on each side, and my subview is 20 units wide, with clipsToBounds set to YES, I'll only see the part of the subview that fits within the bounds of the superview. Otherwise, if clipsToBounds is set to NO, I'll see the entire subview, even the parts outs...
And now it has 7 upvotes... and it feels like they were all very spaced out.
I just upvoted it. I never thought it was that great of a question... but apparently, my answer is one of the very few clear explanations of clipsToBounds on the Internet, so apparently the question is better than I originally thought.
But the really question is... if you're updating the data faster than you can update the UI, is the data actually updating? (If a tree falls in the woods, etc...) So to me, seems the real solution might be to slow down the data updates... — nhgrif42 secs ago
> The SQL Server Database Engine optimizes storage of bit columns. If there are 8 or less bit columns in a table, the columns are stored as 1 byte. If there are from 9 up to 16 bit columns, the columns are stored as 2 bytes, and so on.
@Mat'sMug "The fact that a BIT value is NULL must be stored separately from the bit value itself, since the bit values can be compressed so that 8 BIT values are stored in a byte." stackoverflow.com/a/14702211/1220238
The equivalent is a bit field.
In SQL you use 0 and 1 to set a bit field (just as a yes/no field in Access). In Management Studio it displays as a false/true value (at least in recent versions).
When accessing the database through ASP.NET it will expose the field as a boolean value.
still I learned something today, and it's good to know.. I guess. Like, when you have a table with 1 bit field and a couple of million rows.. you could add another 7 bit fields without weighting a single additional bit.
And SQL does offer bitwise operations (&, |, and ^ anyway)
So, presuming that if(someBitMask) is faster an equivalent number of chained bools, it still may be worthwhile to favor a tinyint field over 8 bit fields even though storage space would be the same.
I'm not just what would be the best way to refactor your code, but I still have some tips for you. I'll take parts of your code and show you how I would have done using a before/after approach:
Snippet 1
Before
magazine.turn({
width: MGZ_WIDTH,
height: MGZ_HEIG...
I have to make a function to return a string representation of an integer that is passed as an argument. If the argument is 5, the function should return "5". Anyone has an idea on how to get started with this?
Introduction
Valve recently launched the Dota 2 Workshop Tools, which allows players to create their own maps with custom gamemodes, similar to Warcraft 3 in capabilities.
Ability and unit definitions are stored in txt files under a specific format, very similar to JSON:
{
"key" "value"
...
I know, but does this guy even Internet? How do you go to StackOverflow and click Ask a Question before doing any searches at all?
You know what I just realized?
39.3 million results in half a second.
The Internet is uh-may-zing.
I think this is how I should approach StackOverflow for the next few weeks. When I see a bad question, I'm going to spend 2 seconds to think up how I'd Google that, then Google it with those obvious search terms. If the top result answers the question, they're getting a screenshot like this.
The problem is your last cout should be inside the else block:
cout << "quotient is";
if (b == 0) {
cout << " undefined";
} else {
quot = a/b;
cout << ": " << quot;
}
cout << endl;
As written, your "quotient is: " << quot is executing in every case, but you actually only want it to...
Preamble: the default frame positioning with Swing JFrames has always bothered me. Eventually I wrote some code to calculate my available desktop space, not counting my abnormally-large right-side-anchored taskbar, and use that information to size and position my JFrames. Then I got sick of copy/...
I implemented the following (what I believe to be) safe Reverse Polish Calculator.
Now I'm using foldM to take advantage of the power of Monads. Previously, I was not.
Can you please critique my code?
import Data.Maybe
import Text.Regex
import Control.Monad
import Network.CGI.Protocol
data Op...
I'm just getting into Clojure, and I wanted to make sure I am writing code the "Clojure way". The challenge I took on is Zeckendorf numbers (fairly trivial). Here's my code:
(defn fibs-until
([n]
(vec (if (< n 3)
(range 1 (inc n))
(concat [1 2] (fibs-until n 1 2)))))
([n a b]...
I am implementing a mutable trie. You can find below the full working code. I tested and it produces correct results. However, it is very slow. I benchmark it against plain old Data.Map and Data.Map is more than twice faster. Full source: https://github.com/seri/toys.hs/tree/master/SpellChecker/s...
this question is about an improvement of the code from this previous question.
It is a constructor function that attaches a click event to radio inputs using event delegation in order to add and remove css classes to the text input which contains a data-value equals to the radio value.
Short e...
Problem statement:
Calvin is driving his favorite vehicle on the 101 freeway. He notices that the check engine light of his vehicle is on, and he wants to service it immediately to avoid any risks. Luckily, a service lane runs parallel to the highway. The length of the highway and the service...
Problem Statement:
Manasa is out on a hike with friends. She finds a trail of stones with numbers on them. She starts following the trail and notices that two consecutive stones have a difference of either a or b. Legend has it that there is a treasure trove at the end of the trail and if Man...
I have a vector with 10000 particles that I use in a Particle Filter. The problem is it's taking too long to compute the weighted selection of the particles. Is there anyway I can optimize this?
std::vector< double > probabilities;
probabilities.reserve(util::NUMBER_OF_PARTICLES);
std::vector< ...
I created a utility method ListUtils.partition(iterable, size) to partition a potentially large list to a list of smaller lists:
public class ListUtils {
public static <T> List<List<T>> partition(Iterable<T> iterable, int size) {
if (iterable == null) {
return Collections...
I am asked to restrict a button on a program. By using another restricted one, I added a few lines and restricted it. But one of lines was adding 0 for when we have nothing on the button. When we delete this code system gives #econverterror. I cant delete this but I cant delete this "0" neither. ...
Hello I have created this program and it works fine its just that its too wonky and huge so I was wondering if anyone knew how I could shorten the program so I didn't have to put all of these into each button
if(guess == number){
l1.setText("You have won the number was " + number);
}
if(guess >
i am new with coding and i recently read article about code refactoring so i have made a console application for booking rooms in ship i need help with code refactoring as far as i understand the refactoring i think in my project there are only 2 part where i need refactoring which are as follow ...
I'm trying to find best structure for managing lifecycle of my entities. Let's say we have classes Component, Parameter and ComponentParameter. Component and Parameter are separate entities, ComponentParameter is an association entity between them having overriden value of Parameter's value.
cla...
I'm aiming for the best (and simplest) way to access "global" variables set in the config file for the site. So I can use them anywhere (even inside functions)
It's for file versioning, and I use htaccess to rewrite urls
Right now, I'm at this:
// settings.php:
class VERS {
static $css = '...
i have written two methods in java that executes any type of hql and returns data. Methods are like
public static Query getHqlQueryObject(String hql) throws Exception{
Query query = null;
Session session = null;
try {
session = HibernateUtil.getSessionFactory...
I'd like to refactor my extractSimplePromptName so it does the same but it's "prettier", hence less code. As far as looking at it, it seems like it could be refactored so it does the same thing, but it's just less code. I'm just fairly new to programming so having a hard time seeing where i shoul...
I have a custom tableview cell for displaying different foods, with a star next to each name. If the food has been favorited (i.e., it exists in the database), the star is filled in, otherwise it is empty. I'm not sure if the logic that determines the color of the star should go in the view cont...
I posted this question on Stack Overflow and was advised that it is best suited to this site. I'm trying to convert a couple of simple CRC calculating functions from C to C#, but I seem to be getting incorrect results.
The C functions are:
#define CRC32_POLYNOMIAL 0xEDB88320
unsigned long CRC3...
https://github.com/andrewjwolf/payjunction-php
I ran into some issues with unit testing in that getting the response body etc from the curl handle was tricky. I didn't want to necessarily use a mock or abstract the curl functionality.
A colleague of mine suggested that I just use the localhost ...
I'd like to refactor my extractSimplePromptName test so it does the same but it's "prettier", hence less code. As far as looking at it, it seems like it could be refactored so it does the same thing, but it's just less code. I'm just fairly new to programming so having a hard time seeing where i ...
I have used the example in the following this question to lock my cache:
public static IEnumerable<Asset> Assets
{
get
{
List<Asset> assets = (List<Asset>)_cache["AssetList"];
if (assets == null)
{
// stop multiple calls to this
lock (_ass...
I'd like feedback on my function to convert FASTA data to a dictionary in python. Here's example FASTA text.
FASTA lines to be used as a key begin with '>'
FASTA lines to be used as a value follow the key line.
Repeat
Is this the best way to remove whitespace, tabs, newlines, etc? I suspect ...
I am trying to extend the JSON format (for private use) to include an include statement. This could be used to include other .json files into a master file, for example. Here is my current code:
#! /usr/bin/perl
use warnings;
use strict;
use File::Slurp 'read_file';
my $str=parseFile('t.json')...
I have some php code to style a button and activate it, when a specific variable is true.
It's actually a radio button, styled with the bootstrap to a button.
As you can see below, this is how it looks when the variable is '1'.
Also, the buttons at the bottom are the same, but then with one extra...
@Vogel612 Update it. Mine was borked too for a while but it's back on track again. Use the Greasemonkey script. I couldn't get the Firefox plugin to work.
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...
I've started to write a form data handler class in PHP. Can you please review it and point out any mistakes or logic errors, or perhaps if a method can be written in a better way.
Code is below. Thanks in advance for your efforts :)
define('VALIDATION_ERR', ' couldn`t be validated.');
define('R...
So I saw a post on a funny pictures site...
"In the word "Scent", is the S or the C silent?"
And I thought I could ask about it here.
In particular, how does the pronunciation of "scent" differ from "cent" and "sent"? Small audio references would help me in particular.
Today we're proposing a new feature to the Meta Stack Overflow community: Stack Snippets.
What do Stack Snippets do?
Stack Snippets make code blocks runnable. Here's an example:
alert("You can even do alerts");
.hello {
font-weight: bold;
font-size: 1.5em;
}
<div class="hello">Stack...
Post a meta question asking for the tool to be implemented on CR. We can all answer/vote for yes/no, and use that as evidence in a request to the SE devs.
@RubberDuck - 4 backslashes are actually 2 (two of them are escape sequences....)
On this site (code-review), the best questions sometimes contain the worst possible code. I'm not the only one who noticed this. On any other code-related SE site, questions with code that causes puppies to cry, and babies to cringe, down-voting is a good way of notifying other users to "not both...
public class Authenticator : IAuthenticator
{
public bool Authenticated
{
get { return HttpContext.Current.User.Identity.IsAuthenticated; }
}
public bool Authenticate(string username, string password)
{
var authenticated = FormsAuthentication.Authenticate(user...
Just wondering if there was someone out there that could offer help in optimizing my script.
<?php
/**
* If you don't understand what this does
* you have no hope as a programmer.
*
*/
function usage ( )
{
// Ahhh the marvels of echo, such a wonderful tool
// yet so advanced that a begin...
In addition to Pimgd's remarks I want to throw in:
Program against high Interfaces, not low ones:
Currently your methods all take a List<? extends T>. That in itself is quite nice already. Now a traversal of existing elements does not necessarily have to be done on an ordered Collection only.
...