天道酬勤,学无止境

问答

Detect supported audio encoders on Android to prevent crash “The given audio encoder 2 is not found”

When an Android device does not support a mandatory audio-encoder, you get: (X=numeric index of the encoder) E/MediaProfiles(4048): The given audio encoder X is not found A/AudioSource(4048): frameworks/base/media/libstagefright/AudioSource.cpp:58 CHECK(channels == 1 || channels == 2) failed. A/libc(4048): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1) In native code. No Exception to react to. App is just force closed. Is there any way to query an Android >3.x device if AAC AMR-NB and AMR-WB are actually supported? Documentation ( http://developer.android.com/guide/appendix/media-formats

2021-06-15 18:17:11   android   media   mediarecorder   amr   stagefright

R: table function suprisingly slow

> class(v) "numeric" > length(v) 80373285 # 80 million The entries of v are integers uniformly distributed between 0 and 100. > ptm <- proc.time() > tv <- table(v) > show(proc.time() - ptm) user system elapsed 96.902 0.807 97.761 Why is the table function so slow on this vector? Is there a faster function for this simple operation? By comparison, the bigtable function from bigtabulate is fast: > library(bigtabulate) > ptm <- proc.time() ; bt <- bigtable(x = matrix(v,ncol=1), ccols=1) ; show(proc.time() - ptm) user system elapsed 4.163 0.120 4.286 While bigtabulate is a good solution, it seems

2021-06-15 18:16:53   r

[Python/Tkinter]How can I fetch the value of data which was set in function “event_generate”

I'm using Python 2.7.4 and new to Tkinter, and I'm stuck with the following code. I generated an event "test" and set the "data" option with a string, but an error occurred when retrieving it from event. Error -> AttributeError: Event instance has no attribute 'data' from Tkinter import * def handle_it(event): # print "event handler" print event.data root = Tk() root.after(1, lambda: root.event_generate('<<test>>', data="hi there")) root.bind('<<test>>', handle_it) root.mainloop() I can't find the related Python docs for this case, so I referred to the tcl document as below http://www.tcl.tk

2021-06-15 18:16:11   python   user-interface   tkinter   tk

Remove white space (i.e., margins) ggplot2 in R

I'm trying to plot a pie chart using GGPLOT2 in R. I want to do this in such a way as to omit the extra margin space. What I'm doing is similar to what sharoz did in this post here except I want to include a legend. Here is what I'm doing: ggplot(DATA, aes(x=factor(0),fill=factor(LABELS),weight=VALUES)) + geom_bar(width=1) + coord_polar(theta='y') + guides(fill=guide_legend(title='LEGEND'))

2021-06-15 18:16:06   r   ggplot2   legend   pie-chart   margins

Property already registered by 'ListView'

I have this code: using System.Collections; using System.Windows; using System.Windows.Controls; public static class SelectedItems { private static readonly DependencyProperty SelectedItemsBehaviorProperty = DependencyProperty.RegisterAttached( "SelectedItemsBehavior", typeof(SelectedItemsBehavior), typeof(ListView), null); public static readonly DependencyProperty ItemsProperty = DependencyProperty.RegisterAttached( "Items", typeof(IList), typeof(SelectedItems), new PropertyMetadata(null, ItemsPropertyChanged)); public static void SetItems(ListView listView, IList list) { listView.SetValue

2021-06-15 18:15:56   c#   wpf   mvvm   visual-studio-2012

Why is implicit conversion allowed from superclass to subclass?

Can someone tell me why the line with "//Compiles" compiles, and why the line with "//Doesn't Compile" does not? I don't understand why A would be implicitly convertible to B, not the other way round. public class SomeClass { static public void Test() { AClass a = new AClass(); BClass b = new BClass(); a = b; // Compiles b = a; // Doesn't compile } } public class AClass { public void AMethod() { Console.WriteLine("AMethod"); } } public class BClass : AClass { public void BMethod() { Console.WriteLine("BMethod"); } } thanks!

2021-06-15 18:15:46   c#   .net   inheritance   type-conversion   implicit-conversion

How can I use `std::array` for a template parameter of the form `template<typename> class`?

Please consider the following tree class template<typename T, template<typename> class Tuple> class tree { private: T m_value; Tuple<tree> m_children; }; template<typename T, std::size_t N> using static_tree = tree<T, std::array<T, N>>; which is not well-defined. std::array<T, N> is not a suitable template parameter for Tuple. I assume the intend of static_tree is clear. We could do something like template<std::size_t N> struct helper { template<typename T> using type = std::array<T, N>; }; template<typename T, std::size_t N> using static_tree = tree<T, helper<N>::template type>; Is there any

2021-06-15 18:15:39   c++   templates   c++14   template-templates

Bundler could not find compatible versions for gem “bundler”: In Gemfile:

I'm making GitHub blog page with Jekyll. I've failed like numerous times and just forked new one and followed README on the repository. It's https://github.com/janczizikow/sleek/blob/master/README.md and I tried to run inside the directory(master) but this msg keeps coming out. I tried 'gem install bundler' 'gem cleanup' and similar solutions on the internet but still can't fix it. I get that I need another version which is lower one, then how can I remove the current one and install the version I need? I've never used Ruby so I'm SO lost. A little advice will mean a lot. bundle install

2021-06-15 18:15:34   ruby   github   rubygems   jekyll

How to make WindowBuilder create fields that are not nested in Eclipse, Java

I am using WindowBuilder for Eclipse Java. When I make a Button or a Menu (or anything), it creates the fields nested inside of the constructor. Is there any way to make them fields and then initialized in the constructor so I can use them outside of the constructor? Thank you. ie: FROM public GUIFrame() { JMenuBar menuBar = new JMenuBar(); } TO public JMenuBar menubar; public GUIFrame() { menuBar = new JMenuBar(); }

2021-06-15 18:15:27   java   eclipse   user-interface   windowbuilder

Swift UI Test - User Notifications System Alert

I'm trying to get past the User Notification system alert by following the flow presented in the follow post, which is the same flow mentioned in the UI testing cheat sheet and a few other posts on SO. Xcode7 | Xcode UI Tests | How to handle location service alert? I'm having a strange problem where I can't hit the OK button. Here is my code addUIInterruptionMonitorWithDescription("User Notifications") { (alert) -> Bool in let okButton = alert.buttons["OK"] let dontAllowButton = alert.buttons["Don\u{2019}t Allow"] print(okButton.frame) print(dontAllowButton.frame) okButton.tap() // Taps the

2021-06-15 18:13:50   swift   xcode-ui-testing