Friday, 27 September 2013

Q: AudioSteamer sometimes doesn't change to AS_PLAYING state

Q: AudioSteamer sometimes doesn't change to AS_PLAYING state

My Music app need to show real-time when the music is playing.I get the
time value from audioStreamer's progress.But if audioStreamer doesn't
change to AS_PLAYING state, the progress value is always 0.0. OK,if I play
next song by allocating a new audioStreamer with a new Song URL,it may be
work correctly. I am confused about this situation. So,I need help.Thanks!

How to append straight markup to HEAD without jQuery?

How to append straight markup to HEAD without jQuery?

I have a string containing HTML for stylesheets (created via the Rails
asset pipeline), and I need to append this to the head and have the
stylesheets actually load, in all major browsers. The string looks like
this:
<link
href="https://www.v.me/assets/core-28020ec7a202f8bc47a5d70d5aeb8477.css"
media="screen" rel="stylesheet" type="text/css" />
<link
href="https://www.v.me/assets/widgets-d4c93376a05ffe6d726371b89bc58731.css"
media="screen" rel="stylesheet" type="text/css" />
<link
href="https://www.v.me/assets/flowplayer-minimalist-3254ab41f4865c79282728f0012bb98d.css"
media="screen" rel="stylesheet" type="text/css" />
<link
href="https://www.v.me/assets/main-12765c4980ba6d109852c52830b34586.css"
media="screen" rel="stylesheet" type="text/css" />
I need to do this without using jQuery. Is this possible?
I wish I had the URLs in an array, but I don't. As a last resort, I could
consider using a regex to parse out the URLs, but I'd like to avoid this.

Hash map iteration

Hash map iteration

How do I iterate through a hash map to find the first 10 elements for eg
if my map contains string as key and int as value, I want to fetch the
first 10 values with highest integer?

Connect to MongoDB/mongoHQ with HotTowel localy in visual studio

Connect to MongoDB/mongoHQ with HotTowel localy in visual studio

i am trying wthout success to post a json file in MongoDB/mongoHQ using
ajax but all i recieve is :
XMLHttpRequest cannot load
https://api.mongohq.com/databases/myFirsttry/collections/customers/documents?_apikey=bblctgd9pffzwhrrq5oo.
Origin http://localhost:56936 is not allowed by
Access-Control-Allow-Origin. localhost:56936/:1
error
first i was thinking it s due tu same origin policy but after a time i
find out that it was not the problem since i can run Get
can anyone help me solving this ?

octave-optim: minimize function applied to only partial list of parameters

octave-optim: minimize function applied to only partial list of parameters

I'm trying to minimize a scalar function of two variables, but I only want
to minimize with respect to the first argument:
function val = f( x, y )
val = (y*x-1.2345)^2;
endfunction
I'd like to pass the value y=2.345 and minimize on x only.
[ xret, fval ] = minimize( @f, ['x'], ??? )
How do I pass y to the f() function, without minimizing on y also?

Insert selected text file after existing text in PowerPoint

Insert selected text file after existing text in PowerPoint

I have created a macro in PowerPoint that does the following: User clicks
text frame on the slide. It names the frame and opens a dialog for them to
choose from a list of text documents. They choose one and the text is read
and inserted into the named text frame.
Here's the insert part of the code:
Dim file As Object
Dim Text As String
Set file =
CreateObject("Scripting.FileSystemObject").OpenTextFile(vrtSelectedItem,
1)
Text = file.ReadAll
oShape.TextFrame.TextRange.Text = Text 'Insert the text into the text frame
The problem I have is that it clears any existing text in the frame,
instead of adding to it. I really need to add the newly selected text
after any existing content in the frame. For instance, if they are adding
in a selection of quotes, they need to add one after the other.
Can anyone advise on ways of doing this?

Thursday, 26 September 2013

Many links with same jquery animation, how to organize them better?

Many links with same jquery animation, how to organize them better?

I have an question about jQuery - I'm working on big system's menu
simulation, so others can play with that and decide, how it should be
better organized - usability and user experience stuff.
Menu is multilevel and every part must be draggable - so it's important (I
guess) to stay all parts in same page. But this not what I want to ask
actually. I have submenu's menu, so it opens using slideToggle() class by
clicking on the menu link.
<script>
$( "#terms" ).click(function() {
$( "#1" ).slideToggle( "slow" );
});
$( "#tc" ).click(function() {
$( "#tc-2" ).slideToggle( "slow" );
});
</script>
I have a lot of that kind of links, so I don't want to write code for
every link, I want to create something like
<script>
$( "a" ).click(function() {
$( "#href" ).slideToggle( "slow" );
});
</script>
So by clicking on the link it opens only this div, which have same id, as
link href.
Sorry for lame question, I really don't know how to explain google what I
want.

Thursday, 19 September 2013

SVN: Revision Numbers on a Branch

SVN: Revision Numbers on a Branch

There are a couple of points about SVN revision numbering on a branch
which are not clear to me:
When I create a branch, does the branch get its own revision number?
How does SVN does handle the revision numbering on the branch? Does branch
have its own sequence of revision numbers separate from the Trunk and
other branches? Or there is only one single sequence numbering for the
whole SVN server? To clarify, please explain what happens when a commit is
done on a branch.

Using while loop as input validation

Using while loop as input validation

I'm trying to use while loop to ask the user to reenter if the input is
not an integer
for eg. input being any float or string
int input;
Scanner scan = new Scanner (System.in);
System.out.print ("Enter the number of miles: ");
input = scan.nextInt();
while (input == int) // This is where the problem is
{
System.out.print("Invalid input. Please reenter: ");
input = scan.nextInt();
}
I can't think of a way to do this. I've just been introduced to java

Search for an existing item in database and fill out a webform

Search for an existing item in database and fill out a webform

For my work we fill in the names for engineers who are working for us that
day. Every time we write the name, phonenumber, company and other data.
I made an App where I can fill in all the required data, but I want to
(auto) fill or choose the existing engineers, phonenumber, company in the
form fields, which worked for us before.
Can you please help me in the right direction?

trigger upgrade from sql server 2005 to sql server 2012

trigger upgrade from sql server 2005 to sql server 2012

I have a serious problem. I have about 200 sql server 2005 databases and
every database has at least 30-40 tables, each with about 10 triggers.
Now the problem is that we have upgraded from sql server 2005 to 2012 and
the triggers are syntactically incorrect now.
How do I change the syntax for so many triggers? Or better still, how do I
make them work in sql server 2012?
Any help would be highly appreciated!! Thanks in advance!
Please help.

Best way to pass css class attribute to grails fields plugin custom template

Best way to pass css class attribute to grails fields plugin custom template

Working with the Grails Fields plugin, I have some custom templates for
which I'd like to pass in an attribute named class (for CSS styling).
e.g. Here's what I want to do:
<f:field property="someProperty" class="someCustomCssClass" />
The problem is I can't simply look for the "class" property in the custom
template, as that's a reserved word. I'd rather not use a different
attribute name like "cssClass", because then I can't easily swap between
default fields template usage and custom fields template usage.
The only thing I can think of so far is to parse the "widget" property and
grab the class out of that String, but is there a better way to grab the
value of the class attribute in a custom fields template?

MS Access enter parameter value

MS Access enter parameter value

I have a form and in the form is a sub form that displays rows from a
query. One of the columns in the subform is the DNANumber. The report
works 100%. Problem is, when I call the report using the following code,
strWhereClause = "[DNANumber]=" & strText
DoCmd.OpenReport "Certificate", acViewPreview, , strWhereClause, , acHidden
I get a popup message asking for the parameter value, also displaying that
exact value it is looking for above the textfield. I have checked all the
spelling in the queries, forms , subforms and tables and controlls.
Everything is fine. Why do I get this popup message. Further, If I type in
the value, it displays the report without a problem.
TIA

Handling 3 finger tap in Android

Handling 3 finger tap in Android

I am using OnTouchListener to capture multitouch events for ex. a 3 finger
tap , I could able to detect up to 2 fingers. i.e event.getPointerCount()
returns upto 2. Even same with onTouchEvent(). Is there any other API for
handling this ? I have enabled 3 finger tap detection on my test device.
This is what I have done so far:
package com.example.toucheventsample;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.VideoView;
public class TouchEventActivity extends Activity implements OnTouchListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.video);
videoView.setOnTouchListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.touch_event, menu);
return true;
}
public boolean handleTouchEvent(MotionEvent event) {
boolean handled = true;
int action = event.getAction();
int count = event.getPointerCount();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_UP:
if (3 == count) {
// handle 3 finger tap
}
break;
}
return handled;
}
@Override
public boolean onTouch(View view, MotionEvent event) {
int count = event.getPointerCount();
handleTouchEvent(event);
return true;
}
}

Not null column to shift left in mysql

Not null column to shift left in mysql

I am working on MySQL database. I have a table empreporting, this table
contains employeeid and reportingemployeeid columns
SELECT e3.`ReportingEmployeeId` AS Level0,e2.`ReportingEmployeeId` AS
Level1,e1.`ReportingEmployeeId` AS Level2,e1.`EmployeeId` AS Level3
FROM empreporting e1
LEFT JOIN empreporting e2 ON e1.`ReportingEmployeeId` = e2.`EmployeeId`
LEFT JOIN empreporting e3 ON e2.`ReportingEmployeeId` = e3.`EmployeeId`
the above query giving below result:
Level0 Level1 Level2 Level3
\N \N 379 369
\N 379 484 372
\N \N \N 379
Required result format is :
Level0 Level1 Level2 Level3
379 369 \N \N
379 484 372 \N
379 \N \N \N
Pls any one help me. Thanks in advance
Prakash

Wednesday, 18 September 2013

Compare Two Character Arrays in C

Compare Two Character Arrays in C

I have a string struct.
struct string
{
char *c;
int length;
int maxLength;
}
I want to check if two strings are equal.
So I want to run a for loop.
for(int i = 0; i < length; i++)
if(s1[i] != s2[i]) // This code is more C# than C.
s1 and s2 are both string structs.
How do I do this if(s1[i] != s2[i]) ?
EDIT: I just did this, is it over kill?
for(i = 0; i < length; i++)
if((*s1).c[i] != (*s2).c[i])
{
printf("Failed");
return 0;
}

Including Capital & Non Capital Letters in Regex

Including Capital & Non Capital Letters in Regex

I'm attempting to create an SQL filtering system which notifies the user
when the request contains any of the included words.
Currently my regex only supports all caps & I was wondering whether it
would be possible to have it also accept non-caps as-well as other
combinations of letters for example SElEcT
I understand entering this manually would be possible, however, this is
not the most productive way to perform such a task.
This is my current code:
function checkString($string)
{
if(preg_match('[SELECT|FROM|DATABASE|TABLE|DROP|ALTER|LIKE|IN|BETWEEN|UNION|NULL|CHECK|JOIN|AVG|SUM|COUNT|FIRST|LAST|MAX|MIN|GROUP]',
$string
Thanks.

Is it possible that setting -Xmx to high on a 32 JVM can shrink the space available to JNI such that JNI fails?

Is it possible that setting -Xmx to high on a 32 JVM can shrink the space
available to JNI such that JNI fails?

I have a problem where allocating to much -Xmx causes a problem of the
most unusual kind.
The Problem: Setting -Xmx to 3072m on a 32bit JVM on a 64bit Linux OS
works except for one condition where a servlet attempts to communicate
with many outside entities via JNI IPC. When we lower the -Xmx to 2048m it
works. No errors within tomcat are ever seen. The only errors that are
seen are within the JNI logging code.
This leads me to believe that since this is a 32bit process, setting the
max java heap space to 3072m leaves to little space for the JNI C++ native
code. It cannot allocate enough space for.. threads, or whatever.
I've investigated: Maximum Java heap size of a 32-bit JVM on a 64-bit OS
and this isn't what I'm asking.
The Question:
Is it possible that setting -Xmx to high on a 32 JVM can shrink the space
available to JNI such that it fails? How might we determine for a given
situation what is available to that JNI process?
The list of Knowns:
Linux 64bit HCOS-130:~ # uname -a Linux HCOS-130 2.6.27.19-5-default #1
SMP 2009-02-28 04:40:21 +0100 x86_64 x86_64 x86_64 GNU/Linux
java 6 32bit jre1.6.0_45
CATALINA_OPTS="-server -Xmx3072m -XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=$CATALINA_HOME/logs"
ps aux | grep -i jsvc
root 19827 0.0 0.0 2344 368 ? Ss 17:32 0:00 jsvc.exec
-user tomcat -home /usr/java/jre1.6.0_45
-Dcatalina.home=/usr/java/apache-tomcat
-Djava.security.auth.login.config=/usr/java/apache-tomcat/conf/jaas.conf
-Djavax.net.ssl.trustStore=/usr/java/apache-tomcat/conf/truststore.ks
-Djavax.net.ssl.trustStorePassword=changeit -Djava.awt.headless=true
-Djava.io.tmpdir=/usr/java/apache-tomcat/temp
-Djavax.net.ssl.trustStore=/usr/java/apache-tomcat/conf/truststore.ks
-Djavax.net.ssl.trustStorePassword=changeit -outfile
/usr/java/apache-tomcat/logs/catalina.out -errfile
/usr/java/apache-tomcat/logs/catalina.err -server -Xmx3072m
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/usr/java/apache-tomcat/logs -cp
/usr/java/apache-tomcat/conf:/usr/java/apache-tomcat/bin/bootstrap.jar:/usr/java/apache-tomcat/bin/commons-daemon.jar:/usr/java/apache-tomcat/bin/tomcat-juli.jar:/usr/java/apache-tomcat/shared/lib/jni.jar:/usr/java/apache-tomcat/shared/lib/log4j-1.2.14.jar:/usr/java/apache-tomcat/shared/lib/dhcajni.jar:/usr/java/apache-tomcat/shared/lib/activejni.jar
org.apache.catalina.startup.Bootstrap
tomcat 19829 1.5 0.1 2863864 162164 ? Sl 17:32 0:10 jsvc.exec
-user tomcat -home /usr/java/jre1.6.0_45
-Dcatalina.home=/usr/java/apache-tomcat
-Djava.security.auth.login.config=/usr/java/apache-tomcat/conf/jaas.conf
-Djavax.net.ssl.trustStore=/usr/java/apache-tomcat/conf/truststore.ks
-Djavax.net.ssl.trustStorePassword=changeit -Djava.awt.headless=true
-Djava.io.tmpdir=/usr/java/apache-tomcat/temp
-Djavax.net.ssl.trustStore=/usr/java/apache-tomcat/conf/truststore.ks
-Djavax.net.ssl.trustStorePassword=changeit -outfile
/usr/java/apache-tomcat/logs/catalina.out -errfile
/usr/java/apache-tomcat/logs/catalina.err -server -Xmx3072m
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/usr/java/apache-tomcat/logs -cp
/usr/java/apache-tomcat/conf:/usr/java/apache-tomcat/bin/bootstrap.jar:/usr/java/apache-tomcat/bin/commons-daemon.jar:/usr/java/apache-tomcat/bin/tomcat-juli.jar:/usr/java/apache-tomcat/shared/lib/jni.jar:/usr/java/apache-tomcat/shared/lib/log4j-1.2.14.jar:/usr/java/apache-tomcat/shared/lib/dhcajni.jar:/usr/java/apache-tomcat/shared/lib/activejni.jar
org.apache.catalina.startup.Bootstrap

Getting error "Arithmetic exception" on debugging

Getting error "Arithmetic exception" on debugging

While answeing this question I tried to run this code (for generating
random numbers in a given range);
#include<stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int max_range, i = 0, rand_num;
bool digit_seen[max_range + 1]; // VLAs For C99 only
srand((unsigned)time(NULL));
printf("Enter your maximum of range: ");
scanf("%d", &max_range);
for (int i = 1; i <= max_range; i++)
digit_seen[i] = false;
for (;;)
{
rand_num = rand() % max_range + 1;
if(rand_num !=3)
if(!digit_seen[rand_num])
{
printf("%d ", rand_num);
digit_seen[rand_num] = true;
i++;
}
if( i == (max_range - 1) )
exit(0);
}
return 0;
}
It worked fine upto a max_range of 47 but after that I got this error on
debugging

Any idea why I am getting this?

Ruby gsub regex doesn't match end of string

Ruby gsub regex doesn't match end of string

I'm trying to add <p> tags to user-generated text in place of line breaks.
Here is my code:
def prep_ug_text string, tags=[]
tags = tags.empty? ? ['p'] : tags
sanitize string.gsub(/(.*)[\n\r\Z$]+/, "<p>\\1</p>"), tags: tags
end
The replacement works exactly as expected for the first paragraph, but it
only wraps the final block of text if I add an extra carriage return. It
seems like the \Z and $ are not matching as I expect them to.
What am I doing wrong?
Examples:
This...
Lorem ipsum dolor sit amet.
Vestibulum laoreet erat id quam.
...turns into this
<p>Lorem ipsum dolor sit amet.</p>
Vestibulum laoreet erat id quam.