Posts

Showing posts from December, 2018

Asyncio.gather Vs Asyncio.wait

Answer : Although similar in general cases ("run and get results for many tasks"), each function has some specific functionality for other cases: asyncio.gather() Returns a Future instance, allowing high level grouping of tasks: import asyncio from pprint import pprint import random async def coro(tag): print(">", tag) await asyncio.sleep(random.uniform(1, 3)) print("<", tag) return tag loop = asyncio.get_event_loop() group1 = asyncio.gather(*[coro("group 1.{}".format(i)) for i in range(1, 6)]) group2 = asyncio.gather(*[coro("group 2.{}".format(i)) for i in range(1, 4)]) group3 = asyncio.gather(*[coro("group 3.{}".format(i)) for i in range(1, 10)]) all_groups = asyncio.gather(group1, group2, group3) results = loop.run_until_complete(all_groups) loop.close() pprint(results) All tasks in a group can be cancelled by calling group2.cancel() or even all_groups.cancel() . See also .gather

Changing The PuTTY Character Set For All Saved Sessions

Answer : I just had the same problem and found PuTTY session manager: PuTTY Session Manager is a tool that allows system administrators to organise their PuTTY sessions into folders and assign hotkeys to favourite sessions. Multiple sessions can be launched with one click. Requires MS Windows and the .NET 2.0 Runtime. It allows you to configure specific attributes of all sessions at once while leaving the distinct elements alone. PuTTY Session Manager has no documentation, so here are instructions (correct as of version 0.50.189.0): In PuTTY, load the default settings, change the settings you need, and save it as the default again. Install PuTTY session manager (if you don't already have it) and start it. Right click the PuTTY Session Manager icon in the system tray, and choose "Session Editor" Select all sessions and click "Copy Session" at the bottom of the window. Make sure the "Choose Session Template" dropdown is set to "Default

Collapse Grid Row In WPF

Answer : All you need is something to cache the height(s) of the visible row. After that, you no longer need converters or to toggle visibility of contained controls. CollapsibleRow public class CollapsibleRow : RowDefinition { #region Fields private GridLength cachedHeight; private double cachedMinHeight; #endregion #region Dependency Properties public static readonly DependencyProperty CollapsedProperty = DependencyProperty.Register("Collapsed", typeof(bool), typeof(CollapsibleRow), new PropertyMetadata(false, OnCollapsedChanged)); private static void OnCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if(d is CollapsibleRow row && e.NewValue is bool collapsed) { if(collapsed) { if(row.MinHeight != 0) { row.cachedMinHeight = row.MinHeight; row.MinHeight = 0; }

C++ String Cpy Code Example

Example: c++ string # include <string> std :: string myString = "Hello, World!" ;

Bootstrap Icons Fa Download Code Example

Example: download icon font awesome < i class = " fa fa-download " aria-hidden = " true " > </ i >

Authentication Failed When Using Flask_pymongo

Answer : This question may be old, but I was experiencing the same issue and found another solution that might work for others. Appending ?authSource=admin to the end of your MONGO_URI variable will authenticate your credentials against the admin database, rather than the one you're connecting to. Example: app.config["MONGO_URI"] = "mongodb://username:password@host:port/db_name?authSource=admin" The problem is if you use the MONGO_URI config parameter then pymongo attempts to authenticate against the db name included in the string. You should break up the config parameters into the following so you can specify a db name and an auth source. app.config['MONGO_HOST'] = 'localhost' app.config['MONGO_PORT'] = '27017' app.config['MONGO_DBNAME'] = 'mongo_test' app.config['MONGO_USERNAME'] = 'root' app.config['MONGO_PASSWORD'] = 'aaa2016' app.config['MONGO_AUTH_SOURCE']

Can't See My Device Of Chrome://inspect/#devices

Answer : Try these steps: Download and install Android SDK Open SDK Manager.exe Select Android SDK Platform-tools and press Install packages... Open a command prompt and execute these commands: cd C:\Program Files(x86)\Android\android-sdk\platform-tools (or C:\Users\User\AppData\Local\Android\Sdk\platform-tools ) adb.exe devices You should receive a response like this: List of devices attached ABCDEFG123 device If your device is listed check if Chrome detect the device, otherwise try to execute this command: adb.exe kill-server adb.exe start-server adb.exe devices Check again if Chrome detect the device. If your device is not listed at all after executing adb devices command there is something wrong in your configuration (e.g. incorrect or missing drivers?) Hope this helps somebody else... This happened to me because I was trying to Chrome inspect a release build (Ionic; i.e. ionic build android --release ). If I build a debug app ( ionic build andr

Anyone Seen A Meaningful SAS Vs SATA Comparison/benchmark?

Answer : Solution 1: IOPs is the difference your looking for in the "speed". The simple way to explain the difference is that SATA is half duplex and SAS is full duplex. SATA drives are dumb and have to communicate with the controller for operations. SAS drives are smart and only requests and returns use the bus. Depending on your usage case, spending more may not gain much.. Solution 2: The "SATA = 7.2K RPM, SAS = 10/15K RPM" mind-set is strong, and (in my opinion anyway) where most of the "SAS is faster than SATA" thinking comes from. There are some slight differences between SAS and SATA drives, notably in their on-board caching algorithms (NCQ vs. TCQ). However, the performance difference of equivalently specced hard-drives will be fractional percentage points in most use-cases. Solution 3: This is only a single anecdote, but I did some performance comparisons a while back for sequential read/write speeds on Seagate Barracuda ES.2 SATA a

Git Fetch And Checkout Remote Branch Code Example

Example 1: git checkout to remote branch $ git checkout -- track origin / newsletter Branch newsletter set up to track remote branch newsletter from origin . Switched to a new branch 'newsletter' Example 2: git checkout remote branch git checkout -- track origin / < branchname > Example 3: pull down remote branch git git fetch origin git checkout -- track origin / < branch_name > Example 4: git checkout remote branch # In modern versions of Git , you can checkout the remote branch like a local branch . git checkout < remotebranch > # Older versions of Git require the creation of a new branch based on the remote . git checkout < remotebranch > origin / < remotebranch > Example 5: git get remote branch git fetch git checkout test

Know Array Size Python Code Example

Example 1: size array python size = len ( myList ) Example 2: python get array length # To get the length of a Python array , use 'len()' a = arr . array ( ‘d’ , [ 1.1 , 2.1 , 3.1 ] ) len ( a ) # Output : 3

Chrome Not Asking To Remember Passwords

Answer : From Google's help: Make Chrome ask to save passwords again If you told Chrome to never offer to save your password for a specific site, but you change your mind, you can bring back the option. On your computer, open Chrome. At the top right, click More More and then Settings. At the bottom, click Show advanced settings. Under "Passwords and forms," click Manage passwords. A box will appear with a list of saved passwords. In the "Never saved" section, select the website and click Delete Delete. Click Done. If Chrome isn't asking to save any passwords anymore, you may have asked it to stop saving passwords. Bring back the prompt by turning "Offer to save your web passwords" back on. Chrome isn't saving passwords If you've told Chrome to save a password but it's not showing up, try deleting and resaving it. Open your list of saved passwords, and check for the website.

Android - Emulator Takes A Long Time To Start Up

Answer : The emulator is just slow, there is not much you can do about it. See https://stackoverflow.com/questions/1554099/slow-android-emulator To maximize the accuracy between emulator and real devices, Google emulator uses ARM opcode, a kind of machine language. It must convert from ARM opcode to Intel opcode. That's why it's slow. My computer is 3GB RAM but it's still slow and lagged. The problem seems not to be RAM but CPU. Improving CPU will improve the emulator. To use emulator more effectively, this is my experience: Don't close emulator everytime you run your application. Scale the emulator screen smaller. Disable snapshot (Yes, it's useful but it takes time to close the emulator). Specify a file path for SD card image file. I use only one SD card for many AVDs. If you got any problems in adb, just reset adb, don't close emulator. Open few programs in your operating sytem. If you are using Windows, don't ever close emulator. Do it c

Bootstrap Studio 4 Download Free Code Example

Example: bootstrap studio download You can download bootstrap studio by refering below link https://bootstrapstudio.io/download By following the link you just need to select your OS And then you can download you OS Compatible bootstrap studio.

Circular Image Border Css Code Example

Example 1: convert image in rounshape in css img { border-radius: 50%; } Example 2: rounded scrolling images < div class = " MagicScroll " data-options = " loop: rewind; " > < img src = " example1.jpg " /> < img src = " example2.jpg " /> ... </ div >

81 Divided By 4 Code Example

Example: 81 divided by 4 81 divided by 4 = 20.25

Bitbucket Pipelines - Multiple Branches With Same Steps

Answer : A comma-separated list inside braces appears to work: pipelines: branches: '{rev,staging}': - step: script: - echo 'step' This is a full example on how you can reuse some steps: image: yourimage:latest definitions: services: ... # Service definitions go there steps: - step: &Test-step name: Run tests script: - npm install - npm run test - step: &Deploy-step name: Deploy to staging deployment: staging script: - npm install - npm run build - fab deploy pipelines: default: - step: *Test-step - step: *Deploy-step branches: master: - step: *Test-step - step: <<: *Deploy-step deployment: production trigger: manual Read more about YAML anchors: https://confluence.atlassian.com/bitbucket/yaml-anchors-960154027.html Instead of interpreting rev|

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Answer : VACUUM is only needed on updated or deleted rows in non-temporary tables. Obviously you're doing lots of INSERTs but it's not obvious from the description that you're also doing lots of UPDATEs or DELETEs. These operations can be tracked with the pg_stat_all_tables view, specifically the n_tup_upd and n_tup_del columns. Also, even more to the point, there is a n_dead_tup column that tells, per table, how much rows need to be vacuumed. (see Monitoring statistics in the doc for functions and views related to statistics gathering). A possible strategy in your case would be to suppress the scheduled VACUUM, keeping an eye on this view and checking on which tables the n_dead_tup is going up significantly. Then apply the aggressive VACUUM to these tables only. This will be a win if there are large tables whose rows never get deleted nor updated and the aggressive VACUUM is really necessary only on smaller tables. But keep running the ANALYZE for the optimiz

Bootstrap Toaster Code Example

Example 1: bootstrap toast <!-- Bootstrap 5 Toasts --> < div class = " toast " role = " alert " aria-live = " assertive " aria-atomic = " true " > < div class = " toast-header " > < img src = " ... " class = " rounded me-2 " alt = " ... " /> < strong class = " me-auto " > Bootstrap </ strong > < small > 11 mins ago </ small > < button type = " button " class = " btn-close " data-bs-dismiss = " toast " aria-label = " Close " > </ button > </ div > < div class = " toast-body " > Hello, world! This is a toast message. </ div > </ div > Example 2: boostrap toast <!-- Flexbox container for aligning the toasts --> < div aria-live = " polite " ari

Apt Install Npm Unable To Correct Problems, You Have Held Broken Packages. Code Example

Example 1: Unable to correct problems, you have held broken packages. sudo apt-get install -f sudo dpkg --configure -a Example 2: Unable to correct problems, you have held broken packages $ sudo dpkg --list then look for a package with the name of the one you're trying to install eg mysql and purge them by name. I repeat by name. $sudo apt-get purge < package name >

Calculating R^2 For A Nonlinear Least Squares Fit

Answer : You just use the lm function to fit a linear model: x = runif(100) y = runif(100) spam = summary(lm(x~y)) > spam$r.squared [1] 0.0008532386 Note that the r squared is not defined for non-linear models, or at least very tricky, quote from R-help: There is a good reason that an nls model fit in R does not provide r-squared - r-squared doesn't make sense for a general nls model. One way of thinking of r-squared is as a comparison of the residual sum of squares for the fitted model to the residual sum of squares for a trivial model that consists of a constant only. You cannot guarantee that this is a comparison of nested models when dealing with an nls model. If the models aren't nested this comparison is not terribly meaningful. So the answer is that you probably don't want to do this in the first place. If you want peer-reviewed evidence, see this article for example; it's not that you can't compute the R^2 valu

Android Studio 2.2.2: All Packages Are Not Available For Download

Answer : I was facing the same issue. For me, it got resolved by setting proxy settings. Android Studio > File > Settings >appearance and behavior> System Settings > HTTP Proxy I would suggest checking any proxy is required to enable internet for your android studio. Hope this will help somebody. Open Android SDK Manager Click on Tools. Click on Android. Click on SDK Manager. Update your SDK's Then Sync ,Re-Build and Restart Your Project "Launch Standalone SDK Manager" is not available in newer versions. Just select "SDK Tools" tab, then "Android SDK Build-Tools and place a check next to 23.0.1, 23.0.2, 23.0.3, etc. and any others you may want to install. Select Apply and when complete, press Finish. Rebuild and see if that helps.

Check Laravel Version Code Example

Example 1: check laravel version php artisan --version Example 2: show version laravel php ./artisan --version ##or php artisan --version Example 3: how to check laravel version in cmd $php artisan --version Example 4: laravel check my laravel version php artisan --version //enter in terminal Example 5: check laravel version cmd laravel version Example 6: check laravel version php artisan --version

Can I Boot Linux From A VHD?

Answer : yes, We just released a sample Linux VHD that you can boot any computer. You can find more info here: Download and boot your physical PC, also runs as vm - http://www.vmlite.com/index.php/forums/17-vboot/1864-linux-vhd-boot-available-download-and-boot-your-physical-pc-also-runs-as-vm 1 Linux as Real Appliance With VBoot for Linux, you can pre-install and pre-configure Linux OS and its applications, then distribute the resulting virtual disk file in VHD format. The vhd can boot a real computer, with configuration and apps instantly available. This way, operating systems are truly manageable, as simple as files. We call such a Linux VHD to be a real appliance, in the sense that it boots physical computers. It's very easy to setup and boot a computer with a vhd file. You download the vhd file, drop it to Windows or Linux file system, then configure the boot loader, and reboot the computer. 2 Linux as Virtual Appliance The exact same vhd file also runs as a vi

Ansible And Git Permission Denied (publickey) At Git Clone

Answer : By reading the documentation for ssh forwarding in ansible. I was able to figure out the solution. The problem was that my ssh keys were not being forwarded because Ansible does not by default forward your keys, even if you have set up the key forwarding on ~/.ssh/conf (I updated my question with the ansible.cfg that I had before fixing the issue). The solution is was to add transport = ssh to ansible.cfg under [defaults] plus running ansible-playbook from the location where ansible.cfg is located and make sure thet the following setting exists in the /etc/ssh/sshd_config of the target box: AllowAgentForwarding yes My ansible.cfg now looks like this: [defaults] transport = ssh [ssh_connection] ssh_args = -o ForwardAgent=yes To clone the private github repo over the remote server, I am doing this: First add the ssh key to your ssh-agent: eval `ssh-agent -s` ssh-add ~/.ssh/my-private-key.pem After that I have modified the ansible.cfg : [defaults]

Changing Order Of Ordered Dictionary In Python

Answer : OrderedDicts are ordered by insertion order. So you would have to construct a new OrderedDict by looping over the key:value pairs in the original object. There is no OrderedDict method that will help you. So you could create a tuple to represent the idea order of the keys , and then iterate over that to create a new OrderedDict . key_order = ('animal', 'people', 'food', 'drink') new_queue = OrderedDict() for k in key_order: new_queue[k] = queue[k] Or more eloquently OrderedDict((k, queue[k]) for k in key_order) Edit: You can write a custom function (warning, this works but is very quick and dirty): EDIT: Fixed bug that occurs when you try to move forward import collections def move_element(odict, thekey, newpos): odict[thekey] = odict.pop(thekey) i = 0 for key, value in odict.items(): if key != thekey and i >= newpos: odict[key] = odict.pop(key) i += 1 return odict queue =