Questions

Create a dictionary with comprehension

Can I use list comprehension syntax to create a dictionary? For example, by iterating over pairs of keys and values: ``` d = {... for k, v in zip(keys, values)} ```

How can I undo git reset --hard HEAD~1?

Is it possible to undo the changes caused by the following command? If so, how? ``` git reset --hard HEAD~1 ```

20 Dec at 15:41

How do I vertically align text in a div?

I am trying to find the most effective way to align text with a div. I have tried a few things and none seem to work. ``` .testimonialText { position: absolute; left: 15px; top: 15px; width: ...

23 Jun at 16:4

How do I make a redirect in PHP?

Is it possible to redirect a user to a different page through the use of PHP? Say the user goes to `www.example.com/page.php` and I want to redirect them to `www.example.com/index.php`, how would I d...

How to get GET (query string) variables in Express.js on Node.js?

Can we get the variables in the query string in Node.js just like we get them in `$_GET` in PHP? I know that in Node.js we can get the URL in the request. Is there a method to get the query string pa...

4 May at 12:1

How do you get a list of the names of all files present in a directory in Node.js?

I'm trying to get a list of the names of all the files present in a directory using Node.js. I want output that is an array of filenames. How can I do this?

How to change the order of DataFrame columns?

I have the following `DataFrame` (`df`): ``` import numpy as np import pandas as pd df = pd.DataFrame(np.random.rand(10, 5)) ``` I add more column(s) by assignment: ``` df['mean'] = df.mean(1) ``...

20 Jan at 13:47

How can I drop all the tables in a PostgreSQL database?

How can I drop all tables in PostgreSQL, working from the command line? I want to drop the database itself, just all tables and all the data in them.

7 Feb at 14:57

How can I revert multiple Git commits?

I have a Git repository that looks like this: ``` A <- B <- C <- D <- HEAD ``` I want the head of the branch to point to A, i.e., I want B, C, D, and HEAD to disappear and I want head to be synonymou...

14 May at 19:47

What are bitwise shift (bit-shift) operators and how do they work?

I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators)... At a core level, what does bit-shifting (`<<`, `>>`, `>>>...

How do I create a file and write to it?

What's the simplest way to [create and write to a (text) file in Java](https://docs.oracle.com/javase/tutorial/essential/io/file.html)?

27 Jan at 11:20

How to join (merge) data frames (inner, outer, left, right)

Given two data frames: ``` df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3))) df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1)...

13 Oct at 19:44

How do I check if directory exists in Python?

How do I check if a directory exists?

9 Apr at 07:49

Why can't Python parse this JSON data?

I have this JSON in a file: ``` { "maps": [ { "id": "blabla", "iscategorical": "0" }, { "id": "blabla", "iscategorical": "0"...

1 Jul at 21:31

Default behavior of "git push" without a branch specified

I use the following command to push to my remote branch: ``` git push origin sandbox ``` If I say ``` git push origin ``` does that push changes in my other branches too, or does it only update ...

24 Jun at 04:40

Why don't self-closing script elements work?

What is the reason browsers do not correctly recognize: ``` <script src="foobar.js" /> <!-- self-closing script element --> ``` Only this is recognized: ``` <script src="foobar.js"></script> ``` ...

Relative imports in Python 3

I want to import a function from another file in the same directory. Usually, one of the following works: ``` from .mymodule import myfunction ``` ``` from mymodule import myfunction ``` ...but the ...

29 Aug at 12:4

How to check if a value exists in an array in Ruby

I have a value `'Dog'` and an array `['Cat', 'Dog', 'Bird']`. How do I check if it exists in the array without looping through it? Is there a simple way of checking if the value exists, nothing more...

6 Feb at 05:16

When are you supposed to use escape instead of encodeURI / encodeURIComponent?

When encoding a query string to be sent to a web server - when do you use `escape()` and when do you use `encodeURI()` or `encodeURIComponent()`: Use escape: ``` escape("% +&="); ``` OR use encod...

11 Dec at 14:17

How do I convert a float number to a whole number in JavaScript?

I'd like to convert a float to a whole number in JavaScript. Actually, I'd like to know how to do BOTH of the standard conversions: by truncating and by rounding. And efficiently, not via converting t...

24 Feb at 18:16

What is setup.py?

What is `setup.py` and how can it be configured or used?

What's a quick way to comment/uncomment lines in Vim?

I have a Ruby code file open in vi, there are lines commented out with `#`: ``` class Search < ActiveRecord::Migration def self.up # create_table :searches do |t| # t.integer :user_id ...

25 Dec at 02:0

How do you do block comments in YAML?

How do I comment a block of lines in YAML?

13 Oct at 14:44

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 20: ordinal not in range(128)

I'm having problems dealing with unicode characters from text fetched from different web pages (on different sites). I am using BeautifulSoup. The problem is that the error is not always reproducibl...

How to convert a string to number in TypeScript?

Given a string representation of a number, how can I convert it to `number` type in TypeScript? ``` var numberString: string = "1234"; var numberValue: number = /* what should I do with `numberString...

1 Jun at 21:30