Questions

How can I force division to be floating point? Division keeps rounding down to 0?

I have two integer values `a` and `b`, but I need their ratio in floating point. I know that `a < b` and I want to calculate `a / b`, so if I use integer division I'll always get 0 with a remainder o...

IndentationError: unindent does not match any outer indentation level

When I compile the Python code below, I get > IndentationError: unindent does not match any outer indentation level --- ``` import sys def Factorial(n): # Return factorial result = 1 for i...

26 Nov at 22:35

Which exception should I raise on bad/illegal argument combinations in Python?

I was wondering about the best practices for indicating invalid argument combinations in Python. I've come across a few situations where you have a function like so: ``` def import_to_orm(name, save=...

2 Nov at 19:26

RGB to hex and hex to RGB

How to convert colors in RGB format to hex format and vice versa? For example, convert `'#0080C0'` to `(0, 128, 192)`.

14 Aug at 11:25

TypeError: 'module' object is not callable

``` File "C:\Users\Administrator\Documents\Mibot\oops\blinkserv.py", line 82, in __init__ self.serv = socket(AF_INET,SOCK_STREAM) TypeError: 'module' object is not callable ``` Why am I getting t...

How do I preview stash contents in Git?

I want to inspect a stash and find out what changes it would make if I applied it to working tree in its current state. I know I can do a git diff on the stash, but this shows me all the differences b...

25 Jul at 04:59

How to find out if an item is present in a std::vector?

All I want to do is to check whether an element exists in the vector or not, so I can deal with each case. ``` if ( item_present ) do_this(); else do_that(); ```

2 Nov at 20:43

Regular expression for alphanumeric and underscores

Is there a regular expression which checks if a string contains only upper and lowercase letters, numbers, and underscores?

17 Oct at 19:47

Remove ALL white spaces from text

``` $("#topNav" + $("#breadCrumb2nd").text().replace(" ", "")).addClass("current"); ``` This is a snippet from my code. I want to add a class to an ID after getting another ID's text property. The p...

15 Dec at 19:54

How to remove spaces from a string using JavaScript?

How to remove spaces in a string? For instance: ``` '/var/www/site/Brand new document.docx' ``` ``` '/var/www/site/Brandnewdocument.docx' ```

19 May at 03:40

What killed my process and why?

My application runs as a background process on Linux. It is currently started at the command line in a Terminal window. Recently a user was executing the application for a while and it died mysteriou...

7 Jul at 08:26

Python int to binary string?

Are there any canned Python methods to convert an Integer (or Long) into a binary string in Python? There are a myriad of dec2bin() functions out on Google... But I was hoping I could use a built-in ...

13 Feb at 02:15

What is the difference between GitHub and gist?

What is the purpose of gist and how is it different from regular code sharing/maintaining using GitHub? [](https://i.stack.imgur.com/gTtGt.png)

10 Nov at 13:52

Delete first character of string if it is 0

I want to delete the first character of a string, if the first character is a 0. The 0 can be there more than once. Is there a simple function that checks the first character and deletes it if it is...

9 Apr at 14:44

How to read all files in a folder from Java?

How to read all the files in a folder through Java? It doesn't matter which API.

1 Mar at 22:14

How do you handle multiple submit buttons in ASP.NET MVC Framework?

Is there some easy way to handle multiple submit buttons from the same form? For example: ``` <% Html.BeginForm("MyAction", "MyController", FormMethod.Post); %> <input type="submit" value="Send" /> <...

How to fix a locale setting warning from Perl

When I run `perl`, I get the warning: How do I fix it?

4 Dec at 18:12

How to define hash tables in Bash?

What is the equivalent of [Python dictionaries](https://docs.python.org/2/tutorial/datastructures.html#dictionaries) but in Bash (should work across OS X and Linux).

What is a stack trace, and how can I use it to debug my application errors?

Sometimes when I run my application it gives me an error that looks like: ``` Exception in thread "main" java.lang.NullPointerException at com.example.myproject.Book.getTitle(Book.java:16) ...

22 Mar at 16:16

IntelliJ: Never use wildcard imports

Is there a way to tell IntelliJ never to use wildcard imports? Under 'Settings > Code Style > Imports', I can see that you can specify the 'class count' prior to IntelliJ using wildcard imports. Howe...

27 Oct at 13:49

What is the difference between declarative and imperative paradigm in programming?

I have been searching the web looking for a definition for and programming that would shed some light for me. However, the language used at some of the resources that I have found is daunting - for ...

node.js remove file

How do I delete a file with node.js? [http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback](http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback) I don't see a remove c...

22 Feb at 13:51

How to output numbers with leading zeros in JavaScript?

Is there a way to prepend leading zeros to numbers so that it results in a string of fixed length? For example, `5` becomes `"05"` if I specify 2 places.

How to fix committing to the wrong Git branch?

I just made a perfectly good commit to the wrong branch. How do I undo the last commit in my master branch and then take those same changes and get them into my upgrade branch?

18 Jul at 07:12

Concatenate two slices in Go

I'm trying to combine the slice `[1, 2]` and the slice `[3, 4]`. How can I do this in Go? I tried: ``` append([]int{1,2}, []int{3,4}) ``` but got: ``` cannot use []int literal (type []int) as typ...

14 Oct at 07:5