Linux HowTo: Two monitors: pointer sometimes gets slightly stuck on the edge on one monitor

Original Source Link

Recently switched from one to two monitor setup. Sometimes, pointer gets stuck on the edge of one monitor (always the same) and I need to really insist by making huge moves to make the pointer finally cross over to the other monitor.

The weird thing is it seems to happen randomly, most of the time it doesn’t occur.

Any idea?

Depending on the arrangement of the two monitors in you’re monitor settings – how exactly they align with each other – you might have to move you’re pointer up or down in order to get to the other monitor. Especially if the two monitors don’t have the same resolution, but it can be the case with the same resolution as well.

Here is an example of a two monitor setting under Windows 10. If you are on the lower right corner of screen 1 (anywhere in the red area) you wont be able to move to the second screen. You will have to move the mouse pointer further up – out of the red area – in order to move to the 2nd monitor:

enter image description here

It’s unlikely to be random.

In any multi-monitor setup, what you see & what the computer sees are two different things.

Pics from a 3-monitor setup, but the same rules apply

What you see is 2 [or 3] monitors of the same size – you don’t really care about the resolution of each.

enter image description here

What the computer sees, however, is only the resolution of each – it cannot see their physical size. So if they have different resolutions, the computer considers them to be different sizes & you cannot pass from one to the other where there is no screen.

enter image description here

So to move your cursor from one to another, you need to leave one monitor in an area where the next monitor exists to the computer, not your eyes.

Some operating systems will allow you to change the precise area where they meet, so you could for instance set the tops in line, rather than the centres.

It’s not random, nor is it a display alignment issue. It’s actually a ‘feature’ of Windows 10.

Note: If you want to be able to see for yourself that it is or isn’t a display alignment issue, try moving your mouse at an angle so that the cursor ‘rubs’ against the edge of the display area as it crosses from one monitor to the other, then try doing the same thing again, but going from the second monitor back to the first. If it works in one direction but not the other, it’s imperfect alignment, if both directions stop at the corner, it’s due to this new feature in Windows.

I’m not sure what the technical name of this feature is, nor do I know if it was added in Windows 8, 8.1 or 10, but I do know it’s not present in Windows 7, and it is present in Windows 10.

The feature I’m referring to is the fact that on Windows 10 moving your cursor from one physical monitor to another will be prevented if the cursor is close enough to the edge of the display area that it thinks you might actually be aiming for the corner of that monitor, instead of trying to get your cursor onto the other monitor. In my experience the threshold appears to be about 5 or so pixels.

I’m unaware of a way to disable this feature (if someone does know of a way, please post some info), however once you’re aware of what’s actually happening, it’s fairly easy to simply move your cursor a little further from the edge of the screen to get around this virtual ‘bump’.

Personally, at this point in my Multi-Monitor Windows 10 usage, I’m unsure if I like or dislike this feature, but it would be nice to have the option to disable it if desired.

I had the same issue and I use the Software DisplayFusion,
it has the Feature Prevent mouse cursor from snagging on unaligned monitor edges, search for it in the help: https://www.displayfusion.com/Help/?Version=9.3.99.103#settings-mousemanagement

It’s sad that the free edition does not offer this function, search for Prevent mouse from snagging on unaligned screen edges:
https://www.displayfusion.com/Compare/

But DisplayFusion is very useful and they maintain the Software, so I’ve got many new features and functions since I bought the license 🙂

I was having this problem and went into ‘Display settings’ and rearranged the screens.
After clicking ‘Apply’ the problem went away.

Let me write my trouble; I’ve got three screens 1-2 horizontally and 3rd is vertical to them. My trouble is my pointer can access from 1-3 and 2-3 easily, but horizontal 1-2 edge there was a rigid line at the edge so that you must accelerate pointer to be able to pass to 1-2 edge. Finally I realized to do that there was a thick gap between 1-2 in the plan at the monitor arrangements at the display setting area. And I tried to make them closer at that screen and re-apply the arrangement and my problem, 1-2 hard edge behavior has been disappeared!

enter image description here

You probably have 2 different monitors. In screen settings (right click on desktop, and option at the end), drag your monitor 2 a little bit up. Now you can slide with mouse on the bottom side. It feels natural (and more often) to slide using bottom side, than using upper side.

Original

After I dragged it

I had the same issue and I figured it out. I have a Mac. In System Preferences, Display: when setting the arrangement of the 2 monitors, make sure that the borders of the monitors are touching each other. That should fix the issue. If there is a gap, then you will have issue.

OK, I had this same exact issue. It’s like there was an invisible barrier between the monitors that the mouse would not cross unless I moved the cursor to the far side of the monitor and “slammed” the cursor thru the barrier. I fixed it In display settings make sure you have the monitor 1 on the actual side that monitor 1 is physically located in your set up and the same for monitor 2. That seems to have fixed the issue for me.

Tagged : /

Math Genius: Is this random walk transient or recurrent

Original Source Link

Suppose $mathbb{P}(X=1)=mathbb{P}(X=-1)=frac{1}{6}$ and $mathbb{P}(X=0) = frac{2}{3}$. Is the random walk of $X$ transient or recurrent?

I wanted to use well known result that random walk is transient iff:
$$mathbb{E}N = lim_{t to 1^-} int_{[-pi , pi]^d}frac{ds}{(2 pi)^d(1-tvarphi(s))} < infty$$
where $N = sum_{n geq 0}mathbb{1}_{{S_n = S_0}}$.

I need to find $varphi_X(t)$. Using what I already know
$$
varphi_X(t)=mathbb{E}e^{itX}=frac{1}{6}e^{it}+frac{1}{6}e^{-it}+frac{2}{3}e^{it0} = frac{cos t + 2}{3}
$$

I am stuck however, with the integral.
$$
mathbb{E}N = lim_{t to 1^-} int_{[-pi , pi]}frac{ds}{2 pi(1-t[frac{cos s + 2}{3}])} =
$$

function seems even so
$$
= lim_{t to 1^-} int_{[0, pi]}frac{ds}{pi(1-t[frac{cos s + 2}{3}])} = dots ?
$$

Is this a good start of this exercise? What can I do next? Can I swap integral with the limit? If yes, why? I appreciate any help.

Recall that the random walk $Y$ on one dimension (i.e. $mathbb{Z}$) is recurrent. Now, it is easy to convert your random walk to $Y$, by conditioning on $Xneq 0$. It should be much easier this way.

Edit: just saw that you wanted to use your method. I am having a look.

Ah okay, look at what happens as $srightarrow 0$ in your integral. The denominator goes to infinity as $trightarrow 1$. This behavior is proportional to a singularity like $1/u$, so your integral is not finite and thus the random walk is recurrent.

This seems more hand-wave-y than an argument based on conditioning.

Okay, it suffices to show that a lower bound of the integral still diverges. By drawing the graph of $cos$ and connecting $(0,1)$ and $(pi/2,0)$, we see that $cos$ is bounded below by $1-(2/pi)*x$. Hence the denominator of the integral is bounded above by $⅓ (1-t)+(2t/pi)x$.

Tagged : / / /

Server Bug Fix: port redirection on solaris 11

Original Source Link

I’m trying port forwarding on solaris 11. I have a mechine behind a server that use solaris 11. I try to access that mechine from the external port, and forwarded by solaris 11 mechine to that machine using the ip filter. I give ipnat.conf configuration like this:

rdr net0 0.0.0.0/0 port 1428 -> 10.1.18.178 port 22

but the response appeared when I tried to remote is connection time out, but if I redirect to a solaris 11 machine itself, the configuration is running well.

I’ve enabled IP forwarding on the system

[email protected]:/etc/ipf# ndd -get /dev/ip ip_forwarding
1

[email protected]:/etc/ipf# routeadm
              Configuration   Current              Current
                     Option   Configuration        System State
---------------------------------------------------------------
               IPv4 routing   enabled              enabled
               IPv6 routing   disabled             disabled
            IPv4 forwarding   enabled              enabled
            IPv6 forwarding   disabled             disabled

[email protected]:/etc/ipf# ipadm show-prop
PROTO PROPERTY              PERM CURRENT      PERSISTENT   DEFAULT      POSSIBLE
ipv4  forwarding            rw   on           on           off          on,off

is there any configuration that I missed?

I’m not sure but Oracle’s Solaris 11.1 documentation has this (see below).
It may be that you explcitly have to name an Ethernet interface or interfaces not just a protocol layer.
I’ll update this answer to confirm or alter the content as required when I get the time to repeat your activity.

# ipadm show-ifprop -p forwarding net0
IFNAME   PROPERTY     PROTO   PERM   CURRENT   PERSISTENT   DEFAULT   POSSIBLE
net0     forwarding   ipv4    rw     off       off          off       on,off
net0     forwarding   ipv6    rw     off       --           off       on,off

# ipadm set-ifprop -p forwarding=on -m ipv4 net0
# ipadm show-ifprop net0
IFNAME   PROPERTY         PROTO  PERM  CURRENT  PERSISTENT  DEFAULT   POSSIBLE
...
net0     forwarding       ipv4   rw    on       on          off       on,off
...

Tagged : / /

Ubuntu HowTo: Graphical way to install .flatpakref (Flatpak) files?

Original Source Link

I’ve been downloaded a file from MonoDevelop website but it couldn’t execute in my ubuntu, how to open that file?

filename is “monodevelop.flatpakref”

Ubuntu 14.04

Based on burhanuddin abbas comment there’s a problem on Ubuntu 14.04.

Unable to locate package flatpak , because it is not supported for ubuntu 14.04 . Visit here for more details

Newer Ubuntu versions (tested on 16.04)

1. Installation of flatpak

  1. sudo add-apt-repository ppa:alexlarsson/flatpak.
  2. sudo apt update.
  3. sudo apt install flatpak.

*1.1. Adding the flathub repository

flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo.

2. Installation of MonoDevelop with flatpakref file

flatpak install monodevelop.flatpakref.

3. Running the application

flatpak run com.xamarin.MonoDevelop (probably, not tested, based on @purlantov answer).


Source: http://www.omgubuntu.co.uk/2017/07/7-flatpak-apps-can-install-right-now-flathub .

This is very helpfull
Install MonoDevelop preview via FlatPak

It worked for me but any time that you want to start MonoDevelop you have to type in console:

flatpak run com.xamarin.MonoDevelop

And there is lot of things that do not work properly.
I suggest you to compile it your self.
This video help me a lot -> VIDEO

Unfortunately there is no longer pre-compiled package for Ubuntu.

A graphical way to install Flatpak app using .flatpakref file starts with installing flatpak plugin to add flatpak support into default software center.

For Debian-based GNOME desktop,

sudo apt install gnome-software-plugin-flatpak

For Debian-based KDE desktop,

sudo apt install plasma-discover-plugin-flatpak

You can change the package manager based on your supported Linux distro. However, most Linux distro comes with pre-configured support for Flatpak.

Now if you search for app in your software center, you’ll notice two application one with source pointing to flathub repo i.e. flatpak app.

Nonetheless, if you’ve already downloaded the .flatpakref file, it’s better to run a single command to install a flatpak app.

flatpak install --from <app-id>.flatpakref

Tagged : / / /

Code Bug Fix: Why is a Java BitSet packed in 6 bytes?

Original Source Link

I was looking into BitSet and the following are not clear to me:

  1. When we pass the number of bits there is a division by 6. Why is 6 being used and not some power of 2?
  2. When initializing the underlying array why is there first a subtraction by 1 before the division by 6 followed by an addition of 1?

I’m assuming you are asking about this bit of code in the JDK:

private static int wordIndex(int bitIndex) {
    return bitIndex >> ADDRESS_BITS_PER_WORD; // ADDRESS_BITS_PER_WORD is 6, question 1
}

public BitSet(int nbits) {
    // nbits can't be negative; size 0 is OK
    if (nbits < 0)
        throw new NegativeArraySizeException("nbits < 0: " + nbits);

    initWords(nbits);
    sizeIsSticky = true;
}

private void initWords(int nbits) {
    words = new long[wordIndex(nbits-1) + 1]; // question 2
}

initWords initialises a long[] to back the bits, essentially storing the bits into “words” of 64 bits. Note that this seems to be an implementation detail. How long should this long[] be? Well, it should be the word index of the last word + 1, because indices are zero-based.

What is the index of the last word? Well, the wordIndex method can tell us the word index of a bit, so if we give it the index of the last bit, nbits - 1 (again because indices are zero-based), it will give us what we want. This should answer your second question.

How does wordIndex find the word index? Well, there are 64 bits in a long, so we just need to divide the bitIndex by 64. What’s another way of dividing by 64? Shift left 6 times, since 64 = 2 to the power 6. See this post for more info.

I suppose you talk about the implementation of this class?

It says so in a comment in the source file:

    /*
     * BitSets are packed into arrays of "words."  Currently a word is
     * a long, which consists of 64 bits, requiring 6 address bits.
     * The choice of word size is determined purely by performance concerns.
     */

So from a given bit number, the lower 6 bits are used for addressing a bit withing a 64 bit word, and the remaining bits are for addressing the word.


For the point 2, I suppose you talk about

wordIndex(nbits-1) + 1

which is

bitIndex >> ADDRESS_BITS_PER_WORD
  • Suppose you want to initialize a BitSet with initially 0 entries. Then you need an array size of 0.
  • Suppose you want to initialize a BitSet with initially 1 to 64 entries. Then you need an array size of 1.
  • Suppose you want to initialize a BitSet with initially 65 to 128 entries. Then you need an array size of 2.

And so on.

This means, you map the original range (1-64, 65-128) to “one less” (0-63, 64-127), divide by 64 (0, 1) and increase the result again (1, 2) to get the number of needed words in the array.


To demonstrate both:

Suppose you want a BitSet with 128 entries. You initialize it and you get an array with 2 64 bit entries. Why?

That’s because wach word can hold 64 bits, so in order to hold 128 bits, you need 2 array entries:

(128-1)/64 + 1 = 127/64 + 1 = 1 + 1 = 2. (Remember that integer divisions go towards the lower value.)

Now, you want to set the bis 5, 13 and 66.

Bit 5 and 13 are fine – you just set bits 5 and 13 in the word at index 0.

But what do you do with the 66? Each word has only 64 bits! (0..63)

Well, in this situation, you substract 64 for each step you make in the array. So you go to word at index 1 and for “compensation”, you go from 66 to 2.

That’s exactly what happens with these bit manipulations: from each of these bit indexes, the lower 6 bits are taken and used as bit address in the respective word.

5 = 0 000101 = 0/5
13 = 0 001101 = 0/13
66 = 1 000001 = 1/2

So

  • 5 is set by setting bit 5 in the word 0.
  • 13 is set by setting bit 13 in the word 0.
  • 66 is set by setting bit 2 in the word 1.
Tagged : / / /

Linux HowTo: The seconds displayed on the Windows 10 lockscreen clock are not updating

Original Source Link

When I go to my lockscreen, Windows shows the time, but the seconds don’t update. I took a screencap of my lockscreen and highlighted in red the part that isn’t working. Basically, the minutes and hours update fine, but the seconds are stuck at whatever value it was when I locked the screen. When the minute updates, the seconds seem to get set to either 00 or 01. Switching to a 12-hour clock did not fix it.

Is there any way I can get the seconds working?

enter image description here

The lock screen displays the short time. By default a short time pattern does not include seconds.

The lock screen design is therefore based on the principle that displaying seconds is not necessary (and unexpected).


Edit: Added link to my submittal of this bug on the Feedback Hub: https://aka.ms/Fb6zs8

Hello The Supreme Leader,

Love your lockscreen background.

What you have done with the time format is the same thing I have done. It’s a semi-bug in Windows 10.

Reproduction Method:

  1. In a command prompt or Run dialog, launch the Intl.cpl (Region Control Panel)
  2. In the Short time drop-down box, you will see 5 entries “HH:mm:ss”,”HH:mm”, “h:mm tt”, “hh:mm tt”, and “H:mm”. “HH:mm:ss” is only showing up because that is the current setting. If you were to select any other options than “HH:mm:ss”, “HH:mm:ss” disappears from the menu choices and only 4 are available.
  3. Click on “Additional Settings…”
  4. Navigate to the Time tab.
  5. In the “Time formats” section, we see the Short time text box/drop-down menu. Here, if “HH:mm:ss” is still set, we see 5 options available. Likely, you did the same thing I did in the past. Originally only have 4 options available, I manually typed in “HH:mm:ss” and pressed apply to save that new value.
  6. After closing that customize format dialog, you will be able to press apply on the Region Control Panel dialog. If that dialog did NOT update to show “HH:mm:ss”, pressing Apply or OK again on this dialog will wipe the previous setting. Press cancel on this screen to close it.
  7. Relaunch Intl.cpl
  8. Navigate to the Administrative tab
  9. Click on “Copy settings…”
  10. Check the box for “Welcome screen and system accounts”
  11. Click OK to close the “Welcome screen and new accounts settings” dialog
  12. Click Cancel to close the Region Control Panel dialog. Now the lock screen upon boot-up and when your user account locks will show this time format.

Do you concur that this is either how you got here or that your settings represent this?

The taskbar does not show this, however, clicking on the clock brings up the time/calendar menu. This does show the clock and update every second. Strangely, each of my calendar appointments for tomorrow show seconds on the time. They are all wrong. In fact, each of the seconds shown are the same, and they were the value of the live clock when the menu loaded. So I loaded the menu at 43, and the clock shows 44.

Clearly Microsoft has not tested this all that well. Some parts of the OS are able to pick up on a custom time and update every second. Other parts are hard-coded to only update every one minute, or just flat out break and show incorrect data.

So now that we have all the data laid out for reference, back to your actual question. The lock screen is in fact properly querying the time format you have specified. It just is not updating at the proper interval.
I came across your post because I was looking for a way to manually modify the update rate to show the proper seconds on the clock. Sorry I don’t have a fix, but perhaps this documentation of the bug scenario will help us find a fix, or workaround.

Screenshot of Short time Time Format Drop-Down(combo box) in Windows 10 1703 15063

Windows 10 Time/Calendar pop-up menu showing live seconds on top and the seconds after each appointment. Note, the seconds on each appointment are all incorrect. They are only the value of seconds from the live clock.

This can be accomplished using the registry.

Powershell script:

New-PSDrive HKU Registry HKEY_CURRENT_USER

$registryPath = “HKU:SoftwareMicrosoftWindowsCurrentVersionExplorerAdvanced”

$Name = “ShowSecondsInSystemClock”

$value = “1”

New-ItemProperty -Path $registryPath -Name $name -Value $value -PropertyType DWORD -Force

This will require a reboot to take effect.

Disclaimer*
Please be aware that registry changes can have unfortunate consequences if not implemented properly. Use at your own risk.

You may also follow the guide found here:
https://www.howtogeek.com/325096/how-to-make-windows-10s-taskbar-clock-display-seconds/

Tagged : / /

Making Game: What is the location (skydrive) of an opened online office 365 document?

Original Source Link

I know that for normal office desktop application you can know where the application is located by going into the file Tab like as the tutorial said.

https://images.tips.net/S06/Figs/T4869F2.png

How about online office files opened in browser, how do i know what is the location of the file?

For office 365 you can click on the top link, then the location is shown.

enter image description here

They’re either stored on a OneDrive virtual folder or on a SharePoint “folder” (directory, more like), but in both cases, they’re in the cloud, and linked to a specific account.

You need credentials and/or permissions to access them (in the case of a SharePoint folder).

You can download a local copy of a document for ease of use if you want to edit it with your local Word or Excel, then upload it back into the cloud if you want. If the document is shared with others, and they too need to edit it while you are doing that on your PC, there might be data corruption, though.

Those documents are meant to be created, edited, saved and shared online.

Tagged : /

Math Genius: Prove $lim_{n to infty}int_0^1 dots int_0^1 f(sqrt[n]{x_1dots x_n})dx_1dots dx_n = f(frac{1}{e}).$ $f$ is continuous on $[0;1].$

Original Source Link

$f$ is continuous on $[0;1].$ Prove $$lim_{n to infty} underbrace{int_0^1 cdots int_0^1}_{n} f(sqrt[n]{x_1cdots x_n})mathrm , dx_1cdots mathrm dx_n = f(frac{1}{e}).$$

At first, I thought that we should get inside the function with the limit, but it’s probably restricted due to $dx_1dots dx_n$. I feel like I’m missing an important Theorem here. And yet it seems like the problem should be easy. Can somebody smart help me out here (at least with a hint) ?

Perhaps, it’s an induction method problem.

A short solution could be. Consider the random variables $u_1,…,u_n$ which they are i.i.d with density function $rho(u)=e^{-u}$ (exponential distribution with $lambda =1 $). So the expected value $E[u] = int^{infty}_{0}ucdot e^{-u}du = 1$. By law of large numbers $frac{S_n}{n}to E[u]=1$. Where $S_n := u_1+..+u_n$. Observe that
$$int_{0}^1dotsint_{0}^1f(sqrt[n]{x_1…x_n})dx_1dots dx_n = int_{0}^{infty}dotsint_{0}^{infty}f(e^{-frac{S_n}{n}}) e^{-u_1}du_1…e^{-u_n}du_n =E[f(e^{-frac{S_n}{n}})]$$
Finally by continuity and dominated convergence
$$E[f(e^{-frac{S_n}{n}})] xrightarrow{n} E[f(e^{-1})]=f(e^{-1}).$$

Here’s an elementary proof. Suppose $f(x) = x^k$ then we see that
begin{align}
int^1_0cdots int^1_0 dx_1cdots dx_n f(sqrt[n]{x_1cdots x_n})=& int^1_0cdots int^1_0 dx_1cdots dx_n left(sqrt[n]{x_1cdots x_n} right)^k\
=& left(int^1_0 dx x^{frac{k}{n}} right)^n = left(1+frac{k}{n} right)^{-n}.
end{align}

In particular, it follows
begin{align}
lim_{nrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n f(sqrt[n]{x_1cdots x_n}) = lim_{nrightarrow infty}left(1+frac{k}{n} right)^{-n} = left(frac{1}{e}right)^k.
end{align}

If $f$ is a polynomial, then it follows
begin{align}
lim_{nrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n f(sqrt[n]{x_1cdots x_n}) = fleft( frac{1}{e}right).
end{align}

Next, if $f$ is continuous, then, by Wierestrass approximation theorem, there exists a sequence of polynomials $p_m$ such that $p_m rightarrow f$ uniformly on $[0, 1]$. Finally, it follows
begin{align}
lim_{nrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n f(sqrt[n]{x_1cdots x_n}) =& lim_{nrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n lim_{mrightarrow infty}p_m(sqrt[n]{x_1cdots x_n})\
=& lim_{nrightarrow infty}lim_{mrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n p_m(sqrt[n]{x_1cdots x_n})\
=& lim_{mrightarrow infty}lim_{nrightarrow infty}int^1_0cdots int^1_0 dx_1cdots dx_n p_m(sqrt[n]{x_1cdots x_n})\
=& lim_{mrightarrow infty} p_mleft(frac{1}{e} right) = fleft(frac{1}{e} right).
end{align}

Tagged : / / /

Code Bug Fix: Delete a document from Firestore

Original Source Link

I am trying to delete a document from a collection called “photo” but it doesn’t work, there is no OnFailureException message as OnSuccess Toast is shown but the document still remain in the Firestore 🙁

Structure of the firestore:
enter image description here

This is the codes I use to delete the document:

        Photo photo = (Photo) getIntent().getSerializableExtra("photo");

        FirebaseFirestore db = FirebaseFirestore.getInstance();

        String userId = mAuth.getCurrentUser().getUid();

        CollectionReference photoRef = db.collection("main").document(userId).collection("photo");

DocumentReference document = photoRef.document(photo.getId());
                    String currentDocumentID = document.getId();
                    photoRef.document(currentDocumentID).delete().addOnSuccessListener(new OnSuccessListener<Void>() {
                        @Override
                        public void onSuccess(Void aVoid) {
                            Toast.makeText(ViewPhotoActivity.this, "Entry Deleted", Toast.LENGTH_SHORT).show();
                            startActivity(new Intent(ViewPhotoActivity.this, PhotoActivity.class));
                            finish();
                        }
                    }).addOnFailureListener(new OnFailureListener() {
                        @Override
                        public void onFailure(@NonNull Exception e) {
                            Toast.makeText(ViewPhotoActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                        }
                    });

I am writing the answer from speculation as there is not enough information as to how you are creating the document.

DocumentReference document = photoRef.document(photo.getId());

In the above line you are creating a reference to a document with photo id. Looking at the document data it seems the photo id is not same as the document id.

Therefore when you create the above reference- you are not referring to the existing document with id="2BMG3..." rather a NEW document with id="jYBPX..."

String currentDocumentID = document.getId();
photoRef.document(currentDocumentID).delete()

How you can fix it depends on how you want to save/create the documents. One way could be to create the documents in photo collection with id= photo id in the first place.

For example, when creating, you could create the document reference as following:

CollectionReference photoRef = db.collection("main")
                                .document(userId)
                                .collection("photo")
                                .document(photo.getId());

And then set the data as:

photoRef.set(photo);

That’d set the data to a document you have created with id=photo id.

These examples can be improved if you show how you’re adding documents to photo collection now. If you’ve been using .colection('photo').add() or .collection.document().set(photo) then the created document would have an auto-generated id different from the photo id.

I am sure there are several ways to do this which includes the answer I received above, the getID method is a little confusing to me as it doesn’t work sometimes or give me a null exception, so I changed my code and use a simpler way, which is to create a unique ID for each document when they are being created, then set the document Id with that unique ID so I could retrieve them easily, for this case, I created the ID by combining the title and 6 random digits.

When creating the document, I added a unique ID field for each document:

//set a unique ID for each photo
                String randomSixNumbers = getRandomNumberString();
                String photoId = (title.toLowerCase() + randomSixNumbers).replace(" ", "").trim();

//set ID to new object 
              Photo photo = new Photo(photoId, title, photoDescription, filePath, datePhoto);

//add object to firestore and set document ID as the uniqueID instead of the default auto-generated documentID                 
              photoRef.document(photoId).set(photo).addOnSuccessListener(...

delete the document using the unique ID:

photoRef.document(photo.getId()).delete().addOnSuccessListener(...

For now, this process seems okay, though I am not sure if it is a good practice or not? If not, could someone point out the downside/fault of this method?

And I noticed that I have to use intent to get the data passing from last activity to get the object data in current activity.

Tagged : /

Server Bug Fix: Ubuntu GRE local ip address, wan ip of router, or ip of ubuntu server

Original Source Link

I have an ubuntu server behind a router that I am configuring to have a GRE tunnel to another remote device across the interwebs.

in the config, I add the line:

pre-up iptunnel add tun1 mode gre local [local ip] remote [remote ip] ttl 255

Since the ubuntu server is behind a router, should the [local ip] be the wan ip of the router? or the actual local ip of the ethernet interface i wish the tunnel to connect through?

The router the server sits behind doesn’t say anywhere anything about forwarding GRE 47 to lan devices, so I just DMZ’d the server (no ideal in product, but I am just testing using GRE to allow for multicast discovery from 1 subnet to another)

Here is the full script (with local ip set as lan ip of ubuntu server)

auto tun1
iface tun1 inet static
    address 10.0.33.1
    netmask 255.255.255.0
    pre-up iptunnel add tun1 mode gre local 192.168.33.72 remote x.x.x.x ttl 255
    up ifconfig tun1 multicast pointopoint 10.0.33.2
    post-down iptunnel del tun1

The IP is the IP of the server and not the IP of router.
So let say you have 1.2.3.4/24 configured on eth0, with 1.2.3.1 being the the default gw/router, then the command would be:

iptunnel add tun1 mode gre local 1.2.3.4 remote x.x.x.x ttl y

Tagged : / /