Posts

Showing posts from November, 2003

Android MediatorLiveData Observer

Answer : This answer is largely reproduction of what @CommonsWare has already shared in the comment section above. In order for the callback on MediatorLiveData's addSource method to be triggered, the MediatorLiveData object needs to be observed itself as well. The logic behind this is that the 'mediator' mediates between a LiveData object that it observes, and a final consumer of the data. The mediator is hence an observer and observable simultaneously, and the callback on addSource won't be triggered for the mediator when there are no active observers. As an example; according to Google's Android Architecture Components, an activity or fragment could have an observer observing a mediator on the ViewModel, which in turn may observe other LiveData objects that are handled within the ViewModel or a referenced to an utility class. @CommonsWare pointed out the use of the Transformation class that exposes methods map and switchMap , but these were not

Clear All Variables Python Code Example

Example: how to clear all local variables in python % reset ##to remove everything in iPython, Then system will ask you to confirm type 'y' then

Git Pull To Remote Branch Code Example

Example 1: pull remote branches git fetch origin git checkout -- track origin / < remote_branch_name > Example 2: pull down remote branch git git fetch origin git checkout -- track origin / < branch_name > Example 3: how to pull remote branch into local branch git fetch origin < branch - name > Example 4: git pull a new branch froma remote repo git checkout -- track origin / daves_branch Example 5: how to pull from a branch in git git pull origin other - branch

Cobol Hello World Program Code Example

Example: hello world in cobol $ vim helloworld IDENTIFICATION DIVISION. PROGRAM-ID. HELLO-WORLD. * simple hello world program PROCEDURE DIVISION. DISPLAY 'Hello world!'. STOP RUN.

Cmd Runas Administrator Code Example

Example 1: how to run cmd run administrator using script @echo off break off title C: \ Windows \ system32 \ cmd.exe cls :cmd set /p cmd = C: \ Enter Command: %cmd% echo. goto cmd Example 2: how to run cmd run administrator using script Set objShell = CreateObject ( “Shell.Application” ) Set objWshShell = WScript.CreateObject ( “WScript.Shell” ) Set objWshProcessEnv = objWshShell.Environment ( “PROCESS” ) objShell.ShellExecute “C: \ Windows \ system32 \ cmd.exe”, “/k”, “”, “runas”

C++ - Split String By Regex

Answer : #include <regex> std::regex rgx("\\s+"); std::sregex_token_iterator iter(string_to_split.begin(), string_to_split.end(), rgx, -1); std::sregex_token_iterator end; for ( ; iter != end; ++iter) std::cout << *iter << '\n'; The -1 is the key here: when the iterator is constructed the iterator points at the text that precedes the match and after each increment the iterator points at the text that followed the previous match. If you don't have C++11, the same thing should work with TR1 or (possibly with slight modification) with Boost. To expand on the answer by @Pete Becker I provide an example of resplit function that can be used to split text using regexp: #include <regex> std::vector<std::string> resplit(const std::string & s, std::string rgx_str = "\\s+") { std::vector<std::string> elems; std::regex rgx (rgx_str); std::sregex_token_iterator iter(s.begin(

Ariel Font Family Code Example

Example 1: nunito font family To embed a font , copy the code into the <head> of your html <link href= "https://fonts.googleapis.com/css2?family=Nunito:wght@200&display=swap" rel= "stylesheet" > font-family : 'Nunito' , sans-serif ; Example 2: css font family Pittsburgh , PA

Change The Mode While Copying File In Python Code Example

Example: copy file in python3 import shutil original = r'original path where the file is currently stored\file name.file extension' target = r'target path where the file will be copied\file name.file extension' shutil . copyfile ( original , target )

Change GIT Account Of Visual Studio Team Explorer

Image
Answer : Look in the Windows Credential manager and remove/update your credentials there: In my case just removing credentials from Windows Credential didn't fix it. I first removed all git and azure related accounts from Windows Credential, then removed accounts from VS>Files>Account Settings, and then VS asked me new credentials and connected to the project. But my commits were still made with the old account! Finally I found out that it was the git config: C:\Users\[USER NAME]\.gitconfig I deleted the whole user section in that file which looks like this: [user] name = [OLD ACCOUNT NAME] email = [OLD ACCOUNT EMAIL] On next commit VS asked me git account information and done. If you want to work with different accounts for different projects on same machine, read this. I am using VS 2017 and this is how I updated my Password for TFS, using Git repository. From the Menu: Team -> manage Connection Click on Manage Connection Link -> Connect

Base64 Encode A Javascript Object

Answer : From String to Base-64 var obj = {a: 'a', b: 'b'}; var encoded = btoa(JSON.stringify(obj)) To decode back to actual var actual = JSON.parse(atob(encoded)) For reference look here. https://developer.mozilla.org/en/docs/Web/API/WindowBase64/Base64_encoding_and_decoding You misunderstood the Buffer(str, [encoding]) constructor, the encoding tells the constructor what encoding was used to create str , or what encoding the constructor should use to decode str into a byte array. Basically the Buffer class represents byte streams, it's only when you convert it from/to strings that encoding comes into context. You should instead use buffer.toString("base64") to get base-64 encoded of the buffer content. let objJsonStr = JSON.stringify(obj); let objJsonB64 = Buffer.from(objJsonStr).toString("base64");

C++ Cstring Find Character C++ Code Example

Example 1: find character in string c++ auto char_to_find = 'a' if ( str . find ( char_to_find ) != std :: string :: npos ) { // character found } Example 2: std string find character c++ // string::find # include <iostream> // std::cout # include <string> // std::string int main ( ) { std :: string str ( "There are two needles in this haystack with needles." ) ; std :: string str2 ( "needle" ) ; // different member versions of find in the same order as above: std :: size_t found = str . find ( str2 ) ; if ( found != std :: string :: npos ) std :: cout << "first 'needle' found at: " << found << '\n' ; found = str . find ( "needles are small" , found + 1 , 6 ) ; if ( found != std :: string :: npos ) std :: cout << "second 'needle' found at: " << found << '\n' ;

Attack On Titan Gif Code Example

Example: giraffe titan attack on titan SPOILER: What if every titan shifters and former titan shifters owners who are mentionned represents a titan ? I mean, there are clues as : - A dinosaur bites another one at the neck for a frame and then the next one shows Ymir's titan biting a titan's neck, as Ymir owns "Jaws" (this is the only name given for this titan at the moment) and the main weapon of a T-Rex are its jaws, few seconds later, we can see a T-Rex next to Zeke/Sieg. - Eren is fighting Reiner which are respectively Offensive Titan and Armored Titan, before panthers (I guess) are attacking a Buffalo. And panthers are known for their aggressiveness as buffalos for their tough skin, also we can see at the very right of the animal group (from backwards) a tiger that could be related to the panthers, and an hippo in the middle-right that can also be related to the buffalo. - (This one is pure guesssing) but the whale is the biggest animal alive, and it coul

13,8cm To Inches Code Example

Example: cm to inch 1 cm = 0.3937 inch

Ceiling Php Code Example

Example 1: php round up //round up to nearest integer echo ( ceil ( 0.60 ) . "<br>" ) ; //result 1 Example 2: php round up <?php echo 'Rounding modes with 9.5' . PHP_EOL ; var_dump ( round ( 9.5 , 0 , PHP_ROUND_HALF_UP ) ) ; var_dump ( round ( 9.5 , 0 , PHP_ROUND_HALF_DOWN ) ) ; var_dump ( round ( 9.5 , 0 , PHP_ROUND_HALF_EVEN ) ) ; var_dump ( round ( 9.5 , 0 , PHP_ROUND_HALF_ODD ) ) ; echo 'Rounding modes with 8.5' . PHP_EOL ; var_dump ( round ( 8.5 , 0 , PHP_ROUND_HALF_UP ) ) ; var_dump ( round ( 8.5 , 0 , PHP_ROUND_HALF_DOWN ) ) ; var_dump ( round ( 8.5 , 0 , PHP_ROUND_HALF_EVEN ) ) ; var_dump ( round ( 8.5 , 0 , PHP_ROUND_HALF_ODD ) ) ; ?>

Advantages Of Using Bundle Instead Of Direct Intent PutExtra() In Android

Answer : It makes little (if any difference). The code using an additional bundle is slightly heavier (it won't make any difference in any practical application) and slightly easier to manage, being more general. If one day you decide that - before sending information inside an intent - you want to serialize the data to database - it will be a bit cleaner to have a bundle that you can serialize, add to an intent and then feed to a PendingBundle - all with one object. [update] A clarification (because of some other answers). Extras is an additional bundle that each Intent might carry (but doesn't have to), so there is no alternative between using a bundle or not using it. You are using a bundle either way. The first time you use putExtra , a mExtras bundle inside Intent is initialized and all the following putExtra are delegated to it. The bundle itself is inaccessible to you (this is by design, to avoid certain kind of bugs). putExtras does not put your bundle