Posts

Showing posts from August, 2011

Add Title To Collection Of Pandas Hist Plots

Answer : With newer Pandas versions, if someone is interested, here a slightly different solution with Pandas only: ax = data.plot(kind='hist',subplots=True,sharex=True,sharey=True,title='My title') You can use suptitle() : import pylab as pl from pandas import * data = DataFrame(np.random.randn(500).reshape(100,5), columns=list('abcde')) axes = data.hist(sharey=True, sharex=True) pl.suptitle("This is Figure title") I found a better way: plt.subplot(2,3,1) # if use subplot df = pd.read_csv('documents',low_memory=False) df['column'].hist() plt.title('your title') It is very easy, display well at the top, and will not mess up your subplot.

Calculating A LookAt Matrix

Answer : Note the example given is a left-handed, row major matrix . So the operation is: Translate to the origin first (move by - eye ), then rotate so that the vector from eye to At lines up with +z: Basically you get the same result if you pre-multiply the rotation matrix by a translation - eye : [ 1 0 0 0 ] [ xaxis.x yaxis.x zaxis.x 0 ] [ 0 1 0 0 ] * [ xaxis.y yaxis.y zaxis.y 0 ] [ 0 0 1 0 ] [ xaxis.z yaxis.z zaxis.z 0 ] [ -eye.x -eye.y -eye.z 1 ] [ 0 0 0 1 ] [ xaxis.x yaxis.x zaxis.x 0 ] = [ xaxis.y yaxis.y zaxis.y 0 ] [ xaxis.z yaxis.z zaxis.z 0 ] [ dot(xaxis,-eye) dot(yaxis,-eye) dot(zaxis,-eye) 1 ] Additional notes: Note that a viewing transformation is (intentionally) inverted : you multiply every vertex by this matrix to "move the world" so that the portion you want to s

Change Placeholder Text Color Of Textarea

Answer : Wrap in quotes: onchange="{(e) => this.props.handleUpdateQuestion(e, firstQuestion.Id)}" otherwise, it should work just fine: textarea::-webkit-input-placeholder { color: #0bf; } textarea:-moz-placeholder { /* Firefox 18- */ color: #0bf; } textarea::-moz-placeholder { /* Firefox 19+ */ color: #0bf; } textarea:-ms-input-placeholder { color: #0bf; } textarea::placeholder { color: #0bf; } <textarea placeholder="test"></textarea> I am not sure but I think is not necessary to use the prefixes right now. textarea::placeholder { color: #fff; }

How To Get Input From Serial Monitor Arduino Code Example

Example: how to print to the serial monitor arduino void setup ( ) { Serial . begin ( 9600 ) ; } void loop ( ) { // This will write to the monitor and end the line Serial . println ( "test text" ) ; // This will write to the monitor but will not end the line Serial . print ( "test text" ) ; }

Apple - AirPods: Extremely Poor Mic Quality On Mac

Image
Answer : OP here – I'd just like to add to the answer below, that I've been in contact with Apple Support. Explanation Apple claims that the poor Mono 8kHz quality which affects recording and indeed simultaneously playback on Mac when the AirPod microphones are activated, is because the SCO codec then gets employed over the entire Mac audio system. This is supposedly "expected behaviour" when trying to use the AirPods and other Bluetooth headsets together with a computer, according to Apple. The AAC codec is normally used when just listening to playback on the AirPods. It's just very unfortunate that SCO – low-quality as it may be – upon AirPod microphone activation is not only limited to doing recording, but also displaces AAC and audio playback. Apple Support claims that Apple is looking at this issue, and that improvements might be coming in future firmware updates, but I did not interpret that as a promise to be honest. But for the time being, I'd

Apply OneHotEncoder For Several Categorical Columns In SparkMlib

Answer : Spark >= 3.0 : In Spark 3.0 OneHotEncoderEstimator has been renamed to OneHotEncoder : from pyspark.ml.feature import OneHotEncoderEstimator, OneHotEncoderModel encoder = OneHotEncoderEstimator(...) with from pyspark.ml.feature import OneHotEncoder, OneHotEncoderModel encoder = OneHotEncoder(...) Spark >= 2.3 You can use newly added OneHotEncoderEstimator : from pyspark.ml.feature import OneHotEncoderEstimator, OneHotEncoderModel encoder = OneHotEncoderEstimator( inputCols=[indexer.getOutputCol() for indexer in indexers], outputCols=[ "{0}_encoded".format(indexer.getOutputCol()) for indexer in indexers] ) assembler = VectorAssembler( inputCols=encoder.getOutputCols(), outputCol="features" ) pipeline = Pipeline(stages=indexers + [encoder, assembler]) pipeline.fit(df).transform(df) Spark < 2.3 It is not possible. StringIndexer transformer operates only on a single column at the time so you'll ne

Youtube Converter Mp4 Hd Video Code Example

Example: youtube to mp4 ytmp3 . cc is the best by far

Can A Torrent With Zero Seeders Download?

Answer : DHT and Peer Exchange are not tracker related, but program related, so yes they can find people who are downloading the same file but are not connected to the tracker you are using. Those people that are found might be either seeders or leechers. From this BiTorrent FAQ: When there are zero seeds for a given torrent (and not enough peers to have a distributed copy), then eventually all the peers will get stuck with an incomplete file, if no one in the swarm has the missing pieces. When this happens, someone with a complete file (a seed) must connect to the swarm so that those missing pieces can be transferred. This is called reseeding. Usually a request for a reseed comes with an implicit promise that the requester will leave his or her client open for some time period after finishing (to add longevity to the torrent) in return for the kind soul reseeding the file. Yes, it is true in practice - but not always. With no seeders, the

Ansi Sql Tutorial Code Example

Example: what is SQL SQL full form is a structured query language , and it allows you to interact through commands with the database . Here are some of the SQL Database functions : This allows users to retrieve information from the relational database . It enables the development of tables and databases . It allows data base and tables to be modified , added , removed , and changed . It gives protection , and allows permission to be set . Allows new ways for people to manage the info .

Can You Beat The British Intelligence? (Nonogram Solver)

Answer : Haskell, 242 230 201 199 177 163 160 149 131 bytes import Data.Lists m=map a#b=[x|x<-m(chunk$length b).mapM id$[0,1]<$(a>>b),g x==a,g(transpose x)==b] g=m$list[0]id.m sum.wordsBy(<1) Finally under 200 bytes, credit to @Bergi. Huge thanks to @nimi for helping almost halving the size. Wow. Almost at half size now, partly because of me but mainly because of @nimi. The magic function is (#) . It finds all solutions of a given nonogram. This is able to solve all cases, but may be super slow, since it's complexity is about O(2^(len a * len b)) . A quick benchmark revealed 86GB allocated for a 5x5 nonogram. Fun fact: It works for all nonograms, not only square ones. How it works: a#b : Given lists of lists of integers which represent the number of squares, generate all grids ( map(chunk$length b).mapM id$a>>b>>[[0,1]] ) and filter the results to keep only the valid ones. g : Given a potential nonogram it sums the runs of 1's

Authentication Order With SSH

Answer : Solution 1: The ssh server decides which authentication options it allows, the ssh client can be configured to decide in which order to try them. The ssh client uses the PreferredAuthentications option in the ssh config file to determine this. From man ssh_config (see it online here): PreferredAuthentications Specifies the order in which the client should try protocol 2 authentication methods. This allows a client to prefer one method (e.g. keyboard-interactive) over another method (e.g. password). The default is: gssapi-with-mic,hostbased,publickey, keyboard-interactive,password I don't believe it's possible, without playing with the source, to tell the OpenSSH server to prefer a certain order - if you think about it, it doesn't quite make sense anyway. Solution 2: Adding this: PreferredAuthentications keyboard-interactive,password,publickey,hostbased,gssapi-with-mic ...to my /

Clear Markers From Google Map In Android

Answer : If you want to clear "all markers, overlays, and polylines from the map", use clear() on your GoogleMap . If you do not wish to clear polylines and only the markers need to be removed follow the steps below. First create a new Marker Array like below List<Marker> AllMarkers = new ArrayList<Marker>(); Then when you add the marker on the google maps also add them to the Marker Array (its AllMarkers in this example) for(int i=0;i<places.length();i++){ LatLng location = new LatLng(Lat,Long); MarkerOptions markerOptions = new MarkerOptions(); markerOptions.position(location); markerOptions.title("Your title"); Marker mLocationMarker = Map.addMarker(markerOptions); // add the marker to Map AllMarkers.add(mLocationMarker); // add the marker to array } then finally call the below method to remove all markers at once

Check Whether A String Contains A Charact In Last Js Code Example

Example: javascript check if string contains a text substring stringVariable . includes ( "Your Text" ) ;

How To Get Size Of Char* In C Code Example

Example 1: c print sizeof char char b = 'b' ; printf ( "the size of b is %d" , sizeof ( b ) ) ; Example 2: how to find the size of a character array in c++ Instead of sizeof ( ) for finding the length of strings or character arrays , just use strlen ( string_name ) with the header file # include <cstring> it's easier .

Are There Any Free Xml Diff/Merge Tools Available?

Image
Answer : Have a look at at File comparison tools, from which I am using WinMerge. It has an ability to compare XML documents (you may wish to enable DisplayXMLFiles prefilter). DisplayXMLFiles.dll - This plugin pretty-prints XML files nicely by inserting tabs and line breaks. This is useful for XML files that do not have line returns in convenient locations. See also my feature comparison table. I wrote and released a Windows application that specifically solves the problem of comparing and merging XML files. Project: Merge can perform two and three way comparisons and merges of any XML file (where two of the files are considered to be independent revisions of a common base file). You can instruct it to identify elements within the input files by attribute values, or the content of child elements, among other things. It is fully controllable via the command line and can also generate text reports containing the differences between the files. There are a few Java-bas

Array Count In Javascript Code Example

Example 1: array length javascript var numbers = [ 1 , 2 , 3 , 4 , 5 ] ; var length = numbers . length ; for ( var i = 0 ; i < length ; i ++ ) { numbers [ i ] *= 2 ; } // numbers is now [2, 4, 6, 8, 10] Example 2: array length javascript var arr = [ 10 , 20 , 30 , 40 , 50 ] ; //An Array is defined with 5 instances var len = arr . length ; //Now arr.length returns 5.Basically, len=5. console . log ( len ) ; //gives 5 console . log ( arr . length ) ; //also gives 5 Example 3: array length in js' var x = [ ] ; console . log ( x . size ( ) ) ; console . log ( x . length ) ; console . log ( x . size ( ) == x . length ) ; x = [ 1 , 2 , 3 ] ; console . log ( x . size ( ) ) ; console . log ( x . length ) ; console . log ( x . size ( ) == x . length ) ; //arjun

Background Color Of Text In SVG

Answer : No this is not possible, SVG elements do not have background-... presentation attributes. To simulate this effect you could draw a rectangle behind the text attribute with fill="green" or something similar (filters). Using JavaScript you could do the following: var ctx = document.getElementById("the-svg"), textElm = ctx.getElementById("the-text"), SVGRect = textElm.getBBox(); var rect = document.createElementNS("http://www.w3.org/2000/svg", "rect"); rect.setAttribute("x", SVGRect.x); rect.setAttribute("y", SVGRect.y); rect.setAttribute("width", SVGRect.width); rect.setAttribute("height", SVGRect.height); rect.setAttribute("fill", "yellow"); ctx.insertBefore(rect, textElm); You could use a filter to generate the background. <svg width="100%" height="100%"> <defs> <filter x="0" y=&qu

Can Villagers Open Iron Doors Minecraft Code Example

Example: can villagers open iron doors Villagers can't open fence gates or trap doors, nor can they use buttons or levers, allowing you to use iron doors, iron trapdoors, or just about any redstone-based door mechanism without them being able to escape.

C# - How To Get Program Files (x86) On Windows 64 Bit

Answer : The function below will return the x86 Program Files directory in all of these three Windows configurations: 32 bit Windows 32 bit program running on 64 bit Windows 64 bit program running on 64 bit windows   static string ProgramFilesx86() { if( 8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))) { return Environment.GetEnvironmentVariable("ProgramFiles(x86)"); } return Environment.GetEnvironmentVariable("ProgramFiles"); } If you're using .NET 4, there is a special folder enumeration ProgramFilesX86: Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) Environment.GetEnvironmentVariable("PROGRAMFILES(X86)") ?? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)

Cannot Kill Python Script With Ctrl-C

Answer : Ctrl + C terminates the main thread, but because your threads aren't in daemon mode, they keep running, and that keeps the process alive. We can make them daemons: f = FirstThread() f.daemon = True f.start() s = SecondThread() s.daemon = True s.start() But then there's another problem - once the main thread has started your threads, there's nothing else for it to do. So it exits, and the threads are destroyed instantly. So let's keep the main thread alive: import time while True: time.sleep(1) Now it will keep print 'first' and 'second' until you hit Ctrl + C . Edit: as commenters have pointed out, the daemon threads may not get a chance to clean up things like temporary files. If you need that, then catch the KeyboardInterrupt on the main thread and have it co-ordinate cleanup and shutdown. But in many cases, letting daemon threads die suddenly is probably good enough. KeyboardInterrupt and signals are only seen by the proc

Angular 7 & Stripe Error TS2304: Cannot Find Name 'Stripe'

Answer : The issue is resolved by including a reference to the @types/stripe-v3 package in the compilerOptions.types array of your tsconfig.app.json file in the src directory of your Angular project. { "extends": "../tsconfig.json", "compilerOptions": { "outDir": "../out-tsc/app", "types": [ "stripe-v3" ] }, "exclude": [ "test.ts", "**/*.spec.ts" ] } This solution was posted by bjornharvold in this thread. Angular imports types based on values of compilerOptions.types and compilerOptions.typeRoots from the typescript configuration file. TS compilerOptions docs reference By default Angular projects created using angular cli will have two typescript configuration files. tsconfig.json in the root of the project tsconfig.app.json in /src directory If both types and typeRoots are undefined angular will import all the typings from

Bash: Using Dot Or "source" Calling Another Script - What Is Difference?

Answer : The only difference is in portability. . is the POSIX-standard command for executing commands from a file; source is a more-readable synonym provided by bash and some other shells. bash itself, however, makes no distinction between the two. There is no difference. From the manual: source source filename A synonym for . (see Bourne Shell Builtins).

Collapsible Bootstrap, Show First Element

Answer : I don't think you've got all the HTML you need for the accordion to work unless you haven't pasted it all above. The Bootstrap docs first example has the first element set to be open: http://twitter.github.com/bootstrap/javascript.html#collapse (These docs are for v2.3.2, which is no longer officially supported.) I think it's the class "in" that sets it to be open initially. <div class="accordion" id="accordion2"> <div class="accordion-group"> <div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne"> Collapsible Group Item #1 </a> </div> <div id="collapseOne" class="accordion-body collapse in"> <div class="accordion-inner"> Anim pariatur cliche... </div> </div> </div> <div class="accordion

Add Views In UIStackView Programmatically

Image
Answer : Stack views use intrinsic content size, so use layout constraints to define the dimensions of the views. There is an easy way to add constraints quickly (example): [view1.heightAnchor constraintEqualToConstant:100].active = true; Complete Code: - (void) setup { //View 1 UIView *view1 = [[UIView alloc] init]; view1.backgroundColor = [UIColor blueColor]; [view1.heightAnchor constraintEqualToConstant:100].active = true; [view1.widthAnchor constraintEqualToConstant:120].active = true; //View 2 UIView *view2 = [[UIView alloc] init]; view2.backgroundColor = [UIColor greenColor]; [view2.heightAnchor constraintEqualToConstant:100].active = true; [view2.widthAnchor constraintEqualToConstant:70].active = true; //View 3 UIView *view3 = [[UIView alloc] init]; view3.backgroundColor = [UIColor magentaColor]; [view3.heightAnchor constraintEqualToConstant:100].active = true; [view3.widthAnchor constraintEqualToConstant

Android Foreground Service Notification Not Showing

Answer : It's because of Android O bg services restrictions. So now you need to call startForeground() only for services that were started with startForegroundService() and call it in first 5 seconds after service has been started. Here is the guide - https://developer.android.com/about/versions/oreo/background#services Like this: //Start service: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { startForegroundService(new Intent(this, YourService.class)); } else { startService(new Intent(this, YourService.class)); } Then create and show notification (with channel as supposed earlier): private void createAndShowForegroundNotification(Service yourService, int notificationId) { final NotificationCompat.Builder builder = getNotificationBuilder(yourService, "com.example.your_app.notification.CHANNEL_ID_FOREGROUND", // Channel id NotificationManagerCompat.IMPORTANCE_LOW); //Low importance prevent visual appearance for this notifica

Anaconda Prompt Environment List Code Example

Example 1: list conda environments conda info --envs conda env list Example 2: conda create env from yml conda env create -f environment.yml

AWS SNS Is Not Sending SMS Anymore

Answer : There are different ways to troubleshoot this problem. This is something addressed in the Developer Forum of AWS. Please go through the following steps to troubleshoot this problem. These could be basic steps, but I am pointing out the most general steps required. Try sending an SMS from the AWS Console. If this works, there is no issue with the spending limit or delivery rate. (So you have mentioned that this is not working too) Now check whether your Mobile number (which is receiving SMS) is subscribed to the topic. Under some conditions, the recipient can opt out from the topic. Where required by local laws and regulations (such as the US and Canada), SMS recipients can opt out, which means that they choose to stop receiving SMS messages from your AWS account. Check the Account Spending Limit which you have set for your calendar month. This could be limiting your SMS delivery. If you haven't set this, the default is 1 USD per month. For Accou

Cdn Fontawesome Icons Code Example

Example 1: fontawesome cdn < link href = " https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css " rel = " stylesheet " > Example 2: fontawesome cdn < link rel = " stylesheet " href = " https://pro.fontawesome.com/releases/v5.10.0/css/all.css " integrity = " sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p " crossorigin = " anonymous " /> Example 3: font-awesome cdn < link rel = " stylesheet " href = " path/to/font-awesome/css/font-awesome.min.css " > Example 4: font awesome cdn font awesome cdn

At What UART Baud Rate Is Hardware Flow Control Required?

Answer : It is not data rate that matters; we use CTS / RTS (or XON / XOFF for software flow control) where a possibility of a receiver overflow exists, although admittedly that is more likely at higher data rates. If a receiver cannot empty its buffers quickly enough, then it should deassert CTS (in response to which, the transmitter will assert RTS if there is more data to transmit). Note that the transmitter may experience a buffer underrun in which case it should deassert RTS (because there is no valid data to send). So it comes down to how fast the buffers can be moved - that is more likely to be an issue at higher data rates but it is completely implementation dependent; there is no single speed. You require some form of flow control (be that hardware or XON/XOFF) when you are transferring data at a speed greater than you can process it. It's as simple as that. Flow control is used for one end to tell the other end "wait a moment, I am still thinking".

Android: Set View Style Programmatically

Answer : Technically you can apply styles programmatically, with custom views anyway: private MyRelativeLayout extends RelativeLayout { public MyRelativeLayout(Context context) { super(context, null, R.style.LightStyle); } } The one argument constructor is the one used when you instantiate views programmatically. So chain this constructor to the super that takes a style parameter. RelativeLayout someLayout = new MyRelativeLayout(new ContextThemeWrapper(this,R.style.RadioButton)); Or as @Dori pointed out simply: RelativeLayout someLayout = new RelativeLayout(new ContextThemeWrapper(activity,R.style.LightStyle)); Now in Kotlin: class MyRelativeLayout @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = R.style.LightStyle, ) : RelativeLayout(context, attributeSet, defStyleAttr) or val rl = RelativeLayout(ContextThemeWrapper(activity, R.style.LightStyle)) What worked for me: Button b = new Button(new