node.js – Comparing mongoose _id and strings

node.js – Comparing mongoose _id and strings

Mongoose uses the mongodb-native driver, which uses the custom ObjectID type. You can compare ObjectIDs with the .equals() method. With your example, results.userId.equals(AnotherMongoDocument._id). The ObjectID type also has a toString() method, if you wish to store a stringified version of the ObjectID in JSON format, or a cookie.

If you use ObjectID = require(mongodb).ObjectID (requires the mongodb-native library) you can check if results.userId is a valid identifier with results.userId instanceof ObjectID.

Etc.

ObjectIDs are objects so if you just compare them with == youre comparing their references. If you want to compare their values you need to use the ObjectID.equals method:

if (results.userId.equals(AnotherMongoDocument._id)) {
    ...
}

node.js – Comparing mongoose _id and strings

converting object id to string(using toString() method) will do the job.

Related posts:

uwp – Permission to access WindowsApps folder

uwp – Permission to access WindowsApps folder

You can access the files inside the WindowsApps folder but only in read-only manner. While it is technically possible to replace files of an app, it is not possible to replace files of an installed app. This would break the integrity of the package and that is verified before the app is launched by the system, so any modification will cause the app not to launch successfully.

However if you just want to access the folder, you can follow the instructions on my brothers blog or here.

Beware

All changes below are at your own risk, as you are modifying the permissions of a system folder and that could potentially cause issues

Go to C:Program Files and right click the WindowsApps folder. Select Properties and go to Security tab. Click the Advanced button. Click the Continue button to give yourself administrative permissions.

Permissions

Next, click the Change button to change the owner and in the newly opened dialogs Enter the object name to select field enter your username or e-mail (in case you use Microsoft Account). Finally apply the setting on subcontainers by checking the Replace owner on subcontainers and objects field.

Apply

Now click Apply and wait until the permissions are granted for all existing items and that should do it 🙂 .

uwp – Permission to access WindowsApps folder

Related posts:

Ubuntu 16.04, CUDA 8 – CUDA driver version is insufficient for CUDA runtime version

Ubuntu 16.04, CUDA 8 – CUDA driver version is insufficient for CUDA runtime version

Running

sudo apt-get purge nvidia-*

and reinstalling the drivers using

sudo apt-get install nvidia-375

solved it. Just for the record, the first time I updated the drivers using the GUI (Additional Drivers tab in Software & Updates).

First, check CUDA Toolkit and Compatible Driver Versions from here, and make sure that your cuda toolkit version is compatible with your cuda-driver version, e.g. if your driver version is nvidia-390, your cuda version must lower than CUDA 9.1.
Then, back to this issue. This issue is caused by your cuda-driver version doesnt match your cuda version, and your CUDA local version may also different from the CUDA runtime version(cuda version in some specific virtual environments).
I met the same issue when I tried to run tensorflow-gpu under the environment of tensorflow_gpuenv created by conda, and tried to test whether the gpu:0 device worked. My driver version is nvidia-390 and Ive already install cuda 9.0, so it doesnt make sense that raising that weird issue. I finally found the reason that the cuda version in the conda virtual environment is cuda 9.2 which isnt compatible with nvidia-390. I solved the issue by following steps in ubuntu 18.04:

  • check cuda driver version
    ~$ nvidia-smi or ~$ cat /proc/driver/nvidia/version
  • check local cuda version
    ~$ nvcc --version or ~$ cat /usr/local/cuda/version.txt
  • check local cudnn version
    ~$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2


  • check cuda version in virtual environment
    ~$ conda list you can see something like these :
    cudatoolkit      9.2       0
    cudnn        7.3.1      cuda9.2_0
    you may find that the cuda version in virtual environment is different from the local cuda version, and isnt compatible with driver version nvidia-390.

So reinstall cuda in the virtual environment:

  • reinstall cuda : ~$ conda install cudatoolkit=8.0
    (change the version number 8.0 to other version number which match your driver version, and your cudnn version will update automatically to match the new version cuda )

Ubuntu 16.04, CUDA 8 – CUDA driver version is insufficient for CUDA runtime version

I have followed the instructions on this page, and it works for me.

https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&target_distro=Ubuntu&target_version=1604&target_type=debnetwork

First, download installer for Linux Ubuntu 16.04 x86_64.

Next, follow these steps to install Linux Ubuntu:

  1. sudo dpkg -i cuda-repo-ubuntu1604_9.2.148-1_amd64.deb
  2. sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/7fa2af80.pub
  3. sudo apt-get update
  4. sudo apt-get install cuda

Related posts:

coldfusion – parsing a string date into datetime format

coldfusion – parsing a string date into datetime format

Not an ideal situation, but the format you are getting data especially dots in am/pm strings make it hard to read and on top of that it comes in UK Date format. This can help:

<cfset x=21/11/2008 7:04:28 p.m.>
<cfset x=Replace(x,.,,All)>
<cfset y=LSDateFormat(x,mm/dd/yyyy,English (UK))>
<cfoutput>
    x====#x#
    <br/>y===#y#
<cfset z=CreateDateTime(Year(y),month(y),day(y),hour(x),minute(x),second(x))>
z====#z#
<cfset someDatevare=LSParseDateTime(x,English (UK))>
</cfoutput>

EDIT As Leigh mentioned, removing periods or any other non-standard characters from the string and then LSParseDateTime will return a date time object.

coldfusion – parsing a string date into datetime format

Related posts:

c – How to convert unsigned long to string

c – How to convert unsigned long to string

const int n = snprintf(NULL, 0, %lu, ulong_value);
assert(n > 0);
char buf[n+1];
int c = snprintf(buf, n+1, %lu, ulong_value);
assert(buf[n] == �);
assert(c == n);

The standard approach is to use sprintf(buffer, %lu, value); to write a string rep of value to buffer. However, overflow is a potential problem, as sprintf will happily (and unknowingly) write over the end of your buffer.

This is actually a big weakness of sprintf, partially fixed in C++ by using streams rather than buffers. The usual answer is to allocate a very generous buffer unlikely to overflow, let sprintf output to that, and then use strlen to determine the actual string length produced, calloc a buffer of (that size + 1) and copy the string to that.

This site discusses this and related problems at some length.

Some libraries offer snprintf as an alternative which lets you specify a maximum buffer size.

c – How to convert unsigned long to string

you can write a function which converts from unsigned long to str, similar to ltostr library function.

char *ultostr(unsigned long value, char *ptr, int base)
{
  unsigned long t = 0, res = 0;
  unsigned long tmp = value;
  int count = 0;

  if (NULL == ptr)
  {
    return NULL;
  }

  if (tmp == 0)
  {
    count++;
  }

  while(tmp > 0)
  {
    tmp = tmp/base;
    count++;
  }

  ptr += count;

  *ptr = �;

  do
  {
    res = value - base * (t = value / base);
    if (res < 10)
    {
      * -- ptr = 0 + res;
    }
    else if ((res >= 10) && (res < 16))
    {
        * --ptr = A - 10 + res;
    }
  } while ((value = t) != 0);

  return(ptr);
}

you can refer to my blog here which explains implementation and usage with example.

Related posts:

push function in perl not adding elements to existing array. why?

push function in perl not adding elements to existing array. why?

first of use strict and warnings pragma. Your script doesnt work because you dont have anything assigned for $b variable, so you are pushing empty values to the array, and as said before you are just printing the number of elements in the array. Also push function only returns the number of the arrays after the new element is pushed to the array if I remember correctly, so returning should always be a scalar.

my @a = (1,2,3);
my @b= (homer, marge, lisa, maria);
my @c= qw(one two three);

#merge the two arrays and count elements
my $no_of_elements = push @a, @b;
print $no_of_elements;

#look into say function, it prints the newline automatically
print n;

#use scalar variable to store a single value not an array 
my $count_number= push @a, $b;

print @count_number; print n;

print @a;

Also interesting fact, if you print @array it will list all the elements without spaces, but if you enclose the array in double quotes, print @array, it will put spaces in between the elements.
Oh and last but not least, if you are new to perl you really really reaaally should download the book of modern perl at http://www.onyxneon.com/books/modern_perl/index.html, it is updated on yearly basis so you will find there the most up to date practices and code; which definitely beats any outdated online tutorials. Also the book is very well and logically structured and makes learning perl a breeze.

$b is undefined.

@b and $b are different variables. One is a list, the other a scalar.

You are printing the length of the array, and not the contents.

Recommendations:

  1. Use use warnings;
  2. Use use strict;
  3. Use push @a, @b;

Your script:

@a = (1,2,3);  # @a contains three elements
@b= (homer, marge, lisa, maria); # @b contains 4 elements
@c= qw(one two three); # @c contains 3 elements
print push @a, $b;     # $b is undefined, @a now contains four elements 
                       #(forth one is undef), you print out 4
print n;

@count_number= push @a, $b; # @a now contains 5 elements, last two are undef, 
                            # @count_number contains one elements: the number 5

print @count_number;        # you print the contents of @count_number which is 5
print n;
print @a;                   # you print @a which looks like what you started with
                            # but actually contains 2 undefs at the end

Try this:

#!/usr/bin/perl
use warnings;
use strict;

my $b = 4;
my @a = (1,2,3);
my @b= (homer, marge, lisa, maria);
my @c= qw(one two three);

print a contains  . @a .  elements: @an;

push @a, $b;
print now a contains  . @a .  elements: @an;

my $count_number = push @a, $b;
print finally, we have $count_number elements n;
print a contains @an;

push function in perl not adding elements to existing array. why?

$array returns the length of the array (Number of elements in the array)
To push any element ($k) into the array (@arr), use push (@arr, $k).
In the above case,

use push (@b, @b);

Related posts:

android – upgraded galaxy S5 to 4.4.4 and now it wont show up in ADB

android – upgraded galaxy S5 to 4.4.4 and now it wont show up in ADB

You need to download the Samsung Universal USB drivers for mobile devices and install it on your Windows 64-bit operating system.

You can get the USB drivers directly from Bittorrent, or go to http://www.samsung.com/ and search for the USB drivers there.

Once USB drivers installation is finished:

  1. Enable USB Debugging option in your S5 device.
  2. Connect your S5 via the USB cable to Windows.
  3. Open a command prompt, type: adb kill-server, then adb start-server, then adb devices. The last command will tell you whether your S5 can be connected successfully to your Windows PC. Note: adb is located at ../android-sdk/platform-tools/ directory.
  4. Start your Android project via your IDE (Eclipse, Android Studio,
    etc).

android – upgraded galaxy S5 to 4.4.4 and now it wont show up in ADB

Related posts:

Chrome says my extensions manifest file is missing or unreadable

Chrome says my extensions manifest file is missing or unreadable

Something that commonly happens is that the manifest file isnt named properly. Double check the name (and extension) and be sure that it doesnt end with .txt (for example).

In order to determine this, make sure you arent hiding file extensions:

  1. Open Windows Explorer
  2. Go to Folder and Search Options > View tab
  3. Uncheck Hide extensions for known file types

Also, note that the naming of the manifest file is, in fact, case sensitive, i.e. manifest.json != MANIFEST.JSON.

My problem was slightly different.

By default Eclipse saved my manifest.json as an ANSI encoded text file.

Solution:

  • Open in Notepad
  • File -> Save As
  • select UTF-8 from the encoding drop-down in the bottom left.
  • Save

Chrome says my extensions manifest file is missing or unreadable

I also encountered this issue.

My problem was that I renamed the folder my extension was in, so all I had to do was delete and reload the extension.

Thought this might help some people out there.

Related posts:

Will Linux servers running MONGODB be affected by plans to add a leap second in 2016?

Will Linux servers running MONGODB be affected by plans to add a leap second in 2016?

You can operate normally as your Red Hat relies on NTP:

From MongoDB and Leap Seconds:

Remember, MongoDB relies on host operating system capabilities for reading the wall clock time, and for synchronizing events with wall clock time. As such, you should ensure that the operating system running under MongoDB is itself prepared for leap seconds.

From Resolve Leap Second Issues in Red Hat Enterprise Linux:

Systems running any version of Red Hat Enterprise Linux should automatically account for leap second corrections if they are using the NTP (Network Time Protocol) daemon to synchronize their local timekeeping with an NTP server. During the last day before a leap second correction, NTP servers should notify their clients that a leap second will occur, and at 23:59:59 UTC, the Linux kernel should add or remove an extra second by making the 60th second occur twice or removing it entirely.

Will Linux servers running MONGODB be affected by plans to add a leap second in 2016?

Related posts:

License expired after installation Microsoft Visual Studio 2015 community

License expired after installation Microsoft Visual Studio 2015 community

I had this same problem. The Community Edition is free, but you have to sign into your Microsoft account to use it more than 30 days. Go to https://account.microsoft.com/about and signup for an account. Its free. When you complete the process, you can sign into Visual Studio using the same email address.

I had to reset Visual Studios settings totally with:

Devenv.exe /ResetSettings

After that my license was detected correctly.

See this post on MSDN Forums for more details

License expired after installation Microsoft Visual Studio 2015 community

I had the same problem using the small executable. I downloaded the .ISO and installed from that. Had no problems since.

Related posts: