Although used within the WordPress platform, this is PHP focussed question.
I have an array of child posts, some have content, some don't. My client wishes to display the posts in alphabetical order, but posts without content are to be positioned at the end (still in A-Z order).
My solution is ...
Classic | Minion | Common | Neutral | Tresting Bacther | 6 | 3 | 4 | <b>Battlecry:</b> If you have a <b>Secret</b> you have a minion with <b>Windfury</b>.
Classic | Spell | Rare | Priest | Cobrlaf of the Meal | 1 | Destroy a minion. If you have a Deal, damage the ALLLohthard chatact ans damage the Attack of your weapon
I have written a program to solve Sudoku puzzles as a (fun?) way to learn Python. It solves puzzles as a human would, using reasoning algorithms rather than brute force/backtracking, as I thought it would a more interesting challenge that way.
I really looking for any feedback on how to reduce i...
I've created a simplified prototype solution as a sort of proof of concept before starting a larger program.
Here is the test data used to build the objects:
create table blah.dbo.tb_sandpitCreateMultipleLinkedObjects
(
CustomerName varchar(50),
ItemCode varchar(50)
);
insert into blah...
Code can be found on Github.
Some coworkers and I sometimes want to delete folders, only to get the very informative: Permission Denied message. I had discovered Handle.exe and Process Explorer to help with this, but the method was still too manual and cumbersome.
Thus, I decided to write thi...
I've just started a self-learning "course" on Python practical programming for beginners. I found this book online, and decided to go through the chapters.
The book had a half-complete implementation of a Tic-Tac-Toe game, and I was supposed to finish it as an exercise. This is my code so far: ...
@Hosch250 It's not worthy of a bounty IMO, but those few advices you have there might be good. I also thought "Based on it being the only return in the function, it almost looks like a signal of success"
<script>
function CalculateProratedRefund() {
"use strict";
var input= document.getElementsByName("input");
// get initial values from HTMLCollection
var purchaseDate = new Date(input[0].value);
var purchasePrice = input[1].value;
var termInYears = input[2].value;
var cancelDate = new Date(input[3].value);
var amtPaidInClaims = input[4].value;
var gracePeriodInDays = input[5].value;
purchasePrice = (purchasePrice).toFixed(2);
amtPaidInClaims = (amtPaidInClaims).toFixed(2);
Then I have this, what seems to me the exact same operation:
When I try to run it (IE11) the script just stops there
document.getElementsByName("input") searches for elements that match <sometag name="input" ...> while document.getElementsByTagName("input") searches for elements that matches <input>
I am using a foreach loop to sort an associative array alphabetically. I would like to know if there is a more proper and/or efficient way of doing it.
The array:
Array
(
[gr_c] => Array
(
[f] => 'value...'
[a] => 'value...'
[d] => 'value...'
...
I'm not really a C/C++ guy anymore, but I know you can't even use values for pre-processor directives in C#. I.e. #define LUA_DEBUG = 1 is invalid. In fact, in C#, pre-processor directives are either defined, or not. They don't even have falues.
@janos Yeah, my language tends to get confusing sometimes, good clarification though! I'll go back through and double-check again to make sure I didn't inadvertently say anything else I didn't mean.
@EBrown when you talk about "inlined-parameters", maybe "inlined default values" is a better term? And to put it simply, the single biggest problem there is the extremely long line, for several reasons: 1. part of the code is hidden, even on wider screens: that's prone to errors, because you cannot detect bugs you cannot see; 2. it's best when code flows from top to bottom, with no distractions sideways. I think these are very clear statements that make rock solid points (feel free to borrow!)
@janos Including that in part of my new edit, I'll show you the language I already had: "These two long lines in this constructor: ...code... Are very hard to read, though not on purpose. All those inlined-parameters tend to make it hard to read. (You can't even tell how many there are without going on some deep comma-searching.) Cleaning that up makes it far clearer to follow in the future. Even a small change such as the following helps:"
I'm not really in it for the bounty, any chance I can get someone to tell me what I am doing right/wrong about my reviewing style is much appreciated. :)
@janos Part of the language for indenting: "Generally, when working in languages like the C/C99/C++/C# languages, Python, PHP, Perl, Visual Basic, etc., we assume each line is a statement. (Or no more than a couple.) When many statements are combined on a single line, we start to make mistakes and our assumptions can lead us astray."
Is there anything wrong with the following implementation of an in-memory top-ten bought products tracker?
public class Main {
private static List<Integer> topTenItems = Collections.synchronizedList(new ArrayList<Integer>(Collections.nCopies(10, 0)));
private static List<Integer> topTenScores =...
This meme has been retired by community decision on Nov 25 2014. It is thus considered a veteran meme. Usages may still occur, but the meme has largely vanished from our site.
Meme: We could really use your ammo
Originator: syb0rg
Cultural Height: Side-effects of The Mission?
Related: ou...
@EBrown it's widely accepted that braces are recommended even on single-line if/for/etc statements, and usually this famous bug is used to demonstrate what can go wrong
I occasionally see legacy code in real life like this:
And I completely understand, I used to never omit braces until I started working on a specific project, and it makes sense to me in situations where it won't be a problem like that. I don't often do it, but when I do it's responsibly.
I have had a real-life situation before where a sequence of bad edits (including auto-formats, and UNIX/DOS line end fixes, human bug fixing, and whitespace-cleaning), resulted in code like:
if (condition)
statement1; statement2
because the call-path to get to that entire code block was uncommon, we did not even see the broken behaviour for years.
@EBrown when I see code without braces, it's a legitimate suggestion to use braces always, for safety reason. Suggesting to remove braces from code that has it, is outright dangerous
I have written the following utility, as my first non-tutorial program in Go.
The purpose of the utility is
to connect to a torque/force sensor (aka load-cell) via UDP;
to send an initialization command; and
to record the resulting stream of measurements.
Since I am planning further function...
For a little toy project of mine I need to have data available in a certain format in order to be able to feed into a Recurrent Neural Network (Long short term memory), it uses HearthStone card data that is available in JSON format.
Example input:
{
"id":"EX1_306",
"name":"S...
Perfect Hash Families (PHFs) are a widely studied combinatorial object. Essentially, they are 4-tuples (N; t, k, v), where the PHF is an N by k array of v symbols. For any t columns chosen, there is at least one row of those chosen columns that has no symbol duplicated in that row.
I want to be ...
Problem: Using current cryptography tools provided in the .NET framework results in ciphertext [containing sensitive information] decrypting to String or Byte array objects in memory in their entirety. There does not appear to presently exist a process for decrypting ciphertext into a SecureStrin...
For a little toy project of mine I need to have data available in a certain format in order to be able to feed into a Recurrent Neural Network (Long short term memory), it uses HearthStone card data that is available in JSON format.
Example input:
{
"id":"EX1_306",
"name":"S...
I execute javascript from a website that opens another page and executes javascript.
If this is possible, please help.
If this isn't possible, please let me know.
I realize this is a really old question, but for future reference you would probably have better luck with a question like this over on Code Review. — CBRF2320 secs ago
I execute JavaScript from a website that opens another page and executes JavaScript:
$('#ctl00_button', "www.example.com/").click();
Is this right? If not, can you post the correct way?
<form>
<label>Purchase Date: <input type="text" id="purchaseDate"></label><br/>
<!-- and later in JS -->
var purchaseDate = new Date(document.getElementById("purchaseDate"));
// does not pass my valid date test...
My implementation of two shortest single source paths, Bellman-Ford and Dijkstra, are below. All comments welcome.
I did not implement a priority queue in Dijkstra, not sure it a trivial priority queue is the best choice, since, after each iteration, several elements change their value, maybe it...
<form>
<label>Purchase Date: <input type="text" id="purchaseDate"></label><br/>
<!-- and later in JS -->
var purchaseDate = new Date(document.getElementById("purchaseDate"));
// does not pass my valid date test...
<script type="text/javascript">
function CalculateProratedRefund() {
"use strict";
var purchaseDate = new Date(document.getElementById("purchaseDate").value);
var purchasePrice = parseFloat(document.getElementById("purchasePrice").value).toFixed(2);
var termInYears = parseInt(document.getElementById("termInYears").value);
var cancelDate = new Date(document.getElementById("cancelDate").value);
var amtPaidInClaims = parseFloat(document.getElementById("amtPaidInClaims").value).toFixed(2);