Posts

Showing posts from February, 2011

Arduino Functions Bool Code Example

Example: arduino bool bool var = 0 or 1;

Checkout New Branch Git Code Example

Example 1: git command to create a branch //Create a New Branch git checkout -b [name_of_your_new_branch] //First Push git push --set-upstream origin [name_of_your_new_branch] Example 2: git checkout new branch // create and checkout new branch in one line git checkout -b new_branch Example 3: git branch and checkout at the same time $ git checkout -b < branch_name > Example 4: createa. branch off of development git //when on branch 'dev' make branch 'myFeature' off of 'dev' git checkout -b myFeature dev Example 5: git checkout branch truelover@PEACE project % git checkout master truelover@PEACE project % git checkout branch_name #create branch truelover@PEACE project % git checkout -b new_branch_name Example 6: make a new branch git git checkout -b branch-name

Codemirror Autocomplete After Any Keyup?

Answer : For version 5.7 neither of the previously proposed solutions work fine for me (and I think they have bugs even for earlier versions). My solution : myCodeMirror.on("keyup", function (cm, event) { if (!cm.state.completionActive && /*Enables keyboard navigation in autocomplete list*/ event.keyCode != 13) { /*Enter - do not open autocomplete list just after item has been selected in it*/ CodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); } }); How it works: This opens autocomplete popup only if it is not opened yet (otherwise keyboard-navigation would have caused reopening the popup with 1st item selected again). When you click Enter you want popup to close so this is special case of a character which shouldn't trigger autocompletion (you may consider a case when you want to show antocompletion for empty line though). Then last fix is setting completeSingle: false which

Can Linux Cat Command Be Used For Writing Text To File?

Answer : That's what echo does: echo "Some text here." > myfile.txt Sounds like you're looking for a Here document cat > outfile.txt <<EOF >some text >to save >EOF Here's another way - cat > outfile.txt >Enter text >to save press ctrl-d

BufferedReader Vs Console Vs Scanner

Answer : BufferedReader Since Java 1.1 Throws checked exceptions Can read chars, char arrays, and lines Fast Scanner Since Java 1.5 Doesn't throw checked exceptions Can read lines, whitespace-delimited tokens, regex-delimited tokens, and numbers Difficult to read single characters Console Since Java 1.6 Doesn't throw checked exceptions Can read lines Underlying reader can read chars and char arrays (stops at line bounds) Not always available (e.g. Eclipse) Can read passwords (i.e. read without displaying the characters) Recommendation: Scanner The methods for reading numbers are very useful. The exceptions are unchecked, so you do not have to write boilerplate try/catch blocks. Console class is implemented in a platform independent way to handle the console input for different Os. All OS has a console/shell but they are quite different in implementation. So Console class gives you a Java platform independent runtime class to access things like

Angular Refresh Page Without Reloading Code Example

Example 1: how to refresh page angular refresh ( ) : void { window . location . reload ( ) ; } Example 2: angular refresh page without reloading this . router . navigate ( [ 'path/to' ] ) . then ( ( ) => { window . location . reload ( ) ; } ) ; Example 3: angular reload component reloadCurrentRoute ( ) { let currentUrl = this . router . url ; this . router . navigateByUrl ( '/' , { skipLocationChange : true } ) . then ( ( ) => { this . router . navigate ( [ currentUrl ] ) ; } ) ; } Example 4: angular 6 reload current page import { DOCUMENT } from '@angular/common' ; import { Component , Inject } from '@angular/core' ; @ Component ( { selector : 'app-refresh-banner-notification' , templateUrl : './refresh-banner-notification.component.html' , styleUrls : [ './refresh-banner-notification.component.scss' ] } ) export class RefreshBanner

Checking If Element Exists With Python Selenium

Answer : a) from selenium.common.exceptions import NoSuchElementException def check_exists_by_xpath(xpath): try: webdriver.find_element_by_xpath(xpath) except NoSuchElementException: return False return True b) use xpath - the most reliable. Moreover you can take the xpath as a standard throughout all your scripts and create functions as above mentions for universal use. UPDATE : I wrote the initial answer over 4 years ago and at the time I thought xpath would be the best option. Now I recommend to use css selectors . I still recommend not to mix/use "by id", "by name" and etc and use one single approach instead. None of the solutions provided seemed at all easiest to me, so I'd like to add my own way. Basically, you get the list of the elements instead of just the element and then count the results; if it's zero, then it doesn't exist. Example: if driver.find_elements_by_css_selector('#element')

C Getline String Code Example

Example: getline cpp //getline allows for multi word input including spaces ex. "Jim Barens" # include <iostream> # include <string> int main ( ) { string namePerson { } ; // creating string getline ( cin , namePerson ) ; // using getline for user input std :: cout << namePerson ; // output string namePerson }

Cant's Change Animation State Of Animator From Script Unity Code Example

Example 1: how to change animator controller in script unity //STEP1: Inside the Assets folder, create a new folder called: Resources //STEP2: Now Create an Animation folder Inside the Resources folder //STEP3: Then put the Animator Controller inside this folder (for this examle we'll call the controller Bob) //STEP4: Now add this to the gamObject that holds the Animator componentAnimator animator; void Start() { animator = gameObject.GetComponent (); } void Update() { //I put it inside this If Statement to avoid Errors/Warnings but its not 100% necessary if(animator.gameObject.activeSelf) { animator.runtimeAnimatorController = Resources.Load("Animation/Bob") as RuntimeAnimatorController; //OR animator.runtimeAnimatorController = Resources.Load ("Animation/Bob"); } } Example 2: how to set an animator parameter through the animator unity //click the add behaviour button on a state in the animator controller //and add

Class 'ViewController' Has No Initializers In Swift

Answer : The error could be improved, but the problem with your first version is you have a member variable, delegate , that does not have a default value. All variables in Swift must always have a value. That means that you have to set it up in an initializer which you do not have or you could provide it a default value in-line. When you make it optional, you allow it to be nil by default, removing the need to explicitly give it a value or initialize it. The Swift Programming Language states: Classes and structures must set all of their stored properties to an appropriate initial value by the time an instance of that class or structure is created. Stored properties cannot be left in an indeterminate state. You can set an initial value for a stored property within an initializer, or by assigning a default property value as part of the property’s definition. Therefore, you can write: class myClass { var delegate: AppDelegate //non-optional variable

Calculating Median With Group By In AWS Redshift

Answer : The following will get you exactly the result you are looking for: SELECT distinct subject, median(num_students) over(partition by Subject) FROM course order by Subject; You simply need to remove the "over()" portion of it. SELECT subject, median(num_students) FROM course GROUP BY 1;

Youtube To M4 Code Example

Example 1: youtube to mp4 ytmp3 . cc is the best by far Example 2: youtube to mp4 flvto . biz is great for it

Yt Ot Mp3 Code Example

Example 1: youtube mp3 converter You can use WebTools , it's an addon that gather the most useful and basic tools such as a synonym dictionary , a dictionary , a translator , a youtube convertor , a speedtest and many others ( there are ten of them ) . You can access them in two clics , without having to open a new tab and without having to search for them ! - Chrome Link : https : //chrome.google.com/webstore/detail/webtools/ejnboneedfadhjddmbckhflmpnlcomge/ Firefox link : https : //addons.mozilla.org/fr/firefox/addon/webtools/ Example 2: yt to mp3 Youtube - DL works great . Download from https : //youtube-dl.org/. To use, type youtube-dl <url> --audio-format mp3 Example 3: youtube download mp3 I use https : //github.com/ytdl-org/youtube-dl/ as a Python CLI tool to download videos

Attempted Import Error: 'addLocaleData' Is Not Exported From 'react-intl'

Answer : I'm still investigating but it looks like addLocaleData was removed as a breaking change for v3. https://formatjs.io/docs/react-intl/upgrade-guide-3x This was a bit confusing for me too because a lot of the tutorials and guides out there still use addLocaleData.

Add "Appendix" Before "A" For Appendix A In Thesis TOC

Answer : Add the following to your preamble: \usepackage[titletoc]{appendix} \makeatletter \renewcommand\backmatter{ \def\chaptermark##1{\markboth{% \ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter: \fi ##1}{% \ifnum \c@secnumdepth > \m@ne \@chapapp\ \thechapter: \fi ##1}}% \def\sectionmark##1{\relax}} \makeatother The appendix package adds some extra functionality for dealing with appendices. This extra functionality (including the one you need) is accessed by using the \appendices environment instead of the \appendix command. So changing your thesis class \backmatter command to remove the \appendix command, along the with [titletoc] option of the package (which appends the appendix name to the letter in the TOC) should solve your problem. Now in your actual thesis tex file you should do the following: \backmatter \begin{appendices} \chapter{An appendix} ... \end{appendices} \bibliography{}

14 Minute Timer Code Example

Example: 20 minute timer for good eyesight every 20 minutes look out the window at something 20 feet away for 20 seconds

Long Long Int Range Cpp Code Example

Example 1: range of long long in c++ Long Data Type Size ( in bytes ) Range long int 4 - 2 , 147 , 483 , 648 to 2 , 147 , 483 , 647 unsigned long int 4 0 to 4 , 294 , 967 , 295 long long int 8 - ( 2 ^ 63 ) to ( 2 ^ 63 ) - 1 unsigned long long int 8 0 to 18 , 446 , 744 , 073 , 709 , 551 , 615 Example 2: data types in c++ int myNum = 5 ; // Integer (whole number) float myFloatNum = 5.99 ; // Floating point number double myDoubleNum = 9.98 ; // Floating point number char myLetter = 'D' ; // Character bool myBoolean = true ; // Boolean string myText = "Hello" ; // String

Axios Npm Tutorial Code Example

Example 1: axios npm $ npm install axios Example 2: axios npm const axios = require ( 'axios' ) ; // Make a request for a user with a given IDaxios.get ( '/user?ID=12345' ) .then ( function ( response ) { // handle success console.log ( response ) ; } ) .catch ( function ( error ) { // handle error console.log ( error ) ; } ) .then ( function ( ) { // always executed } ) ; // Optionally the request above could also be done asaxios.get ( '/user' , { params: { ID: 12345 } } ) .then ( function ( response ) { console.log ( response ) ; } ) .catch ( function ( error ) { console.log ( error ) ; } ) .then ( function ( ) { // always executed } ) ; // Want to use async/await? Add the ` async ` keyword to your outer function/method.async function getUser ( ) { try { const response = await axios.get ( '/user?ID=12345' ) ; console.log ( response ) ; } catch

Adding Borders To GridPane JavaFX

Answer : Don't use setGridLinesVisible(true) : the documentation explicitly states this is for debug only. Instead, place a pane in all the grid cells (even the empty ones), and style the pane so you see the borders. (This gives you the opportunity to control the borders very carefully, so you can avoid double borders, etc.) Then add the content to each pane. You can also register the mouse listeners with the pane, which means you don't have to do the ugly math to figure out which cell was clicked. The recommended way to apply a border to any region is to use CSS and a "nested background" approach. In this approach, you draw two (or more) background fills on the region, with different insets, giving the appearance of a border. So for example: -fx-background-fill: black, white ; -fx-background-insets: 0, 1 ; will first draw a black background with no insets, and then over that will draw a white background with insets of 1 pixel on all sides, giving the appea

Can Scp Create A Directory If It Doesn't Exist?

Answer : This is one of the many things that rsync can do. If you're using a version of rsync released in the past several years,¹ its basic command syntax is similar to scp :² $ rsync -r local-dir remote-machine:path That will copy local-source and its contents to $HOME/path/local-dir on the remote machine, creating whatever directories are required.³ rsync does have some restrictions here that can affect whether this will work in your particular situation. It won't create multiple levels of missing remote directories, for example; it will only create up to one missing level on the remote. You can easily get around this by preceding the rsync command with something like this: $ ssh remote-host 'mkdir -p foo/bar/qux' That will create the $HOME/foo/bar/qux tree if it doesn't exist. It won't complain or do anything else bad if it does already exist. rsync sometimes has other surprising behaviors. Basically, you're asking it to figure