Questions

Can anyone explain this strange behavior with signed floats in C#?

Here is the example with comments: ``` class Program { // first version of structure public struct D1 { public double d; public int f; } // during some changes in...

11 Nov at 23:9

Is it possible to remove inline styles with jQuery?

A jQuery plugin is applying an inline style (`display:block`). I'm feeling lazy and want to override it with `display:none`. What's the best (lazy) way?

27 Jul at 19:10

How do I apply the for-each loop to every character in a String?

So I want to iterate for each character in a string. So I thought: ``` for (char c : "xyz") ``` but I get a compiler error: ``` MyClass.java:20: foreach not applicable to expression type ``` Ho...

23 Feb at 22:49

Remove multiple whitespaces

I'm getting `$row['message']` from a MySQL database and I need to remove all whitespace like `\n` `\t` and so on. ``` $row['message'] = "This is a Text \n and so on \t Text text."; ``` should...

How to get a list of properties with a given attribute?

I have a type, `t`, and I would like to get a list of the public properties that have the attribute `MyAttribute`. The attribute is marked with `AllowMultiple = false`, like this: ``` [AttributeUsage...

6 Jun at 07:41

Exception.Message vs Exception.ToString()

I have code that is logging `Exception.Message`. However, I read an article which states that it's better to use `Exception.ToString()`. With the latter, you retain more crucial information about the ...

10 Sep at 01:55

Cannot refer to a non-final variable inside an inner class defined in a different method

Edited: I need to change the values of several variables as they run several times thorugh a timer. I need to keep updating the values with every iteration through the timer. I cannot set the values t...

20 Jun at 09:12

Mod of negative number is melting my brain

I'm trying to mod an integer to get an array position so that it will loop round. Doing `i % arrayLength` works fine for positive numbers but for negative numbers it all goes wrong. ``` 4 % 3 == 1 3...

7 May at 14:52

Find the last element of an array while using a foreach loop in PHP

I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element of an array from inside the for loop by just checking the current array position with the arr...

8 Jun at 05:14

round() for float in C++

I need a simple floating point rounding function, thus: ``` double round(double); round(0.1) = 0 round(-0.1) = 0 round(-0.9) = -1 ``` I can find `ceil()` and `floor()` in the math.h - but not `ro...

16 Mar at 01:55

List files recursively in Linux CLI with path relative to the current directory

This is similar to [this question](https://stackoverflow.com/questions/105212/linux-recursively-list-all-files-in-a-directory-including-files-in-symlink-dire), but I want to include the path relative ...

23 May at 11:47

Multiple Inheritance in C#

Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. For instance I'm able to i...

20 Jun at 09:12

How can I use xargs to copy files that have spaces and quotes in their names?

I'm trying to copy a bunch of files below a directory and a number of the files have spaces and single-quotes in their names. When I try to string together `find` and `grep` with `xargs`, I get the f...

29 Jul at 20:28

How do you compare structs for equality in C?

How do you compare two instances of structs for equality in standard C?

26 Sep at 20:21

When to use record vs class vs struct

- Should I be using `Record` for all of my DTO classes that move data between controller and service layer?- Should I be using `Record` for all my request bindings since ideally I would want the reque...

2 Jan at 02:43

Locating data volumes in Docker Desktop (Windows)

I'm trying to learn docker at the moment and I'm getting confused about where data volumes actually exist. I'm using . (Windows 10) In the docs they say that running docker inspect on the object wil...

Moment js get first and last day of current month

How do I get the first and last day and time of the current month in the following format in moment.js: > 2016-09-01 00:00 I can get the current date and time like this: `moment().format('YYYY-MM-DD...

23 May at 12:3

How to format LocalDate to string?

I have a `LocalDate` variable called `date`, when I print it displays 1988-05-05 I need to convert this to be printed as 05.May 1988. How to do this?

29 Oct at 18:26

Ternary operator is twice as slow as an if-else block?

I read everywhere that ternary operator is supposed to be faster than, or at least the same as, its equivalent `if`-`else` block. However, I did the following test and found out it's not the case: `...

14 Oct at 20:20

Select Last Row in the Table

I would like to retrieve the last file inserted into my table. I know that the method `first()` exists and provides you with the first file in the table but I don't know how to get the last insert.

21 Nov at 13:39

Rounding BigDecimal to *always* have two decimal places

I'm trying to round BigDecimal values up, to two decimal places. I'm using ``` BigDecimal rounded = value.round(new MathContext(2, RoundingMode.CEILING)); logger.trace("rounded {} to {}", value, rou...

26 Dec at 14:43

Error "Uncaught SyntaxError: Unexpected token with JSON.parse"

What causes this error on the third line? ``` var products = [{ "name": "Pizza", "price": "10", "quantity": "7" }, { "name": "Cerveja", "price": "12", "quantity": "5" }, { "name": "Hambu...

8 Aug at 18:20

Java: Getting a substring from a string starting after a particular character

I have a string: ``` /abc/def/ghfj.doc ``` I would like to extract `ghfj.doc` from this, i.e. the substring after the last `/`, or first `/` from right. Could someone please provide some help?

19 Jul at 19:55

Why is processing a sorted array slower than an unsorted array?

I have a list of 500000 randomly generated `Tuple<long,long,string>` objects on which I am performing a simple "between" search: ``` var data = new List<Tuple<long,long,string>>(500000); ... var cnt ...

Why does typeof array with objects return "object" and not "array"?

> [JavaScript: Check if object is array?](https://stackoverflow.com/questions/4775722/javascript-check-if-object-is-array) Why is an array of objects considered an object, and not an array? Fo...

19 Apr at 17:51