Posts

Showing posts from May, 2012

Can I Profile NodeJS Applications Using Visual Studio Code?

Image
Answer : There is no plugin/support that I am aware of for initiating the profiling, or heap dumps, etc that are available in Chrome's Dev Tools. But, the VS Code debugger can work alongside the dev tools debugger. Start from VS Code, and start debugging as you would. Then open dev tools from any tab in the Chrome/Chromium browser, and look for the green icon indicating a node.js debugging process is running ( manually done via node --inspect ): . Click this green icon and you'll have many of the browser dev tools features for debugging the node.js process, specifically the memory and profiler tabs. Visual Studio Code 1.45 (April 2020) should help, as it integrates Javascript debugging capabilities, including profiling: New JavaScript debugger This month we've continued making progress on our new JavaScript debugger. It's installed by default on Insiders, and can be installed from the Marketplace in VS Code Stable. You can start using it with your e

Activate Virtualization Without Bios Code Example

Example: enable virtualization in bios Inside bios setting > tweaker settings > Advance CPU setting > Enable SVM Mode

Chart.js - Hover Labels To Display Data For All Data Points On X-axis

Answer : Is there a simple way to accomplish this? YES !! There is a quite straightforward way to accomplish this. If you would have read the documentation, you could have found that pretty easily. Anyway, basically you need to set the tooltips mode to index in your chart options, in order to accomplish the behavior you want. ... options: { tooltips: { mode: 'index' } } ... Additionally, you probably want to set the following: ... options: { tooltips: { mode: 'index', intersect: false }, hover: { mode: 'index', intersect: false } } ... This will make it so all of the expected hover/label interactions will occur when hovering anywhere on the graph at the nearest x-value. From the Documentation : # index Finds item at the same index. If the intersect setting is true, the first intersecting item is used to determine the index in the data. If intersect false the nearest item, in the x

Rick Roll Lyrics Code Example

Example: never gonna give you up lyrics /* We're no strangers to love You know the rules and so do I A full commitment's what I'm thinking of You wouldn't get this from any other guy I just wanna tell you how I'm feeling Gotta make you understand Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you We've known each other for so long Your heart's been aching but you're too shy to say it Inside we both know what's been going on We know the game and we're gonna play it And if you ask me how I'm feeling Don't tell me you're too blind to see Never gonna give you up Never gonna let you down Never gonna run around and desert you Never gonna make you cry Never gonna say goodbye Never gonna tell a lie and hurt you Never gonna give you up Never gonna let you down Never gonna run around and

Ansible Task Debug Code Example

Example 1: ansible debug - debug: msg: "SHINE UI URL = {{ shineui_url }}" Example 2: ansible debug - debug: msg={{ result }}

Are Objects In PHP Passed By Value Or Reference?

Answer : Why not run the function and find out? $b = new Bar; echo $b->getFoo(5)->value; $b->test(); echo $b->getFoo(5)->value; For me the above code (along with your code) produced this output: Foo #5 My value has now changed This isn't due to "passing by reference", however, it is due to "assignment by reference". In PHP 5 assignment by reference is the default behaviour with objects. If you want to assign by value instead, use the clone keyword. You can refer to http://ca2.php.net/manual/en/language.oop5.references.php for the actual answer to your question. One of the key-points of PHP5 OOP that is often mentioned is that "objects are passed by references by default". This is not completely true. A PHP reference is an alias, which allows two different variables to write to the same value. As of PHP5, an object variable doesn't contain the object itself as value anymore. It only contains an object identifier which a

Automatically Position Text Box In Matplotlib

Image
Answer : Just use annotate and specify axis coordinates. For example, "upper left" would be: plt.annotate('Something', xy=(0.05, 0.95), xycoords='axes fraction') You could also get fancier and specify a constant offset in points: plt.annotate('Something', xy=(0, 1), xytext=(12, -12), va='top' xycoords='axes fraction', textcoords='offset points') For more explanation see the examples here and the more detailed examples here. I'm not sure if this was available when I originally posted the question but using the loc parameter can now actually be used. Below is an example: import numpy as np import matplotlib.pyplot as plt from matplotlib.offsetbox import AnchoredText # make some data x = np.arange(10) y = x # set up figure and axes f, ax = plt.subplots(1,1) # loc works the same as it does with figures (though best doesn't work) # pad=5 will increase the size of padding between the border and t

Clear Npm Cache Code Example

Example 1: npm clear cache npm cache clean --force Example 2: npm cache clean # To clear a cache in npm, we need to run the npm cache clean --force command in our terminal: npm cache clean --force # clean: It deletes the all data from your cache folder. # You can also verify the cache, by running the following command: npm cache verify Example 3: npm start reset cache npm start -- --reset-cache Example 4: nodejs clean cache npm cache clean --force

Min Heap Implementation In C Code Example

Example 1: min heap in c++ priority_queue < int , vector < int > , greater < int >> minHeap ; Example 2: heapify in c // Max-Heap data structure in C # include <stdio.h> int size = 0 ; void swap ( int * a , int * b ) { int temp = * b ; * b = * a ; * a = temp ; } void heapify ( int array [ ] , int size , int i ) { if ( size == 1 ) { printf ( "Single element in the heap" ) ; } else { int largest = i ; int l = 2 * i + 1 ; int r = 2 * i + 2 ; if ( l < size && array [ l ] > array [ largest ] ) largest = l ; if ( r < size && array [ r ] > array [ largest ] ) largest = r ; if ( largest != i ) { swap ( & array [ i ] , & array [ largest ] ) ; heapify ( array , size , largest ) ; } } } void insert ( int array [ ] , int newNum ) { if ( size == 0 ) {

Centos 7 Iso Image For Vmware Code Example

Example: centos 7 vmware How to install CentOS in VMware Workstation Step 01: Create a New Virtual Machine Step 02: Select Hardware Compatibility Step 03: Use or select CentOS Image to install Step 04: Configure Virtual Machine Name and file Location Step 05: Configure Virtual processor for new virtual machine Step 06: Setup Virtual RAM memory for new virtual machine Step 07: Setup Virtual Machine Network Step 08: Configure Virtual storage disk for new virtual machine Step 09: Now power on of the virtual machine after finish the VMware setup Step 10: Get the CentOS setup screen on display follow the given instruction on screen and it will install in 10 min.

Angular Select Option With Selected Attribute Not Working

Answer : When you use ngModel, the state is handled internally and any explicit change to it just gets ignored. In your example, you are setting the selected property of option , but you are also providing a (void) ngModel to your select , so Angular expects that the state of the select is provided within the ngModel. Briefly, you should leverage on your ngModel instead than setting the selected property: <select name="rate" #rate="ngModel" [(ngModel)]="yourModelName" required> <option value="hr">hr</option> <option value="yr">yr</option> </select> And: yourModelName: string; constructor() { this.yourModelName = 'hr'; } If you don't wish to have a two-way binding, you can set ngModel to the 'default' value and with the template local variable get the selected value: <select #rate ngModel="hr"> <option se

Cat Command On Windows Code Example

Example: cat in windows Just use type command in Windows as follows: C:\>echo hi > a.txt C:\>echo bye > b.txt C:\>type a.txt b.txt > c.txt C:\>type c.txt

Case-insensitive String Startswith In Python

Answer : You could use a regular expression as follows: In [33]: bool(re.match('he', 'Hello', re.I)) Out[33]: True In [34]: bool(re.match('el', 'Hello', re.I)) Out[34]: False On a 2000-character string this is about 20x times faster than lower() : In [38]: s = 'A' * 2000 In [39]: %timeit s.lower().startswith('he') 10000 loops, best of 3: 41.3 us per loop In [40]: %timeit bool(re.match('el', s, re.I)) 100000 loops, best of 3: 2.06 us per loop If you are matching the same prefix repeatedly, pre-compiling the regex can make a large difference: In [41]: p = re.compile('he', re.I) In [42]: %timeit p.match(s) 1000000 loops, best of 3: 351 ns per loop For short prefixes, slicing the prefix out of the string before converting it to lowercase could be even faster: In [43]: %timeit s[:2].lower() == 'he' 1000000 loops, best of 3: 287 ns per loop Relative timings of these approaches will of course depe

Button Onclick Javascript Code Example

Example 1: javascript onclick document.getElementById("myBtn").addEventListener("click", function() { alert("Hello World!"); }); Example 2: HTML button onclick <! DOCTYPE html > < html > < head > < title > Title of the document </ title > </ head > < body > < p > There is a hidden message for you. Click to see it. </ p > < button onclick = " myFunction() " > Click me! </ button > < p id = " demo " > </ p > < script > function myFunction ( ) { document . getElementById ( "demo" ) . innerHTML = "Hello Dear Visitor!</br> We are happy that you've chosen our website to learn programming languages. We're sure you'll become one of the best programmers in your country. Good luck to you!" ; } </ script > </ body > </ html > Ex

Change TinyMce Editor's Height Dynamically

Answer : You can resize tinymce with the resizeTo theme method: editorinstance.theme.resizeTo (width, height); The width and height set the new size of the editing area - I have not found a way to deduce the extra size of the editor instance, so you might want to do something like this: editorinstance.theme.resizeTo (new_width - 2, new_height - 32); Try: tinyMCE.init({ mode : "exact", elements : "elm1", .... To change size dynamically in your javascript code: var resizeHeight = 350; var resizeWidth = 450; tinyMCE.DOM.setStyle(tinyMCE.DOM.get("elm1" + '_ifr'), 'height', resizeHeight + 'px'); tinyMCE.DOM.setStyle(tinyMCE.DOM.get("elm1" + '_ifr'), 'width', resizeWidth + 'px'); The following comes in from this other SO answer I posted: None of the above were working for me in TinyMCE v4, so my solution was to calculate the height based on the toolbars/

Cast Int To String Php Code Example

Example 1: integer to string php return strval ( $integer ) ; Example 2: php int to string $number = 11 ; // This echo strval ( $number ) ; // Or This echo ( String ) $number ; // Output // "11" // "11" Example 3: convert int to string php $var = 5 ; // Inline variable parsing echo "I'd like { $var } waffles" ; // = "I'd like 5 waffles // String concatenation echo "I'd like " . $var . " waffles" ; // I'd like 5 waffles // Explicit cast $items = ( string ) $var ; // $items === "5"; // Function call $items = strval ( $var ) ; // $items === "5"; Example 4: Convert an Integer Into a String in PHP phpCopy <?php $variable = 10 ; $string1 = ( string ) $variable ; echo "The variable is converted to a string and its value is $string1 ." ; ?> Example 5: Convert an Integer Into a String in PHP phpCopy <?php $variable = 10

Angular Material Table Sizing/Scroll

Answer : Add .example-container { overflow-x: scroll; } To the app.component.css to fix the top bar. The bottom will need a similar styling. You can't use width:100% because it is technically outside the table. So it can not pick up the width automatically. I hope this will be help full for others to add Horizontal Scrolling to mat-table and column width according to cell content. .mat-table { overflow-x: scroll; } .mat-cell, .mat-header-cell { word-wrap: initial; display: table-cell; padding: 0px 10px; line-break: unset; width: 100%; white-space: nowrap; overflow: hidden; vertical-align: middle; } .mat-row, .mat-header-row { display: table-row; }

Map Function Arduino Code Example

Example 1: map arduino Syntax map ( value , fromLow , fromHigh , toLow , toHigh ) Parameters value : the number to map . fromLow : the lower bound of the value’s current range . fromHigh : the upper bound of the value’s current range . toLow : the lower bound of the value’s target range . toHigh : the upper bound of the value’s target range . Example : map ( val , 0 , 255 , 0 , 1023 ) ; Example 2: arduino map function long map ( long x , long in_min , long in_max , long out_min , long out_max ) { return ( x - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min ; }

Angular Ng-if="" With Multiple Arguments

Answer : It is possible. <span ng-if="checked && checked2"> I'm removed when the checkbox is unchecked. </span> http://plnkr.co/edit/UKNoaaJX5KG3J7AswhLV?p=preview For people looking to do if statements with multiple 'or' values. <div ng-if="::(a || b || c || d || e || f)"><div> Just to clarify, be aware bracket placement is important! These can be added to any HTML tags... span, div, table, p, tr, td etc. AngularJS ng-if="check1 && !check2" -- AND NOT ng-if="check1 || check2" -- OR ng-if="(check1 || check2) && check3" -- AND/OR - Make sure to use brackets Angular2 + *ngIf="check1 && !check2" -- AND NOT *ngIf="check1 || check2" -- OR *ngIf="(check1 || check2) && check3" -- AND/OR - Make sure to use brackets It's best practice not to do calculations directly within ngIfs, so assign the variables within yo

Arduino Volatile Int "MODE=" 4; Code Example

Example: interrupt arduino attachInterrupt(digitalPinToInterrupt(interruptPin), someFuntion, CHANGE);

Button With Image Background Flutter

Answer : the "RaisedButton" is a material component , its take it shape depends on "material design" roles , you can create your own custom button widget GestureDetector( child: Container( width:120, height: 40, decoration: BoxDecoration( color: Colors.black, image: DecorationImage( image:AssetImage("assets/background_button.png"), fit:BoxFit.cover ), child: Text("clickMe") // button text ) ),onTap:(){ print("you clicked me"); } ) If anyone else come here looking for this, MaterialButton works perfectly. MaterialButton( padding: EdgeInsets.all(8.0), textColor: Colors.white, splashColor: Colors.greenAccent, elevation: 8.0, child: Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage('assets/button_colo

Apple - Can I Stream Any Video Played With VLC Player To Apple TV?

Image
Answer : It's not using VLC (although it uses some of its components and should be able to open anything VLC can open), but it looks like there's a way to do this. It requires on-the-fly transcoding for formats the AppleTV doesn't support (essentially anything not .mp4 or .m4v), which means it may take a fair bit of CPU power on your Mac, especially for HD stuff. It also means that aside from files the AppleTV natively supports, you're not getting bit-perfect renditions of the files, it's a lossy translation, but if you have a decently fast Mac, it should be pretty good. The main tool you'll want is AirFlick. It's a pretty basic program that sends a URL to the AppleTV that tells it to open a stream from your computer. It also handles transcoding the non-native files. It's not very well documented; it looks like the latest versions use a built-in copy of ffmpeg for transcoding, but some of the resources around the web suggest that it may need VLC ins

Android Get Real Path By Uri.getPath()

Answer : This is what I do: Uri selectedImageURI = data.getData(); imageFile = new File(getRealPathFromURI(selectedImageURI)); and: private String getRealPathFromURI(Uri contentURI) { String result; Cursor cursor = getContentResolver().query(contentURI, null, null, null, null); if (cursor == null) { // Source is Dropbox or other similar local file path result = contentURI.getPath(); } else { cursor.moveToFirst(); int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); result = cursor.getString(idx); cursor.close(); } return result; } NOTE: managedQuery() method is deprecated, so I am not using it. Last edit: Improvement. We should close cursor!! Is it really necessary for you to get a physical path? For example, ImageView.setImageURI() and ContentResolver.openInputStream() allow you to access the contents of a file without knowing its real path. @Rene Juuse - above in comments... Thanks

Length Of Array Python Code Example

Example 1: how to loop the length of an array pytoh array = range ( 10 ) for i in range ( len ( array ) ) : print ( array [ i ] ) Example 2: size array python size = len ( myList ) Example 3: 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 Example 4: find array length python array = [ 1 , 2 , 3 , 4 , 5 ] print ( len ( arr ) ) Example 5: python array length len ( my_array ) Example 6: find array length in python a = arr . array ( 'd' , [ 1.1 , 2.1 , 3.1 ] ) len ( a )