Posts

Showing posts from June, 2008

Click Keys Ahk Code Example

Example: autohotkey hotkeys #^!s:: ;This occurs when pressed Windows Button+Control+Alt+s Send Sincerely,{enter}John Smith ; This line sends keystrokes to the active (foremost) window. return

Centos 7 Save Iptables Settings

Answer : Solution 1: Disable firewalld by the following command: systemctl disable firewalld Then install iptables-service by following command: yum install iptables-services Then enable iptables as services: systemctl enable iptables Now you can save your iptable rules by following command: service iptables save Solution 2: CentOS 7 is using FirewallD now! Use the --permanent flag to save settings. Example: firewall-cmd --zone=public --add-port=3000/tcp --permanent Then reload rules: firewall-cmd --reload Solution 3: On CentOS 7 Minimal you may need to install the iptables-services package (thanks to @RichieACC for the suggestion): sudo yum install -y iptables-services And then enable the service using systemd : sudo systemctl enable iptables.service And run the initscript to save your firewall rules: sudo /usr/libexec/iptables/iptables.init save Solution 4: iptables-save > /etc/sysconfig/iptables will save the current configuration wi

Wait System Call C Code Example

Example: wait function in c sleep ( /*How many seconds do you want to wait*/ ) ;

ChromeDriver - Disable Developer Mode Extensions Pop Up On Selenium WebDriver Automation

Answer : Did you try disabling the developer extensions with command line param? Try with the following Selenium WebDriver java code: System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--disable-extensions"); driver = new ChromeDriver(options); I cannot disable extensions because I'm developing & testing one. What I'm doing to dismiss this popup is the following: I load chrome with my extension using Selenium. I then immediately create a new window (via the SendKeys(Control-N) method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window. I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds. Then I close the tab via driver.Close(); (which also closes this new window). Chrome takes that as "cancel", dis

Avatar Last Airbender OC SI Code Example

Example 1: avatar the last airbender The best tv show! Example 2: avatar: the last airbender wait he deleted his reply he said "best show ever"

Addclassname Code Example

Example: javascript add class to element var someElement = document . getElementById ( "myElement" ) ; someElement . className += " newclass" ; //add "newclass" to element (space in front is important)

Check Value In Array Exists Flutter Dart

Answer : list.contains(x); Contains method Above are the correct answers to the current question. But if someone like me is here to check value inside List of Class object then here is the answer. class DownloadedFile { String Url; String location; } List of DownloadedFile List<DownloadedFile> listOfDownloadedFile = List(); listOfDownloadedFile.add(...); Now check if a specific value is inside this list var contain = listOfDownloadedFile.where((element) => element.Url == "your URL link"); if (contain.isEmpty) //value not exists else //value exists There maybe better way/approach. If someone know, then let me know. :) List<int> values = [1, 2, 3, 4]; values.contains(1); // true values.contains(99); // false Method - Contains of Iterable does exactly what you need. See the example above.

Python Create Directory Code Example

Example 1: python create directory # This requires Python’s OS module import os # 'mkdir' creates a directory in current directory . os . mkdir ( 'tempDir' ) # can also be used with a path , if the other folders exist . os . mkdir ( 'tempDir2/temp2/temp' ) # 'makedirs' creates a directory with it's path , if applicable . os . makedirs ( 'tempDir2/temp2/temp' ) Example 2: create a directory python # creates a directory without throwing an error import os def create_dir ( dir ) : if not os . path . exists ( dir ) : os . makedirs ( dir ) print ( "Created Directory : " , dir ) else : print ( "Directory already existed : " , dir ) return dir Example 3: create folder python import os # define the name of the directory to be created path = "/tmp/year" try : os . mkdir ( path ) except OSError : print ( "Creation of the directory %s failed&qu

Center Style Code Example

Example 1: css center text /* To center text, you need to use text-align. */ .centerText { text-align: center; /* This puts the text into the center of the screen. */ } /* There are also other things that you can use in text-align: left, right, and justify. Left and right make the test align to the right or left of the screen, while justify makes the text align both sides by spreading out spaces between some words and squishing others. */ Example 2: css text align center body { text-align: center; }

Appdata/Local/Packages- Safe To Remove?

Answer : AppData folders store per-user information for applications, so if you delete an applications data, it will have to recreate it from default values. In effect the program will forget that you have used it before, configuration choices you may have made, saved files (like game savefiles), etc. I would recommend you use a tool like windirstat to determine where the space is being used, and what application(s) rely on it. From there you can then begin to determine the impact of your proposed deletion. See here for some more information related to your query: http://www.pcworld.com/article/2690709/windows/whats-in-the-hidden-windows-appdata-folder-and-how-to-find-it-if-you-need-it.html If you use Windows Subsystem for Linux (WSL) you will blow away your entire file system for any linux distribution used if you delete this folder. At a quick glance that specific folder appears to be the location where the "per user" settings and state information for the Windows

Android Min SDK Version Vs. Target SDK Version

Answer : The comment posted by the OP to the question (basically stating that the targetSDK doesn't affect the compiling of an app) is entirely wrong! Sorry to be blunt. In short, here is the purpose to declaring a different targetSDK from the minSDK: It means you are using features from a higher level SDK than your minimum, but you have ensured backwards compatibility . In other words, imagine that you want to use a feature that was only recently introduced, but that isn't critical to your application. You would then set the targetSDK to the version where this new feature was introduced and the minimum to something lower so that everyone could still use your app. To give an example, let's say you're writing an app that makes extensive use of gesture detection. However, every command that can be recognised by a gesture can also be done by a button or from the menu. In this case, gestures are a 'cool extra' but aren't required. Therefore you would set

Bash: Bad Substitution

Answer : The default shell ( /bin/sh ) under Ubuntu points to dash , not bash . me@pc:~$ readlink -f $(which sh) /bin/dash So if you chmod +x your_script_file.sh and then run it with ./your_script_file.sh , or if you run it with bash your_script_file.sh , it should work fine. Running it with sh your_script_file.sh will not work because the hashbang line will be ignored and the script will be interpreted by dash , which does not support that string substitution syntax. I had the same problem. Make sure your script didnt have #!/bin/sh at the top of your script. Instead, you should add #!/bin/bash For others that arrive here, this exact message will also appear when using the env variable syntax for commands, for example ${which sh} instead of the correct $(which sh)

Android Microsoft Office Library (.doc, .docx, .xls, .ppt, Etc.)

Answer : Since most of the documents we need to display are already hosted on the web, we opted to use an embedded web view that opens the document using google docs viewer. We still have a few locally stored documents though that this approach doesn't work with. For these, our solution was to rely on the support of existing apps. After spending some more time with Android, It seems that most devices come equipped with some sort of document/pdf reading capability installed fresh out of the box. In the event that they don't have a capable app, we direct them to a market search for a free reader. Unfortunately there's no built in Android control to edit MS Office files, or even to display them! It's a pretty big omission given iOS has built in support for displaying Office files. There don't seem to be viewer app consistently enough available to rely on (and they may not provide the kind of user experience you're hoping for either). If you want to disp

Bind Jump Scroll Csgo Code Example

Example: csgo mouse wheel jump bind bind mwheelup + jump ; bind mwheeldown + jump ; bind space + jump

AlamoFire Download In Background Session

Image
Answer : Update Based on this amazing tutorial, I have put together an example project available on GitHub. It has an example for background session management. According to Apple's URL Loading System Programming Guide: In both iOS and OS X, when the user relaunches your app, your app should immediately create background configuration objects with the same identifiers as any sessions that had outstanding tasks when your app was last running, then create a session for each of those configuration objects. These new sessions are similarly automatically reassociated with ongoing background activity. So apparently by using the appropriate background session configuration instances, your downloads will never be "in flux". I have also found this answer really helpful. Original answer From Alamofire's GitHub page: Applications can create managers for background and ephemeral sessions, as well as new managers that customize the default ses

Cant Uninstall Eslint Code Example

Example: npm uninstall eslint npm uninstall < module_name >

Android Emulator Camera Custom Image

Image
Answer : Under Tools > AVD Manager , select the "pencil" to get to "Virtual Device Configuration". Show Advanced Settings > Camera will give you the option of using emulated, or a device: Device - use host computer webcam or built-in camera If all you need is to get a still image into the camera, starting with Android Studio 3.2 you can put your static images into the virtual scene: as discussed in this entry from Android developers blog. Note that you'll need to move the camera position into the dining room to see your images (turn around and use Alt-w to move forward). Finally! Append to file ~/Android/Sdk/emulator/resources/Toren1BD.posters poster custom size 2 2 position 0 0 -1.8 rotation 0 0 0 default custom.png Place 'custom.png' in ~/Android/Sdk/emulator/resources/ Restart! emulator @Phone -no-snapshot -no-boot-anim (replace 'Phone' with the name of your avd! (see: emulator -list-avds) Profit! Now you have a

Matlab Plot Line Color Code Example

Example: change plot line color in matplotlib plot ( x , y , color = 'green' , linestyle = 'dashed' , marker = 'o' , markerfacecolor = 'blue' , markersize = 12 ) .

Calculate Number Of Days Between Two Dates Using Moment In Angular Code Example

Example 1: momentjs number of days between two dates var given = moment("2018-03-10", "YYYY-MM-DD"); var current = moment().startOf('day'); //Difference in number of days moment.duration(given.diff(current)).asDays(); Example 2: moment check days of difference between days var a = moment([2007, 0, 29]); var b = moment([2007, 0, 28]); a.diff(b, 'days')

Angular Material Dialog: How To Update The Injected Data When They Change In The Parent Component?

Answer : You can just change data of the component instance, like this: this.dialogRef.componentInstance.data = {numbers: value}; Example here: https://stackblitz.com/edit/angular-dialog-update There are 2 ways I can think of at the moment, I don't really like either, but hey... Both ways involve sending an observable to the dialog through the data. You could pass on the observable of the part to the part component, and then pass the observable in the data to the dialog. The dialog could then subscribe to the observable and get the updates that way. AreaComponent @Component({ selector: 'app-area', template: '<app-part *ngFor="let part of planAsync$ | async; i as index" [partData]="part" [part$]="part$(index)"></app-part>' }) export class AreaComponent { plan = []; constructor(private wampService: WampService) { } part$(index) { return this.planAsync$ .map(plan => plan[index]);

Android - GetIntent() From A Fragment

Answer : You can use a getIntent() with Fragments but you need to call getActivity() first. Something like getActivity().getIntent().getExtras().getString("image") could work. It's not that you can't pass data, it's that you don't want to. From the Fragment documentation: Often you will want one Fragment to communicate with another, for example to change the content based on a user event. All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly. If you take a look at the Fragment documentation, it should walk you through how to do this. If you want get intent data, you have to call Fragment's method getArguments() , which returns Bundle with extras.

C Program Prime Number Code Example

Example 1: c program to check prime number using for loop # include <stdio.h> int main ( ) { int n , i , flag = 0 ; printf ( "Enter a positive integer: " ) ; scanf ( "%d" , & n ) ; for ( i = 2 ; i <= n / 2 ; ++ i ) { // condition for non-prime if ( n % i == 0 ) { flag = 1 ; break ; } } if ( n == 1 ) { printf ( "1 is neither prime nor composite." ) ; } else { if ( flag == 0 ) printf ( "%d is a prime number." , n ) ; else printf ( "%d is not a prime number." , n ) ; } return 0 ; } Example 2: prime number c # include <stdio.h> int main ( ) { int i , num , p = 0 ; printf ( "Please enter a number: \n" ) ; scanf ( "%d" , & num ) ; for ( i = 1 ; i <= num ; i ++ ) { if

Clear Console Java Does Not Open Code Example

Example 1: java clear console Runtime . getRuntime ( ) . exec ( "cls" ) ; Example 2: java clear console public static void clearScreen ( ) { System . out . print ( "\033[H\033[2J" ) ; System . out . flush ( ) ; }

Check The Total Number Of Parameters In A PyTorch Model

Answer : PyTorch doesn't have a function to calculate the total number of parameters as Keras does, but it's possible to sum the number of elements for every parameter group: pytorch_total_params = sum(p.numel() for p in model.parameters()) If you want to calculate only the trainable parameters: pytorch_total_params = sum(p.numel() for p in model.parameters() if p.requires_grad) Answer inspired by this answer on PyTorch Forums . Note: I'm answering my own question. If anyone has a better solution, please share with us. To get the parameter count of each layer like Keras, PyTorch has model.named_paramters() that returns an iterator of both the parameter name and the parameter itself. Here is an example: from prettytable import PrettyTable def count_parameters(model): table = PrettyTable(["Modules", "Parameters"]) total_params = 0 for name, parameter in model.named_parameters(): if not parameter.requires_grad: continue

Batch Character Escaping

Answer : This is adapted with permission of the author from the page Batch files - Escape Characters on Rob van der Woude's Scripting Pages site. TLDR Windows (and DOS) batch file character escaping is complicated: Much like the universe, if anyone ever does fully come to understand Batch then the language will instantly be replaced by an infinitely weirder and more complex version of itself. This has obviously happened at least once before ;) Percent Sign % % can be escaped as %% – "May not always be required [to be escaped] in doublequoted strings, just try" Generally, Use a Caret ^ These characters "may not always be required [to be escaped] in doublequoted strings, but it won't hurt": ^ & < > | Example: echo a ^> b to print a > b on screen ' is "required [to be escaped] only in the FOR /F "subject" (i.e. between the parenthesis), unless backq is used" ` is "required [to be es

How To Link Your Whatsapp Number Link To A Website Code Example

Example: link whatsapp to website < ! -- link the following URL to the desired icon or button in your code : https : //wa.me/PhoneNumber (see the example below) remember to include the country code -- > < a href = 'https://wa.me/27722840005' target = '_blank' > < i class = "fa fa-whatsapp" > < / i > < / a >

Android-studio: Unable To Locate Adb

Image
Answer : A couple of days after posting the above solution, the problem returned on my Windows system. Finally after several hours of investigation I think I have another solution for everyone having issues with AVD Manager "Unable to locate adb". I know we have the setting for the SDK in File -> Settings -> Appearance & Behavior -> System Settings -> Android SDK. This it seems is not enough! It appears that Android Studio (at least the new version 4) does not give projects a default SDK, despite the above setting. So, you also (for each project) need to go to File -> Project Structure -> Project Settings -> Project, and select the Project SDK, which is set to [No SDK] by default. If there's nothing in the drop-down box, then select New, select Android SDK, and navigate to your Android SDK location (normally C:\Users[username]\AppData\Local\Android\Sdk on Windows). You will then be able to select the Android API xx Platform. You now sho

Anaconda: Cannot Import Cv2 Even Though Opencv Is Installed (how To Install Opencv3 For Python3)

Answer : opencv is not compatible with python 3. I had to install opencv3 for python 3. The marked answer in how could we install opencv on anaconda? explains how to install opencv(3) for anaconda: Run the following command: conda install -c https://conda.binstar.org/menpo opencv I realized that opencv3 is also available now, run the following command: conda install -c https://conda.binstar.org/menpo opencv3 Edit on Aug 18, 2016: You may like to add the "menpo" channel permanently by: conda config --add channels menpo And then opencv can be installed by: conda install opencv (or opencv3) Edit on Aug 14, 2017: " clinicalgraphics " channel provides relatively newer vtk version for very recent python3 conda install -c clinicalgraphics vtk Edit on April 16, 2020 (based on @AMC's comment): OpenCV can be installed through conda-forge (details see here) conda install -c conda-forge opencv You can try conda install -c menpo opencv=3 Use this cod

Change Favicon Astra Wordpress Code Example

Example: wordpress change favicon 1. Log in to your WordPress website. 2. Click on ‘Appearance’ -> ‘Customize’. 3. Click on ‘Site Identity’. 4. Here you can define your site name, tagline, logo, and icon. The image you set under “Site Icon” will be used as your site’s favicon. reference : https://yoast.com/how-to-change-your-favicon-in-wordpress-a-step-by-step-guide/