Posts

Showing posts from August, 2011

Create A New Line In Java's FileWriter

Answer : If you want to get new line characters used in current OS like \r\n for Windows, you can get them by System.getProperty("line.separator"); since Java7 System.lineSeparator() or as mentioned by Stewart generate them via String.format("%n"); You can also use PrintStream and its println method which will add OS dependent line separator at the end of your string automatically PrintStream fileStream = new PrintStream(new File("file.txt")); fileStream.println("your data"); // ^^^^^^^ will add OS line separator after data (BTW System.out is also instance of PrintStream). Try System.getProperty( "line.separator" ) writer.write(System.getProperty( "line.separator" )); Try wrapping your FileWriter in a BufferedWriter : BufferedWriter bw = new BufferedWriter(writer); bw.newLine(); Javadocs for BufferedWriter here.

Change Bool Toggle Unity Code Example

Example: bool toggle unity c# private bool togl ; togl = ! togl ; //this is what changes the bool the the other state

Can I Produce A Row In Excel Which Is Random Permutation Of Another Row?

Image
Answer : Place the values in A1 through G1 In A2 through G2 enter: =RAND() In A3 through G3 enter: =INDEX($A$1:$G$1,MATCH(LARGE($A$2:$G$2,COLUMN()),$A$2:$G$2,0)) Each time the worksheet is re-calculated, a new permutation will be generated. I use a method similar to what Gary's Student posted, but I use RANK in my formula instead. I think this simplifies the formula and makes it a little easier to understand. For sample data in A1:G1 : dog mouse rhino ape cat fish rat Fill the formula =RAND() across A2:G2 . Then fill the formula below across A3:G3 . =INDEX($A$1:$G$1,RANK(A2,$A2:$G2)) This is good for a one-off or a small number of rows. For a more robust solution, I would use VBA. The macro below will allow you to select the values you want to shuffle and specify the number of permutations you'd like to create. The permutations will be printed to a new sheet, where you can copy and paste them wherever you like. Sub nP

Hai Naman Unko Lyrics In Hindi Song Code Example

Example 1: tu hi hai aashiqui song lyrics A great question on application of priority queues and heapsXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Example 2: tu hi hai aashiqui song lyrics best use of data strutures linked list and unordered_map together

Create React Native App Build Apk For Beginner Code Example

Example 1: build apk react native After run this in cmd react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/ cd android && ./gradlew assembleDebug then you can get apk app/build/outputs/apk/debug/app-debug.apk Example 2: react-native make android apk react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/

Cannot Install Signed Apk To Device Manually, Got Error "App Not Installed"

Image
Answer : You may be using the android 5.0 or above device. Just go to the Settings --> Apps --> Click on your App. ---> In App info page at the action bar menu there will be an option called " Uninstall for All users " click that. Your app will be completely uninstalled and now you can try installing the new version with no issue. Hope this will help you Check my solution from below link. Link 1 Hope it will help you. For Current Updated Android Studio 2.3 users this answer is for you as hardly people use eclipse nowadays for Android development as Android studio has huge advancements. So, Follow this way to create your Signed apk file. Build > Generate Signed apk . Create Keystore path . Put Password, alias, key password . Build type select accordingly(eg to release in playstore use release ). Signature Version select both V1 and V2 checkboxes. Finsih . Go to from explorer where you selected for the apk to store and you will see yo

Bootstrap Modal Close In Jquery Code Example

Example 1: close modal jquery $('#myModal').modal('toggle'); $('#myModal').modal('show'); $('#myModal').modal('hide'); Example 2: data-dismiss= modal in jquery $(document).ready(function(){ // Open modal on page load $("#myModal").modal('show'); // Close modal on button click $(".btn").click(function(){ $("#myModal").modal('hide'); }); }); Example 3: jquery close bootstrap model $('#modal').modal('hide'); Example 4: close bootstrap modal with javascript $('#myModal').modal('hide');

Materialize Css Margin Top Code Example

Example: materialize customize container .container { margin : 0 auto ; max-width : 1280 px ; width : 90 % ; } @media only screen and ( min-width : 601 px ) { .container { width : 85 % ; } } @media only screen and ( min-width : 993 px ) { .container { width : 70 % ; } }

Add Selected Attribute To Option In Select Menu With JQuery

Answer : As of jQuery 1.6 "To retrieve and change DOM properties such as the checked, selected, or disabled state of form elements, use the .prop() method." $("#someselect option[value=somevalue]").prop("selected", "selected") Edit: Select Option: $("#someselect option[value=somevalue]").prop("selected", true) Deselect Option: $("#someselect option[value=somevalue]").prop("selected", false) Check out this previous detailled answer on SO: If you really want to maitain HTML output with selected attribute, and not only have jQuery maitaining the right selectedIndex attribute on the select element, you can hack with original settAttr() function: select[0].options[select[0].selectedIndex].setAttribute('selected','selected'); But as soon as you keep using jQuery methods for val() or ':selected', you should'nt get any problem, you could have problem only if you were par

&amp Symbol In Html Code Example

Example: . and # in html <! DOCTYPE html > < html > < head > < style > .classname { background-color : green ; color : white ; } #idname { background-color : pink ; color : white ; } </ style > </ head > < body > < div class = " classname " > I am green colour < div > < div id = " idname " > I am pink colour </ div > </ body > </ html >

Confusion Matrix And Test Accuracy For PyTorch Transfer Learning Tutorial

Answer : Answer given by ptrblck of PyTorch community. Thanks a lot! nb_classes = 9 confusion_matrix = torch.zeros(nb_classes, nb_classes) with torch.no_grad(): for i, (inputs, classes) in enumerate(dataloaders['val']): inputs = inputs.to(device) classes = classes.to(device) outputs = model_ft(inputs) _, preds = torch.max(outputs, 1) for t, p in zip(classes.view(-1), preds.view(-1)): confusion_matrix[t.long(), p.long()] += 1 print(confusion_matrix) To get the per-class accuracy: print(confusion_matrix.diag()/confusion_matrix.sum(1)) Here is a slightly modified(direct) approach using sklearn's confusion_matrix:- from sklearn.metrics import confusion_matrix nb_classes = 9 # Initialize the prediction and label lists(tensors) predlist=torch.zeros(0,dtype=torch.long, device='cpu') lbllist=torch.zeros(0,dtype=torch.long, device='cpu') with torch.no_grad(): for i, (inputs, classes) in enumerate(da

9am Cst To India Time Code Example

Example: 1pm cst to ist 12.30 AM in India

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