Rectangle 27 41

ldapwhoami -vvv -h <hostname> -p <port> -D <binddn> -x -w <passwd>
binddn
Result: Success (0)
ldap_bind: Invalid credentials (49)

directory - Easy way to test an LDAP User's Credentials - Stack Overfl...

directory ldap opends opendj
Rectangle 27 430

_.range()
_.range(10);
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11);
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5);
=> [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1);
=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]

Or without a library:

Array.apply(null, Array(5)).map(function (_, i) {return i;});
=> [0, 1, 2, 3, 4]
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
String.fromCharCode(..._.range('A'.charCodeAt(0), 'D'.charCodeAt(0) + 1));
=> "ABCD"
console.log([...Array(5).keys()]);

Because if it's useful anywhere it is probably useful in JS. (JS can do functional programming type stuff, which can benefit from a range(0 statement. That and a thousand other reasons it might be useful in some semirare case)

Useful Lodash function, but does not answer the second part of this question: how to create a character range.

(new Array(5)).map(function (value, index) { return index; })
[undefined  5]

@Lewis Because an array defined with that has empty slots that won't be iterated over with map() or one of its friends.

Does JavaScript have a method like "range()" to generate an array base...

javascript arrays
Rectangle 27 419

_.range()
_.range(10);
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11);
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5);
=> [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1);
=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]

Or without a library:

Array.apply(null, Array(5)).map(function (_, i) {return i;});
=> [0, 1, 2, 3, 4]
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
String.fromCharCode(..._.range('A'.charCodeAt(0), 'D'.charCodeAt(0) + 1));
=> "ABCD"
console.log([...Array(5).keys()]);

Because if it's useful anywhere it is probably useful in JS. (JS can do functional programming type stuff, which can benefit from a range(0 statement. That and a thousand other reasons it might be useful in some semirare case)

Useful Lodash function, but does not answer the second part of this question: how to create a character range.

(new Array(5)).map(function (value, index) { return index; })
[undefined  5]

@Lewis Because an array defined with that has empty slots that won't be iterated over with map() or one of its friends.

Does JavaScript have a method like "range()" to generate an array base...

javascript arrays
Rectangle 27 447

_.range()
_.range(10);
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11);
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5);
=> [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1);
=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]

Or without a library:

Array.apply(null, Array(5)).map(function (_, i) {return i;});
=> [0, 1, 2, 3, 4]
[...Array(5).keys()];
=> [0, 1, 2, 3, 4]
String.fromCharCode(..._.range('A'.charCodeAt(0), 'D'.charCodeAt(0) + 1));
=> "ABCD"
console.log([...Array(5).keys()]);

Because if it's useful anywhere it is probably useful in JS. (JS can do functional programming type stuff, which can benefit from a range(0 statement. That and a thousand other reasons it might be useful in some semirare case)

Useful Lodash function, but does not answer the second part of this question: how to create a character range.

(new Array(5)).map(function (value, index) { return index; })
[undefined  5]

@Lewis Because an array defined with that has empty slots that won't be iterated over with map() or one of its friends.

Does JavaScript have a method like "range()" to generate an array base...

javascript arrays
Rectangle 27 833

Use the operation that best describes what you are trying to do.

  • If you are treating the number as a sequence of bits, use bitshift.
  • If you are treating it as a numerical value, use division.

Note that they are not exactly equivalent. They can give different results for negative integers. For example:

-5 / 2  = -2
-5 >> 1 = -3

The original question was also vague about the term 'best'. 'Best' in terms of speed, readability, exam question to trick students, etc... In the absence of a explanation of what 'best' means, this seems to be the most correct answer.

In C++03, both are implementation defined for negative numbers, and might give the same results. In C++11, division is well defined for negative numbers, but shifting is still implementation defined.

While the definition of / is implementation (does if round up or down for negative numbers) defined in early C standards. It must always be consistent with % (modulo/remainder operator).

"Implementation defined" means that the implementer of the compiler got to choose among several implementation choices, usually with substantial constraints. Here, one constraint is that the % and / operators must be consistent for both positive and negative operands so that (a/b)*b+(a%b)==a is true regardless of the signs of a and b. Usually, the author will make choices that get the best possible performance out of the CPU.

So everyone who says "the compiler will convert it to a shift anyway" is wrong, right? Unless the compiler can guarantee that you are dealing with a non-negative integer (either it is a constant or it is an unsigned int), it can't change it to a shift

c++ - Which is better option to use for dividing an integer number by ...

c++ c optimization division micro-optimization
Rectangle 27 833

Use the operation that best describes what you are trying to do.

  • If you are treating the number as a sequence of bits, use bitshift.
  • If you are treating it as a numerical value, use division.

Note that they are not exactly equivalent. They can give different results for negative integers. For example:

-5 / 2  = -2
-5 >> 1 = -3

The original question was also vague about the term 'best'. 'Best' in terms of speed, readability, exam question to trick students, etc... In the absence of a explanation of what 'best' means, this seems to be the most correct answer.

In C++03, both are implementation defined for negative numbers, and might give the same results. In C++11, division is well defined for negative numbers, but shifting is still implementation defined.

While the definition of / is implementation (does if round up or down for negative numbers) defined in early C standards. It must always be consistent with % (modulo/remainder operator).

"Implementation defined" means that the implementer of the compiler got to choose among several implementation choices, usually with substantial constraints. Here, one constraint is that the % and / operators must be consistent for both positive and negative operands so that (a/b)*b+(a%b)==a is true regardless of the signs of a and b. Usually, the author will make choices that get the best possible performance out of the CPU.

So everyone who says "the compiler will convert it to a shift anyway" is wrong, right? Unless the compiler can guarantee that you are dealing with a non-negative integer (either it is a constant or it is an unsigned int), it can't change it to a shift

c++ - Which is better option to use for dividing an integer number by ...

c++ c optimization division micro-optimization
Rectangle 27 99

Yes, use gzip for this. The best way is to read data as input and redirect the compressed to output file i.e.

cat test.csv | gzip > test.csv.gz

cat test.csv will send the data as stdout and using pipe-sign gzip will read that data as stdin. Make sure to redirect the gzip output to some file as compressed data will not be written to the terminal.

Note that the test.csv.gz files remains of 0 size until the data flux is closed.

xz
mysqldump mydb | xz > dbdump.sql.xz
-9
-6

linux - Compress files while reading data from STDIN - Stack Overflow

linux stdin compression
Rectangle 27 81

Use the very popular Underscore _.range method

// _.range([start], stop, [step])

_.range(10); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11); // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5); // => [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1); //  => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
_.range(0); // => []

Create a JavaScript array containing 1...N - Stack Overflow

javascript arrays
Rectangle 27 51

Is this not bcp was meant for?

bcp "select col1, col2, col3 from database.schema.SomeTable" queryout  "c:\MyData.txt"  -c -t"," -r"\n" -S ServerName -T
bcp /?

the syntax is as follows:

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]         [-x generate xml format file]
  [-d database name]

Please, note that bcp can not output column headers.

What do you do if you need to export the column names as a header as well? Is there a straightforward generic solution using bcp?

@johndacosta thanks so much. How would you print the column headers as well? I'm not seeing an easy switch to it anywhere. Thanks!

It looks like there is no way to get column names with bcp. And that makes it useless for the case.

file - How to export data as CSV format from SQL Server using sqlcmd? ...

sql-server file csv sqlcmd
Rectangle 27 81

Use the very popular Underscore _.range method

// _.range([start], stop, [step])

_.range(10); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11); // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5); // => [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1); //  => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
_.range(0); // => []

Create a JavaScript array containing 1...N - Stack Overflow

javascript arrays
Rectangle 27 79

Use the very popular Underscore _.range method

// _.range([start], stop, [step])

_.range(10); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11); // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5); // => [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1); //  => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
_.range(0); // => []

Create a JavaScript array containing 1...N - Stack Overflow

javascript arrays
Rectangle 27 287

Of course, you will get a fatal error for authenticating, because you do not include a user name...

psql -U username -d myDataBase -a -f myInsertFile

If the database is remote, use the same command with host

psql -h host -U username -d myDataBase -a -f myInsertFile

Note that the provided username has to be a valid postgres role. The default is the currently logged in user.

-a

Run a PostgreSQL .sql file using command line arguments - Stack Overfl...

postgresql command-line psql
Rectangle 27 95

run your app on a high port 8080 or whatev then

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

If you are not using ngnix or apache

Also would be helpful to know how to undo this. "--to-port 80" I don't think is the perfect solution. It still has to handle this binding.

To UNDO this: sudo iptables -D PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 (basically change the -A to a -D. That's all)

apache - How do I run Node.js on port 80? - Stack Overflow

apache proxy node.js websocket
Rectangle 27 18

I had a similar problem. I am posting my solution here because I believe it might help one of the commenters.

For me, the obstacle was that the page required a login and then gave me a new URL through javascript. Here is what I had to do:

Note that j_username and j_password is the name of the fields for my website's login form. You will have to open the source of the webpage to see what the 'name' of the username field and the 'name' of the password field is in your case. After that I go an html file with java script in which the new URL was embedded. After parsing this out just resubmit with the new URL:

curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword"  <NEWURL>

php - Is there a way to follow redirects with command line cURL - Stac...

php redirect curl command-line-interface
Rectangle 27 18

I had a similar problem. I am posting my solution here because I believe it might help one of the commenters.

For me, the obstacle was that the page required a login and then gave me a new URL through javascript. Here is what I had to do:

For me the obstacle was that the page required a login and then gave me through java script a new URL. Here is what I had to do:

Note that j_username and j_password is the name of the fields for my website's login form. You will have to open the source of the webpage to see what the 'name' of the username field and the 'name' of the password field is in your case. After that I go an html file with java script in which the new URL was embedded. After parsing this out just resubmit with the new URL:

curl -c cookiejar -g -O -J -L -F "j_username=yourusename" -F "j_password=yourpassword"  <NEWURL>

php - Is there a way to follow redirects with command line cURL - Stac...

php redirect curl command-line-interface
Rectangle 27 95

run your app on a high port 8080 or whatev then

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

If you are not using ngnix or apache

Also would be helpful to know how to undo this. "--to-port 80" I don't think is the perfect solution. It still has to handle this binding.

To UNDO this: sudo iptables -D PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 (basically change the -A to a -D. That's all)

apache - How do I run Node.js on port 80? - Stack Overflow

apache proxy node.js websocket
Rectangle 27 64

The most complete, concise definition of false I've come across is:

Therefore, the following values are false:

  • An object with an overloaded boolean operator that evaluates one of the above.
  • A magical variable that evaluates to one of the above on fetch.

Keep in mind that an empty list literal evaluates to an undefined value in scalar context, so it evaluates to something false.

While numbers that stringify to 0 are false, strings that numify to zero aren't necessarily. The only false strings are 0 and the empty string. Any other string, even if it numifies to zero, is true.

The following are strings that are true as a boolean and zero as a number.

"0.0"
"0E0"
"00"
"+0"
"-0"
" 0"
"0\n"
".0"
"0."
"0 but true"
"\t00"
"\n0e1"
"+0.e-9"
Scalar::Util::looks_like_number
"abc"
my $value = do { package XXX; use overload q[""] => sub { "XXX" }, q[bool] => sub { 0 }; bless [] };
$value

@tobyink, The concise version isn't perfect, merely the best I've found. It's meant to be practical, not all-encompassing. Do note that value returned by your bool does stringify to 0. Also, you are discouraged from creating inconsistent overloads, and the values you return could be considered such. (e.g. a && can be optimized into a ||, so if these were inconsistent, you'd have a problem.)

I'm not sure if 0x00 is covered here.

How do I use boolean variables in Perl? - Stack Overflow

perl boolean
Rectangle 27 32

For Windows users: when using PyCharm with a virtual environment, you can use the /K parameter to cmd.exe to set the virtual environment automatically.

Default shell
Settings
Tools
Terminal
/K <path-to-your-activate.bat>
Shell path

PyCharm 2016.1 or 2016.2: Settings, Tools, Terminal, and add ""/K <path-to-your-activate.bat>"" to Shell path and add (mind the quotes). Also add quotes around cmd.exe, resulting in:

"cmd.exe" /k ""C:\mypath\my-venv\Scripts\activate.bat""
-k
/K

@tchakravarty: that was a typo (corrected in the mean while)

python - How do I activate a virtualenv inside PyCharm's terminal? - S...

python django shell virtualenv pycharm
Rectangle 27 262

Of course, you will get a fatal error for authenticating, because you do not include a user name...

psql -U username -d myDataBase -a -f myInsertFile

Note that the provided username has to be a valid postgres role. The default is the currently logged in user.

This should be the accepted answer.

Run a PostgreSQL .sql file using command line arguments - Stack Overfl...

postgresql command-line psql
Rectangle 27 113

You can user reversed() method

for i in (1...5).reversed() { print(i) } // 5 4 3 2 1
for i in stride(from:5,to:1,by:-1) { print(i) } // 5 4 3 2 1

First of all, protocol extensions change how reverse is used:

for i in (1...5).reverse() { print(i) } // 5 4 3 2 1
for i in 0.stride(to: -8, by: -2) { print(i) } // 0 -2 -4 -6
for i in 0.stride(through: -8, by: -2) { print(i) } // 0 -2 -4 -6 -8
Doubles
for i in 0.5.stride(to:-0.1, by: -0.1) { print(i) }

Be wary of floating point compares here for the bounds.

If you are just looking to reverse a range, the reverse function is all you need:

for i in reverse(1...5) { println(i) } // prints 5,4,3,2,1

As posted by 0x7fffffff there is a new stride construct which can be used to iterate and increment by arbitrary integers. Apple also stated that floating point support is coming.

for x in stride(from: 0, through: -8, by: -2) {
    println(x) // 0, -2, -4, -6, -8
}

for x in stride(from: 6, to: -2, by: -4) {
    println(x) // 6, 2
}

it should be (1...5).reverse() (as a function call), please update your answer. (Since it's only two characters, I couldn't edit your post.)

looks like the stride code for swift 3 is slightly incorrect. to include the number 1, you would need to use through opposed to to like this: for i in stride(from:5,through:1,by:-1) { print(i) }

Reverse Range in Swift - Stack Overflow

swift