Questions

How to access a dictionary element in a Django template?

I would like to print out the number of votes that each choice got. I have this code in a template: ``` {% for choice in choices %} {{choice.choice}} - {{votes[choice.id]}} <br /> {% endfor %} `...

21 Apr at 18:49

SQL Logic Operator Precedence: And and Or

Are the two statements below equivalent? ``` SELECT [...] FROM [...] WHERE some_col in (1,2,3,4,5) AND some_other_expr ``` and ``` SELECT [...] FROM [...] WHERE some_col in (1,2,3) or some_col in ...

Custom numeric format string to always display the sign

Is there any way I can specify a standard or custom numeric format string to always output the sign, be it +ve or -ve (although what it should do for zero, I'm not sure!)

12 Mar at 08:4

How to get a variable name as a string in PHP?

Say i have this PHP code: ``` $FooBar = "a string"; ``` i then need a function like this: ``` print_var_name($FooBar); ``` which prints: ``` FooBar ``` Any Ideas how to achieve this? Is this ...

1 Nov at 00:28

Convert char to int in C#

I have a char in c#: ``` char foo = '2'; ``` Now I want to get the 2 into an int. I find that Convert.ToInt32 returns the actual decimal value of the char and not the number 2. The following will...

21 Jul at 17:11

Why does C# not provide the C++ style 'friend' keyword?

The [C++ friend keyword](http://www.cplusplus.com/doc/tutorial/inheritance/) allows a `class A` to designate `class B` as its friend. This allows `Class B` to access the `private`/`protected` members...

23 May at 11:47

How do you do relative time in Rails?

I'm writing a Rails application, but can't seem to find how to do relative time, i.e. if given a certain Time class, it can calculate "30 seconds ago" or "2 days ago" or if it's longer than a month "9...

15 Oct at 15:54

Embedding JavaScript engine into .NET

just wondering if anyone has ever tried embedding and actually integrating any js engine into the .net environment. I could find and actually use (after a of pain and effort, since it's pretty outdat...

12 Mar at 18:19

Java Delegates?

Does the Java language have delegate features, similar to how C# has support for delegates?

4 Sep at 22:45

Running actions in another directory

I've just started exploring Github actions however I've found myself placing a command in multiple places. I have a PHP project where the `composer.json` is not in the root, my structure looks like:...

28 Sep at 10:29

VSCode single to double quote automatic replace

When I execute a `Format Document` command on a Vue Component.vue file VSCode replace all single quoted string with double quoted string. In my specific case this rule conflicts with electron-vue lin...

27 May at 06:39

How to convert FormData (HTML5 object) to JSON

How do I convert the entries from a HTML5 `FormData` object to JSON? The solution should not use jQuery. Also, it should not simply serialize the entire `FormData` object, but only its key/value entri...

31 Dec at 13:36

How can I remove duplicate lines in Visual Studio Code?

Say you have the following text: ``` abc 123 abc 456 789 abc abc ``` I want to remove all "abc" lines and just keep one. I don't mind sorting. The result should be like this: ``` abc 123 456 789 `...

9 Jun at 12:25

PostgreSQL INSERT ON CONFLICT UPDATE (upsert) use all excluded values

When you are upserting a row (PostgreSQL >= 9.5), and you want the possible INSERT to be exactly the same as the possible UPDATE, you can write it like this: ``` INSERT INTO tablename (id, username, ...

10 Nov at 16:25

How to send push notification to web browser?

I have been reading for past few hours about [Push Notification API](http://www.w3.org/TR/push-api/) and [Web Notification API](http://www.w3.org/TR/notifications/). I also discovered that Google & Ap...

Convert row names into first column

I have a data frame like this: ``` df VALUE ABS_CALL DETECTION P-VALUE 1007_s_at "957.729231881542" "P" "0.00486279317241156" 1053_at "320.632701283368"...

1 May at 06:9

How to replace text in a string column of a Pandas dataframe?

I have a column in my dataframe like this: ``` range "(2,30)" "(50,290)" "(400,1000)" ... ``` and I want to replace the `,` comma with `-` dash. I'm currently using this method but nothing is changed...

21 Dec at 22:11

Implementing Singleton with an Enum (in Java)

I have read that it is possible to implement `Singleton` in Java using an `Enum` such as: ``` public enum MySingleton { INSTANCE; } ``` But, how does the above work? Specifically, an `Objec...

26 Dec at 03:18

Upgrade python packages from requirements.txt using pip command

How do I upgrade all my python packages from requirements.txt file using pip command? tried with below command ``` $ pip install --upgrade -r requirements.txt ``` Since, the python packages are su...

16 Apr at 15:16

Nested rows with bootstrap grid system?

I want 1 larger image with 4 smaller images in a 2x2 format like this: ![Figure 1 Example](https://i.stack.imgur.com/tdxuMm.png) My initial thought was to house everything in one row. Then create t...

How can I parse a local JSON file from assets folder into a ListView?

I'm currently developing a physics app that is supposed to show a list of formulas and even solve some of them (the only problem is the `ListView`) ``` <?xml version="1.0" encoding="utf-8"?> <LinearL...

Run ssh and immediately execute command

I'm trying to find UNIX or bash command to run a command after connecting to an ssh server. For example: ``` ssh name@ip "tmux list-sessions" ``` The above code works, it lists the sessions, but i...

1 Sep at 08:39

Delete files older than 15 days using PowerShell

I would like to delete only the files that were created more than 15 days ago in a particular folder. How could I do this using PowerShell?

AngularJS toggle class using ng-class

I am trying to toggle the class of an element using `ng-class` ``` <button class="btn"> <i ng-class="{(isAutoScroll()) ? 'icon-autoscroll' : 'icon-autoscroll-disabled'}"></i> </button> ``` isAuto...

3 Oct at 16:37

How to read a text file into a list or an array with Python

I am trying to read the lines of a text file into a list or array in python. I just need to be able to individually access any item in the list or array after it is created. The text file is formatt...

21 Jun at 19:19