Spring-Integration in Java Config

Question: I have to convert a project using Spring integration in xmls to Java config, and tried below, but I am getting exceptions.
What I am trying to achieve is, create a message listener which listens messages on a queue destination, puts it on to a channel, which is read and processed by a xsl transformer that puts in the next channel, which is again read and processed by JaxbUnmarshaller to create to Java object and put it the third channel, which will be consumed by a Java Consumer. In case of error, the message is put on a error channel which is again the same Java Consumer that handles it.
Below is the Spring config
  <int:channel id="channel_1"/>
  <int:channel id="channel_2"/>
  <int:channel id="channel_3"/>
  <int:channel id="channel_error"/>

  <int-jms:message-driven-channel-adapter connection-factory="factory" destination-name="destName"
       pub-sub-domain="false" channel="channel_1" error-channel="channel_error"/>

  <int-xml:xslt-transformer input-channel="channel_1" output-channel="channel_2" xsl-resource="classpath:sample.xsl"/>

  <int-xml:unmarshalling-transformer input-channel="channel_2" output-channel="channel_3" unmarshaller="unmarshaller"/>

  <oxm:jaxb2-marshaller id="unmarshaller">
    <oxm:class-to-be-bound name="sample.example.MyData"/>
  </oxm:jaxb2-marshaller>

  <int:outbound-channel-adapter channel="channel_3" ref="consumer" method="handleMessage"/>

  <bean id="consumer" class="sample.example.MyConsumer"></bean>

  <int:outbound-channel-adapter channel="channel_error" ref="consumer" method="handleError"/>

Below is the Java Config I have for this
  @Bean
  public MessageChannel channel_1() {
    return new DirectChannel();
  }
  @Bean
  public MessageChannel channel_2() {
    return new DirectChannel();
  }
  @Bean
  public MessageChannel channel_3() {
    return new DirectChannel();
  }
  @Bean
  public MessageChannel channel_error() {
    return new DirectChannel();
  }
  @Bean
  @Autowired
  public DefaultMessageListenerContainer container(String destinationQueueName) {
    DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
    container.setConnectionFactory(factory());
    container.setDestinationName(destinationQueueName);
    container.setPubSubDomain(false);
    container.setMessageListener(messageListener());
    return container;
  }

  @Bean
  public ChannelPublishingJmsMessageListener messageListener(){
    ChannelPublishingJmsMessageListener adapter = new ChannelPublishingJmsMessageListener();
    adapter.setRequestChannel(channel_1());
    adapter.setErrorChannel(channel_error());
    return adapter;
  }

  @Bean
  @Transformer(inputChannel = "channel_1", outputChannel = "channel_2")
  public XsltPayloadTransformer transformer() {
    return new XsltPayloadTransformer(new ClassPathResource("sample.xsl"));
  }

  @Bean
  @Transformer(inputChannel = "channel_2", outputChannel = "channel_3")
  public UnmarshallingTransformer unmarshallingTransformer() {
    return new UnmarshallingTransformer(unmarshaller());
  }

  @Bean
  public Jaxb2Marshaller unmarshaller() {
    Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller();
    unmarshaller.setClassesToBeBound(MyData.class);
    return unmarshaller;
  }

  @Bean
  @ServiceActivator(inputChannel = "channel_3")
  public MessageHandler messageHandler() {
    return new MethodInvokingMessageHandler(consumer(), "handleMessage");
  }

  @Bean
  @ServiceActivator(inputChannel = "channel_error")
  public MessageHandler errorHandler() {
    return new MethodInvokingMessageHandler(consumer(), "handleError");
  }

I get the below exception, when I refer for this exception, it says that service activator is not configured properly. I am not sure what I am missing, can someone please help.
  org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'org.springframework.web.context.WebApplicationContext:/v1.channel_error'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:81)
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:287)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:95)
    at org.springframework.integration.gateway.MessagingGatewaySupport.send(MessagingGatewaySupport.java:281)
    at org.springframework.integration.jms.ChannelPublishingJmsMessageListener$GatewayDelegate.send(ChannelPublishingJmsMessageListener.java:479)
    at org.springframework.integration.jms.ChannelPublishingJmsMessageListener.onMessage(ChannelPublishingJmsMessageListener.java:322)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:674)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:634)
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:605)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:308)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:246)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1144)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1136)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1033)
    at java.lang.Thread.run(Thread.java:745)
  Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:107)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
    ... 16 more

Logs on start up :
2016-03-30 13:06:46,423 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [servletConfigInitParams] PropertySource with lowest search precedence
2016-03-30 13:06:46,403 DEBUG com.amazonaws.jmx.MBeans.registerMBean[58] - Failed to register mbean com.amazonaws.management:type=AwsSdkMetrics
javax.management.InstanceAlreadyExistsException: com.amazonaws.management:type=AwsSdkMetrics
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900)
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324)
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522)
    at com.amazonaws.jmx.MBeans.registerMBean(MBeans.java:52)
    at com.amazonaws.jmx.SdkMBeanRegistrySupport.registerMetricAdminMBean(SdkMBeanRegistrySupport.java:27)
    at com.amazonaws.metrics.AwsSdkMetrics.registerMetricAdminMBean(AwsSdkMetrics.java:355)
    at com.amazonaws.metrics.AwsSdkMetrics.<clinit>(AwsSdkMetrics.java:316)
    at com.amazonaws.AmazonWebServiceClient.requestMetricCollector(AmazonWebServiceClient.java:629)
    at com.amazonaws.AmazonWebServiceClient.isRMCEnabledAtClientOrSdkLevel(AmazonWebServiceClient.java:570)
    at com.amazonaws.AmazonWebServiceClient.isRequestMetricsEnabled(AmazonWebServiceClient.java:562)
    at com.amazonaws.AmazonWebServiceClient.createExecutionContext(AmazonWebServiceClient.java:523)
    at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:525)
    at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.getQueueUrl(AmazonSQSMessagingClientWrapper.java:260)
    at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.getQueueUrl(AmazonSQSMessagingClientWrapper.java:230)
    at com.amazon.sqs.javamessaging.SQSSession.createQueue(SQSSession.java:576)
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveQueue(DynamicDestinationResolver.java:84)
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveDestinationName(DynamicDestinationResolver.java:58)
    at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:98)
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:204)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1167)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1143)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1136)
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1033)
    at java.lang.Thread.run(Thread.java:745)
2016-03-30 13:06:46,423 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [servletConfigInitParams] PropertySource with lowest search precedence
2016-03-30 13:06:46,427 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [servletContextInitParams] PropertySource with lowest search precedence
2016-03-30 13:06:46,427 DEBUG com.amazonaws.metrics.AwsSdkMetrics.registerMetricAdminMBean[369] - Admin mbean registered under com.amazonaws.management:type=AwsSdkMetrics/4
2016-03-30 13:06:46,427 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [servletContextInitParams] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [jndiProperties] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [jndiProperties] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [systemProperties] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [systemProperties] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [systemEnvironment] PropertySource with lowest search precedence
2016-03-30 13:06:46,428 DEBUG org.springframework.web.context.support.StandardServletEnvironment.addLast[109] - Adding [systemEnvironment] PropertySource with lowest search precedence
2016-03-30 13:06:46,429 DEBUG org.springframework.web.context.support.StandardServletEnvironment.<init>[126] - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2016-03-30 13:06:46,429 DEBUG org.springframework.web.context.support.StandardServletEnvironment.<init>[126] - Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2016-03-30 13:06:46,432 DEBUG com.choiceedge.library.common.service.v1.endpoint.AbstractEndpoint$RequestContextAwareFilter.init[177] - Initializing filter 'RequestContextAwareFilter'
2016-03-30 13:06:46,436 DEBUG com.choiceedge.library.common.service.v1.endpoint.AbstractEndpoint$RequestContextAwareFilter.init[202] - Filter 'RequestContextAwareFilter' configured successfully
2016-03-30 13:06:46,437 DEBUG com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials[105] - Loading credentials from EnvironmentVariableCredentialsProvider
2016-03-30 13:06:46,438 DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBean[248] - Returning cached instance of singleton bean 'cxf'
2016-03-30 13:06:46,438 DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBean[248] - Returning cached instance of singleton bean 'cxf'

This is how I register my AppConfig in my WebApplicationInitializer
  @Override
  public void onStartup(final ServletContext servletContext) throws ServletException {

    rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.getEnvironment().setActiveProfiles(System.getenv(ENVIRONMENT));
    LOGGER.info(System.getenv(ENVIRONMENT));
    System.out.println("Starting application in " + System.getenv(ENVIRONMENT));
    rootContext.register(AppConfig.class);
    rootContext.setDisplayName(DISPLAY_NAME);

    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));
.....

And in my AppConfig I have
@Configuration
@ImportResource("...") - this is for another custom library
@ComponentScan(...)
@EnableIntegration
public class AppConfig {

Answer: Haven't you missed @EnableIntegration on your @Configuration?

Starting with version 4.0, the @EnableIntegration annotation has been introduced, to allow the registration of Spring Integration infrastructure beans (see JavaDocs). This annotation is required when only Java & Annotation configuration is used, e.g. with Spring Boot and/or Spring Integration Messaging Annotation support and Spring Integration Java DSL with no XML integration configuration.

http://docs.spring.io/spring-integration/docs/4.3.0.BUILD-SNAPSHOT/reference/html/overview.html#configuration-enable-integration
Comment: Hi Artem, I do have both of the annotations on my class.
Comment: OK. Switch on the `DEBUG` logging level for the `org.springframework` category and share logs just after the application starting. Seems for me you have there something like parent-child config and it is Web application. You might need to duplicate `@EnableIntegration` in several your `@Configuration` classes to reach the parent-child configuration nature.
Comment: I added the Logs on start up Artem. There is this one exception while registering the destination on the listener container but am not sure if that is stopping Spring from loading all the beans ? I also dont see any logs saying about the beans instantiated in the context
Comment: I don't see in your logs the Spring Integration stuff loading. So, that means that you don't have `@EnableIntegration` for your application, or you don't show the full application startup logs...
Comment: thats all the logs I see, I even posted how i am registering the AppConfig
Comment: Well, or your `WebApplicationInitializer` isn't visible for scanning or you have there such a profile that doesn't allow to load your `AppConfig`. From other side you have there several `System.out.println()`, but we don't see them in your logs. We can't help if the info provided isn't consistent. Try to simplify your application as much as possible around the ` Dispatcher has no subscribers` problem and share the app with me to play from my side. Right now I don't have any clues to help you. Sorry.
Comment: I am sure my appconfig is loading or atleast parts of it, because I have a REST service as well in the application and its working fine. I am having issues only on processing these queue messages. Anyways, I will try to make a small sample project and share you that
Comment: Yeah... Since it doesn't work in the forehead there is something nasty which we definitely have to catch and fix. That's why I'm asking about simple app to play locally.
Comment: Hi Artem, When I created a sample application I found it working without issues. Looking through the logs, I noticed that the subscriber was created only for the error channel and not for others. Autowiring the channel to the listener actually resolved the issue. I have added an answer with the changes. Thank you
Answer: SOLVED : The changes that resolved the issue, was to autowire the channels to the listener. And Make the PropertyPlaceHolderConfigurer bean as static
@Bean
@Autowired
public ChannelPublishingJmsMessageListener messageListener(MessageChannel channel_1, MessageChannel channel_error){
    ChannelPublishingJmsMessageListener adapter = new ChannelPublishingJmsMessageListener();
     adapter.setRequestChannel(channel_1);
     adapter.setErrorChannel(channel_error);
     return adapter;
}

Comment: Ok, that's great! Actually I think that the real trap was exactly non-static PropertyPlaceholderConfigurer. Any BeanPostProcessor must be declared as static.

Spring-Integration in Java Config


What order does the sshd_config files use values for the settings MACs and Ciphers?

Question: I am currently using MACs and Ciphers in my sshd_config. We have these settings being scanned for vulnerabilities.
I would like to know if the order of these settings matters at all?
Currently, they are:
MACs hmac-sha2-256,hmac-sha2-512
Ciphers aes128-ctr,aes192-ctr,aes256-ctr

Does this behave any differently:
MACs hmac-sha2-512,hmac-sha2-256
Ciphers aes256-ctr,aes192-ctr,aes128-ctr

If the values for the settings are moved around into a different order does that matter?
If it does matter can you possibly link some documentation on your answer?
Answer: Yes, the order differs since both MACs and Ciphers will set the allowed and order of preference.
From ssh_config manpage:

Ciphers
Specifies the ciphers allowed and their order of preference.  Multiple ciphers must be comma-separated.  If the specified list begins with a '+' character, then the specified ciphers will be appended to the default set instead of replacing them.  If the specified list begins with a '-' character, then the specified ciphers (including wildcards) will be removed from the default set instead of replacing them.  If the specified list begins with a '^' character, then the specified ciphers will be placed at the head of the default set.

MACs
Specifies the MAC (message authentication code) algorithms in order of
preference.  The MAC algorithm is used for data integrity protection.
Multiple algorithms must be comma-separated.  If the specified list
begins with a '+' character, then the specified algorithms will be
appended to the default set instead of replacing them.  If the
specified list begins with a '-' character, then the specified
algorithms (including wild‐cards) will be removed from the default set
instead of replacing them.  If the specified list begins with a '^'
character, then the specified algorithms will be placed at the head of
the default set.

Although, since they are set as preferred orders, it will not prevent a client from having a different preference for negotiation, nor any Cipher or MAC missing.


Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8

Question: As per mentioned in developer.android website

"The Jack toolchain is deprecated, as per this announcement. If your
  project depends on Jack, you should migrate to using Java 8 support
  built into Android Studio's default toolchain."

I need to use lambda expressions so I have disabled the jack options, but when I compile my code, I get the following error
Error:Jack is required to support Java 8 language features. Either enable Jack or remove sourceCompatibility JavaVersion.VERSION_1_8.

Below is the screenshot of my build.gradle file
Answer: Check you version of com.android.tools.build:gradle.
I had the same error. My solution:

set com.android.tools.build:gradle:3.0.0-alpha6
update kotlin to 1.1.3-2
add to repositories google()

I'm using AS 3.0 Canary 6.
Comment: what if we don't use the beta version of AS, no workaround on this?
Answer: You should do the following:

Update your Android Studio to version 3.0.1.
Upgrade your gradle to 'com.android.tools.build:gradle:3.0.1'
Make sure you buildToolsVersion is at least 26.0.2.

After that you can remove Jack options and use supported Java 8 features.


How to do VPN split tunneling for urls and IP addresses on Windows 11

Question: On Windows 11 I want any traffic going to long.dns.name.amazonaws.com (DataGrip Redshift connection) and http://n.n.n.n:8000/ (Airbyte hosted on EC2 with an elastic ip) to be routed through my VPN, but nothing else.
I disabled Use default gateway on remote network but have the following error adding the route:
PS C:\> Add-VpnConnectionRoute -ConnectionName 'xxx' -DestinationPrefix n.n.n.100/24
Add-VpnConnectionRoute:  Invalid parameter DestinationPrefix n.n.n.100/24. : The parameter is incorrect.

Will Add-VpnConnectionRoute work with a url address, not an IP address?
Comment: `126.96.36.199/24` why are you specifying a /24 starting at .100? Parameter incorrect indeed.
Comment: @GregAskew for the same reason i'm asking this question, I'm a developer not a network engineer
Comment: As others mentioned, you should step back and state what you are attempting to accomplish. Many organizations have detailed routing tables to accommodate split tunneling workers.
Comment: You aren't being asked what your job is or what you know. You were asked to simply explain what you did. We still don't know if it is a typo or cargo cult copy paste.
Answer: You cannot get this behavior exactly. Forwarding packets is always based on IP addresses: The entity that forwards packets checks the destination IP address and selects outgoing interface based on that information.
Only option you have is to route all the IP addresses that this domain name might have via VPN. This means that other domain names that map to that address space get forwarded via the VPN.
I think you need to go a step back and consider what exactly is the issue you are trying to solve with VPN and think of some other solution.
About the error message above: 18.104.22.168/24 is an invalid network specification. /24 networks always start at .0 and cover 256 addresses. In your case I think you meant 18.104.22.168/32 to cover a single IP address.


Poster image for video embedding

Question: On my home page I have 4 embedded videos. To reduce loading time I would like to generate thumbnails that link to an other page with the real embedded video.
How can I generate these thumbnails?
Noting that :

embedded videos come from several video shraing websites (dailymotion, youtube, vimeo or for example : this video ...)
videos are added dinamicaly every day by the site administrator and he can't make the thumbnail manualy for each video.
Comment: Video sharing websites already provide solutions for that. youtube example : http://google.about.com/od/youtube/ss/embed-share-YouTube-videos.htm
Comment: yes but the embedded videos come from several websites like this video : http://www.letelegramme.fr/fil_region/fil_bretagne/landerneau-les-pompiers-demenagent-21-05-2013-2109919.php that don't provide a solution for that.
Comment: as Dan said, the thumbnails is provided by the video site. If you are trying to autogenerate a thumbnail for any video, I wish you good luck. If you just want to create a embeded mechanism, you can see that most of the embeded videos are flash players, built like this `...` This can be a cule.
Comment: ok, I'll have to find a way to retrieve those thumbnails for each video sharing website.
Answer: Keep in mind, embedded videos from other sites don't really slow load time.  When embedding video from another site like YouTube, it's usually flash, and it shows the thumbnails inside the player, and the video doesn't load until the user clicks play.  I know at least YouTube has predictable thumbnail image locations if you just wanted the graphic.  They can be found at
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg

Comment: thanks for the reply, the problem is that the videos can come from many different websites like the example I gave in my question. and they don't provide those thumbnails.
Comment: What is wrong with just using each site's own embedding thumbnails instead of images?
Comment: in fact they do provide the thumbnails. I'll have to find a way to retrieve the thumbnails form each video sharing website, that is going to be a hassle...
Comment: "... and they don't provide those thumbnails..." => "...in fact they do provide the thumbnails..." So ? When you embed a video, you don't have to manage the thumbnail, the providing site will do it for you.
Comment: For vimeo - http://stackoverflow.com/questions/1361149/get-img-thumbnails-from-vimeo , from Dailymotion - http://stackoverflow.com/questions/13173641/how-to-get-the-video-thumbnail-from-dailymotion-video-from-the-video-id-of-that .  That combined with the YouTube links above ought to handle it for ya, right?
Answer: this can help you if you need posters / thumbnails of your local videos try this link and                     this can also help   here is described how can we get poster image , size,length,title of videos using ff-mpeg in php
function captureVideoPosterImg($movie_file = '')
{
    extension_loaded('ffmpeg');
    $movie_file = 'E:\wamp new\www\projects\indiemade_live\developer\uploads\comments\11\14\video\04072011094613_24062011234404_s Sporting Goods- Teams Come Alive.flv';
    // Instantiates the class ffmpeg_movie so we can get the information you want the video
    $movie = new ffmpeg_movie($movie_file);
    // Get The duration of the video in seconds
    echo $Duration = round($movie->getDuration(), 0);
    // Get the number of frames of the video
    $TotalFrames = $movie->getFrameCount();
    // Get the height in pixels Video
    $height = $movie->getFrameHeight();
    // Get the width of the video in pixels
    $width = $movie->getFrameWidth();
    //Receiving the frame from the video and saving
    // Need to create a GD image ffmpeg-php to work on it
    $image = imagecreatetruecolor($width, $height);
    // Create an instance of the frame with the class ffmpeg_frame
    $Frame = new ffmpeg_frame($image);
    // Choose the frame you want to save as jpeg
    $thumbnailOf = (int) round($movie->getFrameCount() / 2.5);
    // Receives the frame
    $frame = $movie->GetFrame($thumbnailOf);
    // Convert to a GD image
    $image = $frame->toGDImage();
    // Save to disk.
    //echo $movie_file.'.jpg';
    imagejpeg($image, $movie_file.'.jpg', 100);

    return $movie_file.'.jpg';
}

Comment: While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference.  Link-only answers can become invalid if the linked page changes.
Comment: i have gived some info about what the page contains and also code

Poster image for video embedding


XSLT Consolidating data when ID is the same

Question: I am having some issues with consuming an XML and applying multiple conditions on it. I have an input XML that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <resultSets>
            <resultSet>
                <row>
                    <column1>11111</column1>
                    <column2>0</column2>
                    <column3>imageId/111111</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>11111</column1>
                    <column2>2</column2>
                    <column3>imageId/111112</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>11111</column1>
                    <column2>2</column2>
                    <column3>imageId/111113</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>22222</column1>
                    <column2>0</column2>
                    <column3>imageId/222222</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
                <row>
                    <column1>22222</column1>
                    <column2>2</column2>
                    <column3>imageId/222223</column3>
                    <column4>2012-04-03T10:11:22.187</column4>
                </row>
            </resultSet>
        </resultSets>
    </result>
</results>

However i would like it to look like this:
<?xml version="1.0" encoding="UTF-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <row>
            <id>11111</id>
            <lagrgeImage>imageId/111111</lagrgeImage>
            <smallImage>imageId/111112</smallImage>
            <smallImage>imageId/111113</smallImage>
        </row>
        <row>
            <id>22222</id>
            <lagrgeImage>imageId/222222</lagrgeImage>
            <smallImage>imageId/222223</smallImage>
        </row>
    </result>
</results>

As you can see there are two filtering condition:
If column2 = 0 then largeImage tag is needed in the output however column2 = 2 then smallImage tag is needed in the output.
UPDATE
Both of the examples below worked perfectly, however they are both including namespacing in the root that are unexpected. The output i get is:
<?xml version="1.0" encoding="utf-8"?>
<results xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType">
    <result>
        <row>
            <id>11111</id>
            <largeImage>imageId/111111</largeImage>
            <smallImage>imageId/111112</smallImage>
            <smallImage>imageId/111113</smallImage>
        </row>
        <row>
            <id>22222</id>
            <largeImage>imageId/222222</largeImage>
            <smallImage>imageId/222223</smallImage>
        </row>
    </result>
</results>

How do i remove xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType" from the above output?
Comment: @liveek: I have added a solution (which is even XSLT 1.0 compatiable) that runs a for-each loop once for each ID.
Comment: Are you able to use XSLT2.0 as this has dedicated commands for grouping.
Comment: XSLT2.0....I can for loop around however the bit i dont know how to do it to get the XSLT to know what was the ID in the last loop. If the id is the same as the one before at to the already created tag...if not add a new tag with the new id. How do you do this?
Comment: @O. R. Mapper this was the bit i did not know how to do `preceding-sibling::` thanks
Comment: @liveek: Glad to hear that :-) Please mark the solution as accepted if you have no further questions left, or otherwise write a comment below my solution so I'll notice if you need any further info :-)
Answer: If you are using XSLT2.0 you make use of the for-each-group function.
<xsl:for-each-group select="row" group-by="column1">

Assuming your context is resultSets this would group the rows by the 'id' in column1. The current grouping key could then be obtained as follows:
<xsl:value-of select="current-grouping-key()"/>

And to get the various rows in the group, to transform them to either largeImage or smallImage, you would do this
<xsl:apply-templates select="current-group()" />

Here is the full XSLT
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.castiron.com//response">

   <xsl:output method="xml" indent="yes"/>

   <xsl:template match="resultSets">
      <xsl:apply-templates select="@*|node()"/>
   </xsl:template>

   <xsl:template match="resultSet">
      <xsl:apply-templates select="@*"/>
      <xsl:for-each-group select="row" group-by="column1">
         <row>
            <id><xsl:value-of select="current-grouping-key()"/></id>
            <xsl:apply-templates select="current-group()" />
          </row>
      </xsl:for-each-group>
   </xsl:template>

   <xsl:template match="row[column2='0']">
      <largeImage><xsl:value-of select="column3" /></largeImage>
   </xsl:template>

   <xsl:template match="row">
      <smallImage><xsl:value-of select="column3" /></smallImage>
   </xsl:template>

   <xsl:template match="@*|node()[not(self::*)]">
      <xsl:copy>
         <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
   </xsl:template>

   <xsl:template match="*">
      <xsl:element name="{local-name()}">
         <xsl:apply-templates select="@*|node()"/>
      </xsl:element>
   </xsl:template>
</xsl:stylesheet>

When applied to your sample XML, the following is output
<results xmlns="http://www.castiron.com//response">
   <result>
      <row>
         <id>11111</id>
         <largeImage>imageId/111111</largeImage>
         <smallImage>imageId/111112</smallImage>
         <smallImage>imageId/111113</smallImage>
      </row>
      <row>
         <id>22222</id>
         <largeImage>imageId/222222</largeImage>
         <smallImage>imageId/222223</smallImage>
      </row>
   </result>
</results>

Comment: This works perfectly; however i am getting the following namespacing in the root node `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType"` is there a way to remove it? Root Node: ``
Comment: I did exclude the namespace from my input sample, to keep it simple. Can you amend the question though, to show the expected output with the new root node and namespace, and I will see if I can amend my answer.
Comment: I've made an amendment to remove the old namespace and add a new one.
Answer: For spitting out the 'largeimage' and 'smallimage' elements (in an xsl for loop) try:

<xsl:if test="/results/result/resultSets/resultSet/row/column2='0'">
<largeImage>
<xsl:value-of select="/results/result/resultSets/resultSet/row/column3"/>
</largeImage>
</xsl:if>

Comment: How do you join multiple IDs together. I get the for loop, loop through every ID however how do i add it to the previous if the same id was the one before? Does that make sense?
Comment: This looks like a step in the right direction: http://www.jguru.com/faq/view.jsp?EID=548449
Answer: In XSLT 1.0, the (IMO) most straightforward solution is to first find all unique IDs. This can be achieved by looking for IDs that did not appear in any preceding siblings (in other words, for each ID, you find the first element that contains that ID).
Once you have a unique ID, you can <xsl:for-each> over all <row> siblings (including the current element) with the same ID. In the below code, I have used an <xsl:choose> element to check <column2> and insert a <largeImage> or <smallImage> element based on the <column2> value.
This does what you are looking for:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/results">
        <results>
            <xsl:copy-of select="@*"/>
            <result>
                <xsl:apply-templates select="result"/>
            </result>
        </results>
    </xsl:template>

    <xsl:template match="/results/result/resultSets/resultSet/row">
        <xsl:if test="not(column1 = preceding-sibling::row/column1)">
            <row>
                <id><xsl:value-of select="column1"/></id>
                <xsl:for-each select="../row[column1 = current()/column1]">
                    <xsl:choose>
                        <xsl:when test="column2 = '0'">
                            <largeImage><xsl:value-of select="column3"/></largeImage>
                        </xsl:when>
                        <xsl:when test="column2 = '2'">
                            <smallImage><xsl:value-of select="column3"/></smallImage>
                        </xsl:when>
                    </xsl:choose>
                </xsl:for-each>
            </row>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>

Comment: This works perfectly; however i am getting the following namespacing in the root node `xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ResultsType"` is there a way to remove it? Root Node: ``
Comment: Just omit the line `` from the XSLT. That line is responsible for copying the attributes of the `` element.


$ tr(TS)=0$ and $T,S$ are positive, compact implies $TS=0$

Question: Suppose $T$ and $S$ are positive compact operators and Tr$(TS)=0$ , then show $TS=ST=0$.
Attempt: Apply the spectral decomposition for $T$ to obtain $\lambda_n(T)$ and corresponding orthonormal sequence ${e_n}$. $0=\sum_n \langle TS e_n,e_n\rangle =
 \sum_n \langle S e_n,\lambda_n(T) e_n\rangle $.
Since $\lambda_n(T)$ is positive and $S$ is positive, if $\lambda(T)$ has infinite many non-zeros then $S=0$.
So assume finitely nonzero up to N, then $\langle S e_n, e_n\rangle =0$ for $n=1,..N$.
I'm stuck here, its still not enough to show $ST=0$
Answer: Notice that $(Se_n, e_n) = || \sqrt{S}e_n ||^2 =0$. Hence, $\sqrt{S}e_n =0$ and thus $Se_n = 0$. Therefore, $S = 0$ on the image of $T$ and thus $ST = 0$
Comment: Is it obvious that $TS$ is self-adjoint, i.e. $TS = ST$?
Answer: Note that given the spectral decomposition $T(x) = \sum_{n=1}^\infty \lambda_n(T)\langle x,e_n\rangle e_n$, there is a unique positive operator $$T^{1/2}(x)=\sum_{n=1}^\infty \sqrt{\lambda_n(T)}\langle x,e_n\rangle e_n$$ such that $T^{1/2}T^{1/2}=T$. As was already proven in the OP, we have for each $n\ge 1$,
$$
 \langle Se_n,\lambda_n(T)e_n\rangle = \langle S^{1/2}\sqrt{\lambda_n(T)}e_n, S^{1/2}\sqrt{\lambda_n(T)}e_n\rangle = \|S^{1/2}\sqrt{\lambda_n(T)}e_n\|^2 =0.
$$ Since $T^{1/2}e_n = \sqrt{\lambda_n(T)}e_n$, we obtain for each $n\ge 1$,
$$
S^{1/2}T^{1/2}e_n=0,
$$ i.e. $S^{1/2}T^{1/2}=O$. This implies $$
ST = S^{1/2}(S^{1/2}T^{1/2})T^{1/2} = O
$$ and $$TS = (ST)^*=O$$ as wanted.


How to create a table in MySQL with automatic numeration of rows?

Question: I just want to have a table in which a first column is a monotonically increasing unique integer number. For example, if I have a table with 5 rows the indexes of the rows should be 1,2,3,4,5. And if I add a new row it gets index 6.
I am alway confused with this things because there are many related options: "auto_increment",  "primary key", "unique", "index". What should I use?
Comment: stackoverflow maybe?
Answer: CREATE TABLE test (
     id INT NOT NULL AUTO_INCREMENT,
     name CHAR(30) NOT NULL,
     PRIMARY KEY (id)
 );
auto_increment: This value will automatically increase.
primary key: This is the column which holds the first, and probably most logical, sort order. Almost always this means that it's unique.
index: This column is one which might be chosen as a sort order. Any column or combination of columns can be indexed, not just the primary key.
unique: This is a special index, where each value is going to appear only once.
Comment: Just to be sure that I got it right. Since "id" is declared as a "PRIMARY KEY", the "id" will be used as a the default column for ordering or rows when "select" is used. Is it right? But what if I do not use "PRIMARY KEY (id)"? Rows will be displayed in a random order?
Comment: primary key isn't necessarily sort order. Unless you give a specific sort order, the database is free to return the rows in any order, usually in the one they are found on the disk, which in the case of an autoincrement id column usually is the same, but doesn't have to be. And this question probably belongs to stackoverflow and not serverfault.
Comment: So, than I do not understand what "PRIMARY KEY (id)". You said "it holds the firs, and probably most logical, sort order". But what does it means? What if I remove "PRIMARY KEY" from your example? What will it affect? P.S. Can I move my question to stackoverflow?
Comment: PRIMARY KEY is basically a comment. You could do the exact same thing by defining a unique index, but by putting primary key you're letting anyone who looks at the schema know your intent.


How to present and compare mixed models vs. regular linear regression models?

Question: The regular linear regression model is easy to present; we are minimizing the sum of the least square errors:  $$\sum_{i=1}^{n} ( y_i - \hat{y}_i)^2$$
How do we present the mixed model? More specifically, we are wondering about how to present the following simple model:
<code>lmefit = lmer(MathAch ~ SES + (1 |School) , MathScores)
</code>
We need to explain/present the model to some one who are not of statistical background.
 Our questions are:
(a) What objective function are we minimizing here?
We don't want to show that
  $$y = X \beta + Zb + e$$
Because this is not very intuitive, especially the $Zb$ part.Is there a way that we could intuitively see what we are doing via the mixed-model approach?
(b) Is there a presentation-friendly way of comparing the regular linear regression vs. the mixed model above? Hopefully we can visualize them intuitively.
(c) What sorts of model-checking and post-fit-diagnosis could we show for mixed-model?
What are the typical goodness-of-fit checking procedures?
(d) How do we show the benefit of using mixed model vs. regular linear regression?
Hopefully there are some visualization or intuitive arguments that we can put into one slide?
Could anybody please shed some lights to us? We also appreciate any good books/resources one this.
Thanks a lot!
[c.p. on R-mixed list in case no one sees our questions... Thank you!]
Comment: Well, why exactly are you using a mixed model? If you can explain that to your audience, this could go a long way in terms of providing intuition for the audience.
Answer: The random effects are effects that we can view as being pick from a population of possible effects.  In clincial trials we often have multicenter studies.  In analyzing the study results we often use a mixed model wher the centers are random effects.  This makes sense because we have a large population of potential sites out of which we selected the few that are in the study.  They are not really selected at random but we do want to incorporate the variability associated with the choice of sites.  Another choice would probably give different results.  So it is much more realistic to think of the site effect as random rather than fixed because the fixed effect assumption would mean that if say we selected 10 sites the effect would not change if we picked a different set of 10.  I think this gives some insight in layman's terms to what random effects are.  in other applications it may not be so clear.


What fingerings are used for the minor and major blues scales?

Question: It's my understanding that for the diatonic scales, there's a consensus of which fingerings are optimal for most people. They are not a hard rule, some pianists use other fingerings, but they are still recommended and presented as a great starting point. Something like this.
Because of this, if you search for diatonic scale fingerings, 99% of the time you'll find the exact same fingerings everywhere. They tend to work really well for most people.
Is there something similar for the minor and major blues scales? Which are the recommended fingerings for a complete run through these scales?
Comment: Hopefully a more experienced pianist will have an answer for you. I personally just view them as major/minor with the extra passing tone when I play it so my fingering is derived from that unlike the other two (which even they are slightly different) so there may not be a standard fingering for them.
Comment: [This pdf](http://www.playpianotoday.com/blues-11-fingering-charts-one-and-two-octave-blues-scales.pdf) covers all 12 scales pretty well should give you a good idea what to use as does [this site](http://www.freejazzlessons.com/blues-scale-piano/).
Answer: Instead of learning the "best" or "correct" fingering for every different scale, I think it's better to learn some general principles, and then work out the details for yourself.

The repeated pattern of fingers is 1 2 3 1 2 3 4 - but not necessarily starting on 1, because ....
Don't use your thumb on the black keys.
With the right hand, use your thumb on the note AFTER a black key for a scale going up, and the note BEFORE a black key for a scale going down. This makes it easier to pass the thumb under the fingers.
For the left hand, use the mirror image of #3 above.
If the above principles still leave you with a choice of fingering, use your thumb on the most important note(s) of the scale, for example on the key note or on the main beats in the bar.

You will find most "fingering charts" agree with those general principles, but they often give alternative fingerings which are just as good as the one option shown on a chart, and may be more useful when the scale passage is part of a piece and not just a technical exercise.
Just as a historical note, there is a consensus about this for modern keyboard technique for all types of music, but historically scales were fingered very differently. For example in the 16th century the standard fingering for the right hand going up was 2 3 2 3 2 3 4 - i.e. no thumb and 5th finger at all! In the 18th century, right hand scales were fingered similar to the modern method, the left hand scales down were often fingered 1 2 1 2 1 2 3.
Answer: I'm not aware of standard fingerings for the major or minor blues scales in the same sense that there are standards for the diatonic scales. But here are the guidelines I use:
Right hand

When possible, use 1 on the white keys and 3 (my preference) or 2 on the black keys. (pattern "A")
When that doesn't work, use 1-2-3-1-2-3 (pattern "B") (This is mostly for scales having consecutive black keys.)
In the major blues scales, sometimes it's easier to use 1-2-3-4-1-2 (pattern "C".

Left hand

Break the scale into two segments with fingerings 4321 and 31. (pattern "A")
Break the scale into two segments with fingerings 421 and 321. (pattern "B")

Here are the keys I use with each pattern:
Minor blues scales
The minor blues scale is: 1 b3 4 #4(b5) 5 b7 (1 ...)
The scales that use each pattern are:

Right hand
[A]: C  C#/Db  D         E     F#/Gb  G         A
[B]:              D#/Eb     F            G#/Ab     A#/Bb  B

Left hand
[A]: C  C#/Db  D  D#/Eb     F            G#/Ab     A#/Bb
[B]:                     E     F#/Gb  G         A         B

And the complete fingering list:

Key    RH fingering  [RH pattern]
       LH fingering  [LH pattern]
---    --------------------------

C      1 3 1 3 1 3 1 [A]
       1 3 1 4 3 2 1 [A] (ALT: 1 3 1 3 1 3 1)

C#/Db  3 1 3 1 3 1 3 [A]
       3 1 4 3 2 1 3 [A] (ALT: 3 1 3 1 3 1 3)

D      1 3 1 3 1 3 1 [A]
       3 1 4 3 2 1 3 [A]

D#/Eb  1 2 3 1 2 3 1 [B]
       4 3 2 1 3 1 4 [A]

E      1 3 1 3 1 3 1 [A]
       4 2 1 3 2 1 4 [B]

F      1 2 3 1 2 3 1 [B]
       1 4 3 2 1 3 1 [A]

F#/Gb  3 1 3 1 3 1 3 [A]
       4 2 1 3 2 1 4 [B]

G      1 3 1 3 1 3 1 [A]
       4 2 1 3 2 1 4 [B]

G#/Ab  1 2 3 1 2 3 1 [B]
       2 1 3 1 4 3 2 [A]

A      1 3 1 3 1 3 1 [A]
       4 2 1 3 2 1 4 [B]

A#/Bb  1 2 3 1 2 3 1 [B]
       4 3 2 1 3 1 4 [A]

B      1 2 3 1 2 3 1 [B]
       4 2 1 3 2 1 4 [B]

Major blues scales
The major blues scale is: 1 2 b3 3 5 6 (1 ...)
The scales that use each pattern are:

Right hand
[A]:              D#/Eb  E                          A#/Bb
[B]: C                      F         G   G#/Ab
[C]:    C#/Db  D               F#/Gb             A         B

Left hand
[A]: C            D#/Eb  E                G#/Ab  A  A#/Bb
[B]:    C#/Db  D            F  F#/Gb  G                    B

And the complete fingerings:

C      1 2 3 1 2 3 1 [B]
       3 1 4 3 2 1 3 [A]

C#/Db  1 2 1 2 3 4 1 [C] (ALT: 1 2 3 1 2 3 1 [B])
       3 2 1 4 2 1 3 [B]

D      1 2 3 4 1 2 1 [C]
       3 2 1 4 2 1 3 [B] (ALT: 3 1 4 3 2 1 3 [A])

D#/Eb  3 1 3 1 3 1 3 [A]
       3 1 4 3 2 1 3 [A]

E      1 3 1 3 1 3 1 [A]
       1 4 3 2 1 3 1 [A]

F      1 2 3 1 2 3 1 [B]
       2 1 3 2 1 4 2 [B] (ALT: 3 1 4 3 2 1 3 [A])

F#/Gb  1 2 1 2 3 4 1 [C]
       3 2 1 4 2 1 3 [B]

G      1 2 3 1 2 3 1 [B]
       3 1 4 3 2 1 3 [A]

G#/Ab  2 3 1 2 3 1 2 [B]
       4 3 2 1 3 1 4 [A] (ALT: 3 2 1 4 2 1 3 [B]

A      1 2 3 4 1 2 1 [C] (ALT: 1 3 1 3 1 3 1 [A])
       2 1 3 2 1 4 2 [A]

A#/Bb  3 1 3 1 3 1 3 [A] (ALT: 3 1 3 1 *2* 1 3)
       2 1 3 2 1 4 2 [B] (ALT: 4 3 2 1 3 1)

B      1 2 1 2 3 4 1 [C]
       1 3 1 4 3 2 1 [A]


fixed point conversion from a real variable in vhdl

Question: I have the following code snippet in vhdl:
signal s: signed(31 downto 0);
s <= to_signed(to_sfixed(1.2,8,-23),32);

Now I am expecting the fixed point version of 1.2 to be available in the signal 's'.
But it always neglects the fraction part. The 's' just contains the decimal part(here "1").
What am I missing here?
Answer: s doesn't have anywhere to store any fractional part, it's a signed vector which can only represent integers.
You're nearly there though - drop the signedness and make s and sfixed type:
signal s: sfixed(8 downto -23);
s <= to_sfixed(1.2,sfixed'high,sfixed'low);

Comment: But the problem is that I am using this signal as an input to a module where 's' should be of signed format. since fixed_pkg is not synthesisable in many platforms I am using it only in the testbench code.
Comment: fixed_pkg should be synthesisable just fine.  If you can;t use it, you'll have to shift the sfixed value and keep track of where the binary point is yourself...
Answer: If you just want to reinterpret the bits from the sfixed to as signed type, just use a simple type conversion:
signal s: signed(31 downto 0);
...
s <= signed(to_sfixed(1.2,8,-23));

Comment: awesome thanks.. just as a side note, for the back conversion you can use this:  r <= to_real(to_sfixed(std_logic_vector(s),8,-23)); where r is a real type.
Comment: Doing it this way, *you* have to keep track of the binary point.  It'd be better (IMHO) to keep to `sfixed` all the way through and let the compiler keep track of it.  If the destination is *really* out of your control, then you have no choice but to manage it.  I'd make sure I created some constants for the `8` and `-23` in case you want to change them in future though.
Comment: I agree with Martin that using the right types to represent your data all the way through the design is the best way to do it. On the other hand, you often have to interface with designs that don't do it this way, and it's good to know how to convert between different representations. =)


What skills or traits should a "Sr. Systems Engineer" have?

Question: I'd like to know what sklls or traits you expect to see when you see someone with the title "Sr. Systems Engineer".
Do certifications matter?  If so, which ones?
Do you expect them to obtain any other special recognition or achievement within the industry?
Answer: I'm not all that keen on certifications. Sure, there are a few that are very good, but from what I've seen, the vast majority of "certifications" out there are nothing more than rote memorization and a means to add a bullet point to one's resume.
Above all certifications, training, etc., the ability to adapt quickly, troubleshoot in a logical manner, and delve deeply into OS internals, all the while maintaining a "10,000 foot" view of the environment you're working in are critical characteristics of a good Systems Engineer.
Answer: I've found that regardless of industry, certifications are not a clear indication once one gets past the point of more than a few (read 5 - 10) years of solid technical experience.  As explanation of what is more important than environment-, vendor- and application-specific knowledge, here are some core expectations I'm using to fill my current resource requirements in my department:

Level of Experience
Has had wide EXPOSURE to a variety of
  technologies and architectures, in a
  hands-on and directly-involved way.
  UNDERSTANDS the global inter-network
  fundamentally (e.g. from Ethernet and
  E-carriers to IP and BGP) and
  conceptually (e.g. from AS and IXP to
  NRO and IETF).  UNDERSTANDS computing
  principles, from flip-flops and ICs to
  OS design principles and software
  engineering practices to IPC and
  distributed computing.  Is CONFIDENT
  in their knowledge, and can
  effectively communicate it to
  technical and non-technical people
  alike.
Role Responsibility
Is intrinsically aware of the
  responsibility inherent in the role of
  being a systems administrator and/or
  IT professional, especially in a
  highly available, 24/7/365
  environment.  Fully UNDERSTANDS the
  business impact of their role, and
  actively pursues practices that assist
  with mitigating any negative
  consequences.
Smart
Has the aptitude and WILLINGNESS TO
  LEARN in a way beneficial to the
  business, the department and their own
  career.  Is able to effectively manage
  expectations and their own time,
  prioritizing according to communicated
  business requirements dynamically.
Get's Things Done
Has the proven ability to assume
  ownership and leadership to overcome
  institutional or other intertia, FOCUS
  ON BUSINESS NEEDS first and solve
  problems.

Generic as some of this may sound, no matter the education or certification of an individual, if they can't meet the majority of these, they are not senior, and any sort or critical reliance on them will prove this point.
Of course, standard disclaimers apply, and YMMV. ;)
Answer: Most of the jobs I've seen with Senior  in them seem to want 5-7 years experience.
However to my mind that is not very senior, so I reckon that should be a minimum.
In my current team (all seniors) the average amongst 6 guys is probably 12-15 years.
We are all RHCEs, but I that is more because the organisation sends us on the training.
In most cases I think we would have all passed the RHCE without much training - i.e. we were all at or better than that level already.
What I'd expect from a senior engineer is:
1) technical ability - doesn't have to know everything but has to know how to approach problems and how to find out what they need. i.e. must have good problem solving/fault finding skills and know how to find and assess specific knowledge quickly.
2) a very good, strong grasp of the basic tools - whatever they are for your platform. They know  what the standard tools are and know what they can do. May not know every option of every command, but they know most and are not surprised by anything in the OS portion of the filesystem.
3) a level of maturity that allows them to collect and weight evidence and then accept whatever will allow the fastest, bestest solution. I.e. will look at problems and solve them without ego.
4) will take ownership of problems
5) the ability to manage themselves and perhaps one or two other people - not full blown team lader or project manager type management, but if given a task that involves say themselves, a junior and someone from another team, the ability to do what is necessary from a non tech view to get the job done.
6) willing and able to share their knowledge and skills with other people within the organisation, whether that be other system engineers, app people, helpdesk dudes, whoever.
7) ability to prioritise
8) sufficient experience to be able to critically assess a system, either existing or proposed. e.g. be able to look at a system and say, "well to get the IOPs needed for X many transactions were going to need N spindles, and we'll need to have at least Y paths active to sustain transfer that over the iscsi network"
9) a very high level of  knowledge of the ancillary technologies that make your systems work, e.g. LDAP, AD, DNS, TCP/IP etc.
Answer: We all are not RHCE's I am 10+ years as a linux admin and never once got certified. I've never been asked in an interview what certs do I have.
Here are some of the things you need

able to see ahead plan 6-12 months out
able to lead jr admins and delegate work
know everything about what you admin.
be a problem solver
able to say no.. even to upper management.
so many more
Comment: "know everything"? Really? Seems like an admirable goal, but nearly impossible to attain. It seems like a more realistic statement would be "Know a *lot* about your systems, but also know where to look for help/reference if need be".


How to debug in Tensorflow2?

Question: I am new to Tensorflow and am currently working on Tensorflow2. I'm still having a hard time writing code, because I don't have the possibility to debug.
I already tried to get further with the line:
tf.executing_eagerly()

and

tf.print()

but this is only a small help compared to the "normal" debugging in python.
Is there a better possibility to debug the code and to view the content of variables?
The only thing I currently get is this view, but that doesn't give me any insight into the actual variables either:
Answer: Rather than using tf.print, use the normal Python's print if you are eagerly executing. You will be able to see the contents of the variables.
Comment: Unfortunately I do not see the content of the variable. I see information during debugging like "dtype", "shape", "graph", "value_index" and "_name" but unfortunately no information about the content of the tensor
Comment: If you are eagerly executing, it will show you the contents.
Comment: if I use print() in eager mode i get the following output: array([,
       ,
       ,
       ], dtype=object)
Comment: Just type the variable name and hit enter. If you are doing this in terminal or else just leave the name of variable there and run the code.
Comment: I use Visual Studio code as IDE. If I enter the pure variable name in a line, then no output is generated or nothing is output on the console
Comment: I added a picture of my currenct debugging view

How to debug in Tensorflow2?


Store age from Date of birth when use registration

Question: I am having a date of birth field in my registration form.

I want to add the age in user data when the reregistration form is
submitted.
How can I update the age in the field when crone is run.
Answer: Computed Field Module will do the job:

Computed Field is a very powerful field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.) This field is literally the Swiss Army knife of fields. So start cooking up your PHP based values!

You can also google "Drupal Computed Field Age" for more information.


JSP exception when I try to import static file

Question: I am trying to import javascript from a file into my jsp to be used as an in line script:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

The above code works 99% of the time but I see a few errors like this in my tomcat logs:
Jun 20, 2013 1:25:33 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspTagException: 304 /path/to/file.js
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.acquireString(ImportSupport.java:329)
    at org.apache.taglibs.standard.tag.common.core.ImportSupport.doEndTag(ImportSupport.java:171)
    at org.apache.jsp.WEB_002dINF.jsp.common.head.scripts_jsp._jspx_meth_c_005fimport_005f0(scripts_jsp.java:182)
    at org.apache.jsp.WEB_002dINF.jsp.common.head.scripts_jsp._jspService(scripts_jsp.java:85)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:605)
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:544)
    at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary.java:954)
    at org.apache.jsp.WEB_002dINF.jsp.game_jsp._jspService(game_jsp.java:181)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    .......

I found the code that throws the above exception in ImportSupport.java:
// disallow inappropriate response codes per JSTL spec
if (irw.getStatus() < 200 || irw.getStatus() > 299) {
    throw new JspTagException(irw.getStatus() + " " + stripSession(targetUrl));
}

So it looks like the servlet response code is 304.
The question is why? Is this a bug or am I missing something?
Update:
The problem seems to only occur if the incoming request has the If-Modified-Since header on
Update 2:
I solved the problem by removing the If-Modified-Since header from every request except for static files.
Comment: Why not simply use:
Comment: Try clearing the cache and try again .
Comment: @MickJ For performance reasons.
Comment: On the contrary you should get better performance by keeping it external instead of importing the content. Please see: http://stackoverflow.com/questions/138884/when-should-i-use-inline-vs-external-javascript
Answer: I'm using Spring MVC's ResourceHttpRequestHandler (configured with mvc:resources) to serve my static resources from /resources/* and it returns 304 on incoming requests that use the If-Modified-Since header. So when I include such a static resource with c:import and the incoming request has an  If-Modified-Since header I get the javax.servlet.jsp.JspTagException: 304 error.
I need dynamic including so @include isn't an option, and jsp:include produces an IllegalStateException when trying to include a URL handled by ResourceHttpRequestHandler. So I was left with writing my own include that reads from the file and writes it out in the JSP:
<%@ page import="org.springframework.web.context.support.ServletContextResourceLoader, org.springframework.core.io.Resource" %>
<%@ page import="org.apache.commons.io.IOUtils" %>

<%
    String path = "/resources/fileName.html";
    ServletContextResourceLoader loader = new ServletContextResourceLoader(getServletConfig().getServletContext());
    Resource resource = loader.getResource(path);
    IOUtils.copy(contentResource.getInputStream(), pageContext.getOut());
 %>

Comment: In Apache's http.conf
Comment: That would work as well, especially if removing the if-modified-since isn't an option.
Comment: BTW - how did you remove the if-modified-since header from the request?
Comment: Yes, I only left it on for one directory from where static files are served to the clients browser.
Comment: How do you actually remove it? Just curious.
Answer: Try by adding one "/" at the end url
e.g
   Yours -- <c:import url="/path/to/file.js"/>
try with -- <c:import url="/path/to/file.js/"/>


is there anyway to detect which part of hand is touching the object in interaction engine (Leap Motion & Unity3D)

Question: I am trying to build a application which includes using leap motion interaction engine to move the object in unity 3d. However, i also need to find out which fingers are touching the object when interacting with object in unity. Is there anyway i can do that? Thanks in advance!!
Comment: I guess, when you check from the editor it shows hands as L and R, it also does this for fingers from 1 to 5. If you can't get those names directly, add empty gameObjects with colliders on them as child to fingers and hands and use `OnTriggerEnter` to get the names of the fingers or hands you want
Comment: Thanks for the reply, however the interaction engine requires brush hands instead of rigid hand and i couldn't find any fingers in brush hands. Please correct me if i am wrong. Thanks!
Comment: It has been a while since I've worked with leap motion. What I recall is, I've used magnetic pinch to grab objects. Also, i was able to hold objects in my palm like grabbing a handful of water from a river, hitting them with the back of my hand. Do you have the demo scenes for Unity? There should be example scenes like `lots of cubes` was the scene name I guess. Check the hands used in that scene if you did not before. They might give you a lead. And I am not sure if I used interaction engine or not. Sorry for foggy comment.
Answer: Strictly speaking, the Grasping logic of the Interaction Engine has to check this very thing in order to initiate or release grasps, but it doesn't have a friendly API for accessing this information.
A more convenient way to express this, even though it's not the most efficient way, would be to detect when a hand is intersecting with the interaction object and checking the distance between each fingertip and the object.
All InteractionControllers that are intersecting with a given InteractionBehaviour can be accessed via its contactingControllers property; using the Query library included in Leap tools for Unity, you can convert a bunch of Interaction Controller references to a bunch of Leap Hands without too much effort, and then perform the check:
using Leap.Unity;
using Leap.Unity.Interaction;
using Leap.Unity.Query;
using UnityEngine;

public class QueryFingertips : MonoBehaviour {

  public InteractionBehaviour intObj;

  private Collider[] _collidersBuffer = new Collider[16];
  private float _fingertipRadius = 0.01f; // 1 cm

  void FixedUpdate() {
    foreach (var contactingHand in intObj.contactingControllers
                                         .Query()
                                         .Select(controller => controller.intHand)
                                         .Where(intHand => intHand != null)
                                         .Select(intHand => intHand.leapHand)) {

      foreach (var finger in contactingHand.Fingers) {
        var fingertipPosition = finger.TipPosition.ToVector3();

        // If the distance from the fingertip and the object is less
        // than the 'fingertip radius', the fingertip is touching the object.
        if (intObj.GetHoverDistance(fingertipPosition) < _fingertipRadius) {
          Debug.Log("Found collision for fingertip: " + finger.Type);
        }
      }
    }
  }

}


Tri-Tone Substitution theory and practice

Question: Can someone give me a practical explanation of the theory and practice of tri-tone substitution for jazz piano?
Answer: The basic premise of the tritone substitution is that we take a chord (typically a major-minor seventh) that has a tritone in it and substitute the entire chord with another major-minor seventh chord that has the same tritone.
Let's begin in C major and imagine a V7 chord that progresses to I. Within the V7 chord (G B D F) is the tritone B F. This is shown at letter A below.

As it turns out, this tritone exists in another major-minor seventh chord, this one on D♭: D♭ F A♭ C♭. (Note that the B F tritone is now enharmonically spelled as F C♭.) This is shown at letter B above.
So basically, wherever you use a G7 chord, you can substitute it with a D♭7 chord, because the tritone stays the same in both harmonies. Note, too, that the roots of the chords—G and D♭—are a tritone apart.
Listen to a recording here.

We can take this one step further; let's stay in C major, but let's think about a secondary dominant to V. In other words, we're looking at V7/V, or D7. In this chord (D F♯ A C), the tritone is F♯ C; see C below. The tritone substitution of this harmony (again remembering that the roots are a tritone apart) will be A♭7 (A♭ C E♭ G♭) with the enharmonically spelled tritone C G♭; this is shown at letter D.

If you've learned about the German augmented-sixth chord (A♭ C E♭ F♯ in the key of C), you see here that it's enharmonically equivalent to the tritone sub of V7/V!


Connecting to user dbus as root

Question: If we open a python interpreter normally and enter the following:
import dbus
bus = dbus.SessionBus()
bus.list_names()

We see all the services on the user's session dbus. Now suppose we wanted to do some root-only things in the same script to determine information to pass through dbus, so we run the interpreter with sudo python and run the same thing, we only see a short list of items on the root user's session dbus, and attempting to connect to anything that was on the user dbus with get_object produces a not found error accordingly.
So far I've tried inserting
import os

os.seteuid(int(os.environ['SUDO_UID']))

But this only makes SessionBus() give a org.freedesktop.DBus.Error.NoReply so this is probably nonsense. Is there a way to connect to a user's dbus service as a super user, with the python dbus bindings?
Answer: I have little knowledge about DBus, but that question got me curious.
TL;DR: Use dbus.bus.BusConnection with the socket address for the target user and seteuid for gaining access.
First question: What socket does DBus connect to for the session bus?
$ cat list_bus.py
import dbus
print(dbus.SessionBus().list_names())
$ strace -o list_bus.trace python3 list_bus.py
$ grep ^connect list_bus.trace
connect(3, {sa_family=AF_UNIX, sun_path="/run/user/1000/bus"}, 20) = 0

Maybe it relies on environment variables for this? Gotcha!
$ env|grep /run/user/1000/bus
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus

Stracing the behaviour from the root account it appears that it does not know the address to connect to. Googling for the variable name got me to the D-Bus Specification, section "Well-known Message Bus Instances".
Second question: Can we connect directly to the socket without having the D-Bus library guess the right address? The dbus-python tutorial states:

For special purposes, you might use a non-default Bus, or a connection which isn't a Bus at all, using some new API added in dbus-python 0.81.0.

Looking at the changelog, this appears to refer to these:

Bus has a superclass dbus.bus.BusConnection (a connection to a bus daemon, but without the shared-connection semantics or any deprecated API) for the benefit of those wanting to subclass bus daemon connections

Let's try this out:
$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
>>> from dbus.bus import BusConnection
>>> len(BusConnection("unix:path=/run/user/1000/bus").list_names())
145

How about root access?
# python3
>>> from dbus.bus import BusConnection
>>> len(BusConnection("unix:path=/run/user/1000/bus").list_names())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/dbus/bus.py", line 124, in __new__
    bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NoReply: Did not
  receive a reply. Possible causes include: the remote application did not send
  a reply, the message bus security policy blocked the reply, the reply timeout
  expired, or the network connection was broken.
>>> import os
>>> os.seteuid(1000)
>>> len(BusConnection("unix:path=/run/user/1000/bus").list_names())
143

So this answers the question: Use BusConnection instead of SessionBus and specify the address explicitly, combined with seteuid to gain access.
Bonus: Connect as root without seteuid
Still I'd like to know if it is possible
to access the bus directly as root user, without resorting to seteuid. After
a few search queries, I found a systemd ticket
with this remark:

dbus-daemon is the component enforcing access ... (but you can drop an xml policy file in, to make it so).

This led me to an askubuntu question discussing how to modify the site local session bus policy.
Just to play with it, I ran this in one terminal:
$ cp /usr/share/dbus-1/session.conf session.conf
$ (edit session.conf to modify the include for local customization)
$ diff /usr/share/dbus-1/session.conf session.conf
50c50
<   <include ignore_missing="yes">/etc/dbus-1/session-local.conf</include>
---
>   <include ignore_missing="yes">session-local.conf</include>
$ cat > session-local.conf
<busconfig>
  <policy context="mandatory">
    <allow user="root"/>
  </policy>
</busconfig>
$ dbus-daemon --config-file session.conf --print-address
unix:abstract=/tmp/dbus-j0r67hLIuh,guid=d100052e45d06f248242109262325b98
$ dbus-daemon --config-file session.conf --print-address
unix:abstract=/tmp/dbus-j0r67hLIuh,guid=d100052e45d06f248242109262325b98

In another terminal, I can not attach to this bus as a root user:
# python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
>>> from dbus.bus import BusConnection
>>> address = "unix:abstract=/tmp/dbus-j0r67hLIuh,guid=d100052e45d06f248242109262325b98"
>>> BusConnection(address).list_names()
dbus.Array([dbus.String('org.freedesktop.DBus'), dbus.String(':1.0')], signature=dbus.Signature('s'))

This should also enable accessing all session busses on the system, when installing session-local.conf globally:
# cp session-local.conf /etc/dbus-1/session-local.conf
# kill -HUP 1865   # reload config of my users session dbus-daemon
# python3
>>> from dbus.bus import BusConnection
>>> len(BusConnection("unix:path=/run/user/1000/bus").list_names())
143

And it works - now root can connect to any session bus without resorting to seteuid. Don't forget to
# rm /etc/dbus-1/session-local.conf

if your root user does not need this power.
Comment: Such a great answer that will be helpful for times to come, thanks especially for spending the time to explaining dbus policies \o/ I'm wondering if it'd be possible to only allow root to access all sessions, and why that's not the common case?

While this is the best answer to the original question, it would be better to avoid running python as root altogether, and just escalate the privileges where necessary.
Comment: Resolves the issue, with a heap of context too.

For the thing about defaults from teprrr, usually user dbus is application software that a root user shouldn't care about or need to send dbus signals to, so root normally doesn't get to see user dbus.
Answer: Bluehorn's answer helped me. I figured I'd share my solution. I'm only a few months into learning Python (coming from just shell scripting) so if this is really wrong and just happens to work on my system please let me know.
These are parts from a daemon I wrote to monitor CPU temps and control the fan speeds in Linux so it needs root permissions. Not sure how well it would work if ran as a regular user when multiple users are logged in. I'm guessing it wouldn't...

import os, pwd
from dbus import SessionBus, Interface
from dbus.bus import BusConnection

# Subclassing dbus.Interface because why not

class Dbus(Interface):
    def __init__(self, uid):
        method = 'org.freedesktop.Notifications'
        path = '/' + method.replace('.', '/')
        if os.getuid() == uid:
            obj = SessionBus().get_object( method, path )
        else:
            os.seteuid(uid)
            obj = BusConnection( "unix:path=/run/user/" + str(uid) + "/bus" )
            obj.get_object( method, path )

        super().__init__(obj, method)

# Did this so my notifications would work
# when running as root or non root

class DbusNotificationHandler:

    app_icon = r"/path/to/my/apps/icon.png"
    name     = "MacFanD"

    def __init__(self):
        loggedIn, users = [ os.getlogin() ], []
        for login in pwd.getpwall():
            if login.pw_name in loggedIn:
                users.append( login.pw_uid )

        self.users = []
        for i in users:
            self.users.append( Dbus(i) )

    def notification(self, msg, mtype=None):
        if not isinstance(msg, list) or len(msg) < 2:
            raise TypeError("Expecting a list of 2 for 'msg' parameter")

        hint = {}

        if mtype == 'temp':
            icon = 'dialog-warning'
            hint['urgency'] = 2
            db_id = 498237618
            timeout = 0
        elif mtype == 'warn':
            icon = 'dialog-warning'
            hint['urgency'] = 2
            db_id = 0
            timeout = 5000
        else:
            icon = self.app_icon
            hint['urgency'] = 1
            db_id = 0
            timeout = 5000

        for db in self.users:
            db.Notify( self.name, db_id, icon, msg[0], msg[1:], [], hint, timeout )

handler = DbusNotificationHandler()
notify = handler.notification

msg = [ "Daemon Started", "Daemon is now running - %s"%os.getpid() ]
notify(msg)

temp = "95 Celsius"
msg = [ "High Temp Warning", "CPU temperature has reached %s"%temp ]
notify(msg, 'warn')

Answer: You can set DBUS_SESSION_BUS_ADDRESS environment variable to choose the dbus session you want to connect to.
Incorrect permissions (i.e., missing the seteuid) causes an immediate NoReply, and not defining DBUS_SESSION_BUS_ADDRESS responded with Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead.
Here's the test code I used:
import os
import dbus

# become user
uid = os.environ["SUDO_UID"]
print(f"I'm {os.geteuid()}, becoming {uid}")
os.seteuid(int(uid))

# set the dbus address
os.environ["DBUS_SESSION_BUS_ADDRESS"] = f"unix:path=/run/user/{uid}/bus"

bus = dbus.SessionBus()
print(bus.list_names())

# I'm 0, becoming 1000
# dbus.Array([dbus.String('org.freedesktop.DBus'), dbus.String('org.fr .. <snip>

Connecting to user dbus as root


Android Webview cant focus on its elements

Question: I have a android TV app and so all my controls are using the focus(remote).
I have a webview which loads up the url and displays the content.
Now this page has a section in the centre and there are 2 buttons inside this section.
Now the focus is on the section itself and it doesnt go inside and focus on the buttons.
If I click on up and down buttons on the remote, the page just scrolls up and down but the focus doesnt move inside to the buttons.
Any idea how I can solve this?
Thanks.
Comment: @Gaurav Did you found any solution?
Comment: http://stackoverflow.com/a/4075955/1318946
Comment: The webpage is from a third party so cant do anything on it. @PratikButani
Comment: The webpage is yours, but webview is not. So I wondering if calling `webView.requestFocus(View.FOCUS_DOWN);` will be of any help. As it will call focus to your webview only.
Comment: I tried that. It doesnt help. And webview mine. Webpage is not.
Comment: you want to setup focus on navigation buttons?
Comment: @ssh There are 2 buttons which are inside a section in the webview. the focus comes on the entire section but doesnt go a level deeper on the buttons
Answer: Hi you can try something like this
<code>mWebview.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (view.hasFocus() == false) {
                    view.requestFocus();
                }
                break;
         }
         return false;
    }
});
</code>
Comment: This gives focus to the whole section and not the buttons which I want
Answer: I think you need a wrapper on your webview, which holds navigation above on webview.
After that disable all user-actions to this webview.(touch,focus,etc..)
Setup buttons and redirect user actions to webview.
For ex.
UP button click -> redirect to scroll webview.


Setting MPMoviePlayerController orientation without MPMoviePlayerViewController

Question: It seems the best (only?) way to rotate an MPMoviePlayerController to landscape is to use an MPMoviePlayerViewController .
I'm currently modifying an open source game which, unfortunately, does not have a root UIViewController set. Is there any way to set the orientation only with MPMoviePlayerController, or do I have to suck it up and hack a root UIViewController into this application?
Edit: in response to Shivan Raptor, the game is Canabalt: https://github.com/ericjohnson/canabalt-ios. I'm instantiating an MPMoviePlayerController as follows:
<code>self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:self.videoTempFilePath];
self.moviePlayerController.repeatMode = MPMovieRepeatModeNone;

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlaybackComplete:)
                                             name:MPMoviePlayerDidExitFullscreenNotification
                                           object:self.moviePlayerController];
[glView addSubview:self.moviePlayerController.view];

// MUST SET THIS HERE AFTER WE ADD AS SUBVIEW
self.moviePlayerController.fullscreen = YES;

[self.moviePlayerController play];
</code>
The movie plays in portrait and stays locked there, but I'd like to play it in landscape.
Comment: Can you post related codes here ?
Answer: I created a root UIViewController and made the MPMoviePlayerViewController a child of it. This created the desired effect.
Answer: I think this might helpful.
<code>- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
    return true;
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
    [self.view setTransform:CGAffineTransformMakeRotation(M_PI * 2)];
    return true;
}
else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) {
    [self.view setTransform:CGAffineTransformIdentity];
    return true;
}
else return false;
}
</code>


Can't get mahout itemsimilarity result with preferences (booleanValue=false)

Question: I'm trying to create get itemismilarity using mahout. The problem is that I do get few similarities in output.
Here are my input data characteristics:

15.910.847 total count of preferences
4.047.745 distinct users
773.015 distinct items
I've built the distribution of users and prefereces

The first column is count of distinct users
The second column is count of preferences per users. I do have 2.221.760 uses which have only one preference, for example.

2221760   1
688258    2
322497    3
192003    4
122446    5
87033 6
63733 7
49556 8
39090 9
31637 10
25634 11

Here are my input settings:
similarityClassname=SIMILARITY_PEARSON_CORRELATION
maxSimilaritiesPerItem=100000
minPrefsPerUser=0

booleanData=false
threshold=0.75

Answer: Column 1 should be Mahout user ID, from 0 thru number of users - 1
Column 2 should be Mahout item ID, from 0 to number of items - 1 You can't just count preferences you want to record each item that the user showed some preference for
Column 3 is the strength of preference, like a rating
IDs are like row and column numbers in a matrix or table 0,0 is user 0 item 0, the value is the rating.
You must translate your IDs into Mahout IDs then back again into your ids when reading the results of itemsimilarity.
Comment: Hi :) I got your response in mahout user group. I'm using org.apache.mahout.cf.taste.hadoop.similarity.item.ItemSimilarityJob and I can't find requirement for mapping numerical user and item ids to range [0..qtty_of_users], [0..qtty_of_items] before feeding preference data to mahout.... The same for org.apache.mahout.cf.taste.hadoop.item.RecommenderJob where I can get itemSimilarityMatrix
Comment: And yet it is true.  I'll write up a wiki page describing this. We just rewrote the Wiki for 0.9 release and is was missed.
Comment: Great, going to try and report.
Comment: didn't help. I've used apache pig Rank function to give 1..N id for each distinct user_id and 1..M for each distinct item_id. I did feed ItemSimilarityJob with dataset, where user_id in [1..N], item_id [1..M], preference: 1.0 or 2.0, output result is pretty the same 16*10^6 preferences from 4*10^6 users for 7*10^5 items give only 10^3 similarities for 10 items... What do I do wrong? Does input dataset should be ordered by item/users id?
Answer:
didn't help. I've used apache pig Rank function to give 1..N id for each distinct user_id and 1..M for each distinct item_id. I did feed ItemSimilarityJob with dataset, where user_id in [1..N], item_id [1..M], preference: 1.0 or 2.0, output result is pretty the same 16*10^6 preferences from 4*10^6 users for 7*10^5 items give only 10^3 similarities for 10 items... What do I do wrong? Does input dataset should be ordered by item/users id? –  Sergey Jul 27 at 20:46

It is because Mahout taste implementations accept ints as input for user_ids. If you supply anything that overflows MAX.int value, it will rollover to a minimum, which means it wont get added as a unique user.
You could perhaps Hash your user_id if it exceeds MAX.int value before you feed it to Mahout. Or you could have a alpha-numeric id and then user the ID-Migrator class for user_id input.
Answer:
I should use COSINE_SIMILARTY instead of SIMILARITY_PEARSON_CORRELATION because I use discrete preference

Don't use threshold, It works not like with param booleanData=true
I'm not sure that I have to "remap" my natural user, item ids to to surrogate [0...N].

Problem looks like solved. Thank you guys!


Significance of eigenvalue

Question: When I represent a graph with a matrix and calculate its eigenvalues what does it signify?  I mean, what will spectral analysis of a graph tell me?
Answer: Here are some things you can learn from eigenvalues.
If there are $d$ distinct eigenvalues, then the diameter of the graph is at least $d+1$.
If a graph is $k$-regular, then the multiplicity of $k$ as an eigenvalue gives you the number of connected components in the graph.  In general, if a graph is connected, then the largest eigenvalue must have multiplicity 1.
For strongly regular graphs, you can use information about the eigenvalues and their multiplicities to determine if certain parameter values are even possible.  That is, if we have a strongly regular graph with parameters (n, k, a, c), then there exists one eigenvalue of multiplicity 1 and two other eigenvalues, $\theta$ and $\tau$.  These eigenvalues have multiplicities:
$m_\theta = \frac{1}{2} \left( (n-1) - \frac{2k+(n-1)(a-c)}{\sqrt{\Delta}}\right)$
and
$m_\tau = \frac{1}{2} \left( (n-1) + \frac{2k+(n-1)(a-c)}{\sqrt{\Delta}}\right)$
where $\Delta = (a - c)^2 + 4(k - c)$.  Since these represent eigenvalue multiplicities, they must be integers.  Therefore, any parameter values (n, k, a, c) which do not give integer values for these multiplicities, are not possible.
See Algebraic Graph Theory by Godsil and Royle, chapter 10, for more on this.
If you are interested in learning about the connection between eigenvalues and graphs, then read a book.  You already know the term spectral analysis.  Read Spectra of Graphs, for instance:
http://homepages.cwi.nl/~aeb/math/ipm/ipm.pdf
P14 of this book gives the first result I gave, plus the proof.
Comment: The first eigenvalue also bounds the Cheeger constant of the graph, which gives you information about whether it has any bottlenecks.
Comment: But how can you connect notion of eigen values and graph theory?i'm not getting this point
Comment: @user997704 The diameter is a notion of graph theory.  I explained one connection between graphs and their eigenvalues, which involves the diameter.  I'm not sure what you mean?  I'm not saying my answer gives you a complete picture.  I'm giving you a bit of information.
Comment: I got wht u r saying but is there any proof for this statement?How did u come to this statement?Please post some mathematical proof
Comment: @user997704 See Algebraic Graph Theory by Biggs.  It has the proof in it.
Comment: Your link doesn't work. At least not for me. Can you fix it please?
Comment: @draks It's fixed.
Answer: The dominant (largest) eigenvalue can be used to tell you which node(s) are the most connected. Since the matrix is symmetric, it is diagonalizable (in fact, orthogonally diagonalizable, but diagonalizable is enough for what follows).
So all $n$-vectors can be written as a linear combination of eigenvectors. Say $$\vec{x}=\sum_{i=1}^nc_i\vec{v}_i$$ where $\vec{v}_i$ is an eigenvector for $\lambda_i$ and $\lambda_1$ is the dominant eigenvalue.
In particular, apply this to the columns of the matrix $\vec{a_j}$:
$$\vec{a_j}=\sum_{i=1}^nc_{ij}\vec{v}_i$$
I assume you understand that $A^n$ shows you how many paths there are of length $n$ from each vertex $i$ to each vertex $j$. But $$A^n=A^{n-1}A=\begin{bmatrix}A^{n-1}\vec{a}_j\end{bmatrix}=\begin{bmatrix}\sum_{i=1}^nc_{ij}\lambda_i^{n-1}\vec{v}_i\end{bmatrix}$$ For large $n$, $\lambda_1^{n-1}$ is relatively much larger than all other such terms. So $$A^n\approx\begin{bmatrix}c_{1j}\lambda_1^{n-1}\vec{v}_1\end{bmatrix}$$ where the $\approx$ comparison is made entry by entry and compares entires by looking for ratios close to $1$. (I'm being informal, for ease of reading).
Thus the columns of $A^n$ are proportional to $\vec{v}_1$, so for each column of $A^n$, the entries of $\vec{v}_1$ tell you which entries are largest, which in turn tells you which nodes have the most paths of length $n$ to each of the other nodes. As $n$ gets larger, this feature of $A^n$'s columns won't change. So in a nice sense, you will understand which nodes are the most connected to other nodes through paths of long-enough lengths.
Comment: Seems reasonable.Can I get more material regarding spectra of graphs apart from http://homepages.cwi.nl/~aeb/math/ipm.pdf ,this seems good book but i'm looking for quick material....
Comment: @user997704  Read chapter 1.  That's not that complicated and that would be quick and you'd learn a lot.
Answer: The ratio between the largest and
smallest eigenvalue can be used to estimate the chromatic number:
$$
\chi(G)\ge1+\frac{\lambda_{\min}}{\lambda_\max}.
$$
A proof can be found here (Theorem 2.4).

Significance of eigenvalue


Output buffering - Echo values dynamically?

Question: I want to echo string dynamically, not all of them at once when script finished running. Tried this one, but it echos all of them when script finished running. How can I echo values dynamically ?
<?php
ob_start();

echo "Line #1...
";
ob_flush();
flush();
sleep(2);

echo "Line #2...
";
ob_flush();
flush();
sleep(2);

echo "Line #4...
";

?>

Comment: are you sure that it isn't your browser buffering before display?
Comment: As pointed by Jon Taylor, the browser is doing its own buffering. So I don't think it is achievable using only PHP.
Comment: Tip: you also might want to change the [execution time](http://www.php.net/manual/en/function.set-time-limit.php) of your script if it'll take longer then 30seconds
Comment: Some browsers would like to render the page after the full document has loaded. Especially for XHTML
Answer: Try sending a line-ending like \n or append at least 256 spaces to each echo to trigger the browser.
Some browsers will wait for at least 256bytes before rendering, others need a newline char. Try this combination before each flush:
echo str_repeat(" ", 256) . "\n";

Other cause could be the webserver that is caching the response.
Comment: isn't it 512 for html5 now? Or am I confusing this with something else?
Comment: I think it more depends on browser implementation then on the html version.
Comment: It works only if I use
echo str_repeat("sent", 256) . "\n";
And it echos "sent" 256 times dramatically. How to fix that ?
Comment: Increase the number of spaces. Use 1024 instead of 256


Replace OAuthUri with OAuthAuthenticator

Question: I have the folowing:
Uri retUri = null;

if (this.settings.OAuthUser != null &&
    location.IndexOf(OAuthUri.OAuthParameter) != 0)
{
    //
    // How to replace in the following line
    // the OAuthUri with OAuthAuthenticator ?
    //
    retUri = new OAuthUri(location, this.settings.OAuthUser,
                          this.settings.OAuthDomain);
}
else
{
    retUri = new Uri(location);
}

The warning says :

Warning   196 'Google.GData.Client.OAuthUri' is obsolete: 'this is going
  to be removed in the future and replaced with OAuthAuthenticator'
Answer: I think you are using an older version of the Google client lib
PM> Install-Package Google.Apis

The Oauth code will look something like this
UserCredential credential;
 credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
              new ClientSecrets { ClientId = "YourClientId", ClientSecret = "YourClientSecret" },
              new[] { DriveService.Scope.Drive,
                DriveService.Scope.DriveFile },
              "user",
              CancellationToken.None,
              new FileDataStore("Drive.Auth.Store")).Result; }

Scopes will change depending upon which API you are trying to connect to.  Also FileDatastore stores the refresh token in %AppData%, if you want to store it someplace else you will need to make your own implementation of Idatastore.
There is a short tutorial on it here Google Oauth2 C#


Azure Devops image in readme from relative path

Question: I'm trying to add an image to my readme but I can't get it to render.
As far as I can see online my current setup should work.
My folder structure is like so:

And then I tried to use the image located in the resources directory, but that did not work:
![Architecture view for AllProjects.png](./Resources/Architecture-view-for-AllProjects.png)

Any suggestions?
Answer: This seems to work well for me: Replace the space with   or %20.
![Architecture view for AllProjects.png](./Resources/Architecture%20view%20for%20AllProjects.png)

![Architecture view for AllProjects.png](./Resources/Architecture view for AllProjects.png)

Result:
Answer: Your file is Architecture view for AllProjects.png so if you add - all should be fine.
Please check out here - Spaces in path to image file.
I tried encoding it with %20 but link was still broken. So your only/best way is to add - to the name.
Comment: Hi, thanks for taking the time to look  over my question. the answer of Vito Lui worked, either ` ` or `%20` displayed the image correctly for me. I'd thought replacing spaces with `-` would do the trick since a couple lines above this image i have a link to a wiki document that includes spaces, and the relative link there works. Something like: `[my wiki link](/my-wiki-link)`.So it works for wiki page links, but not for images inside a git repo for some reason, but such are the mysteries of life.


Como instalar o rvm no Debian squeeze

Question: Estou tentando instalar o rvm mas não estou conseguindo. Na hora de fazer a verificação das dependências ele reclama do pacote libgmp-dev que não está instalado e ao tentar instalar ele não é localizado.
Pelo que andei pesquisando e parece que realmente não existe esse pacote para o squeeze ou o pacote está com outro nome...
Answer: Rafael, não possuo o debian para efetuar testes.
No momento com o Mint instalado qualquer teste feito não seria válido.
Portanto sugiro que tente instalar uma versão compatível com a última distribuição do debian contida nesta página:
https://packages.debian.org/search?keywords=libgmp-dev
Espero ter ajudado.
Answer: Tente executar os seguinte passos:
Instale alguns pre-requisitos do Debian
apt-get -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion locales-all python libxml2=2.7.8.dfsg-2+squeeze6

Agora tente instalar o RVM normalmente
curl -L https://get.rvm.io | bash -s stable

Answer: Instala o rbenv que é muito melhor que o RVM. Com o git instalado execute esse comando no terminal.
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv

O ruby-build, que simplifica o modo como o Ruby é instalado.
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Adiciona o rbenv ao $PATH. Para isso execute o comando à seguir:
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc

Adicionar o script de inicialização ao seu arquivo de inicialização do terminal. Execute o comando.
echo 'eval "$(rbenv init -)"' >> ~/.bashrc

Reinicie o seu terminal para carregar estas novas configurações, ou execute o comando source ~/.bashrc.
Se tudo deu certo. Agora você pode instalar o ruby. Para saber quais versões estão disponíveis, execute o comando rbenv install -l.
$ rbenv install -l
Available versions:
  1.8.6-p383
  1.8.6-p420
  1.8.7-p249
  1.8.7-p302
  1.8.7-p334
  ...

Para instalar a última versão disponível neste momento, exeute o comando rbenv install 2.3.1. Este processo irá demorar um pouco, já que o rbenv irá compilar o Ruby.
Quando a instalação acabar, execute o comando rbenv global 2.3.1 para definir a versão global do Ruby/
Para exibir a versão do Ruby, execute o comando ruby -v.
Opinião próprio sobre o  rbenv ser superior ao RMV e a possiblidade de instalar plugins para facilitar sua vida.Um deles é o rbenv-gem-rehash, que faz rehashing automaticamente sempre que uma gem for instalada ou removida.
"Rehashing é o processo de atualizar o $PATH com os binários das gems. O comando rbenv init faz isso para você, mas ele é apenas executado quando uma nova sessão do terminal é iniciada; assim, qualquer gem instalada após esta etapa pode não funcionar corretamente, a menos que você execute manualmente o comando rbenv rehash."
Execute o comando à seguir para instalar o plugin:
$ git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash

fonte: Blog Nando Vieira

Como instalar o rvm no Debian squeeze