Monday, April 30, 2012

php get file extention

I wish to get an extension of an image I am uploading but I just get an array back. Is there a way to just get the extension itself



     $userfile_name = $_FILES['image']['name'];
$userfile_extn = explode(".", strtolower($_FILES['image']['name']));




Venn Diagram Drawing Algorithms

Someone was asked about overlapping subclusters in GraphViz and got the following response:




Sorry, no. General subgraphs can share nodes without implying subset
containment but not clusters. The problem is in the drawing.
If clusters can overlap arbitrarily, drawing them becomes the problem
of drawing Venn diagrams, for which there are no good algorithms.




What is a formal definition or example of the "problem of drawing Venn diagrams"?, and why is it (I assume NP-complete/hard) hard ? (Extra points: Sketch a reduction to a well-known NP-complete problem)





ICU's MessageFormat on iOS

It is my understanding that iOS uses ICU under the hood. I'd like to access the functionality of ICU's MessageFormat for strings involving numbers and plurals, for example,



There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.


Does iOS expose this capability? If so how do I use it? I thought I might be able to write



[NSString stringWithFormat: "There {0,choice,0#are no files|1#is one file|1<are {0,number,integer} files}.", n];


or



[NSString stringWithFormat: "There {0,plural, =0{are no files}=1{is one file}other{are %ld files}}.", n];


But these formats (ICU4J and ICU, respectively) do not work.





Select statement for xdoc query

I am trying to add a sub category to Messages in my xml statement Is there a way I can do this GroupMessages -> Message -> GroupMessage :



        var groups = xDoc.Descendants("Group")
.Select(n => new
{
GroupName = n.Element("GroupName").Value,
GroupHeader = n.Element("GroupHeader").Value,
TimeCreated = DateTime.Parse(n.Element("TimeAdded").Value),
Tags = n.Element("Tags").Value,
Messages = n.Element("GroupMessages").Value
//line above
})
.ToList();


In my method GroupMessages contains both MessageID and GroupMessage and it is listing both in my datagrid within the one container. So I tryed this but it lists nothing:



 Messages = n.Descendants("GroupMessages").Select(nd => nd.Element("GroupMessage").Value)


My xml looks like this:



<Group>
<TimeAdded>2012-04-27T10:23:50.7153613+01:00</TimeAdded>
<GroupName>Group</GroupName>
<GroupHeader>Header</GroupHeader>
<GroupMessages>
<Message>
<MessageID>1</MessageID>
<GroupMessage>Message</GroupMessage>
<MessageGroup/>
</Message>
</GroupMessages>
</Group>


I have also tryed:



Messages = n.Descendants("GroupMessages").Select(nd => nd.Descendants("Message").Select(nde => nde.Element("GroupMessage").Value))


To no avail?





Ideal Skip list ? O(n) run-time?

I'm trying to find the best algorithm for



converting an "ordinary" linked list 
into an `ideal skip list`


.



Where the definition of an ideal skip list is that in the first level we'll have all
the elements , in the level above - half of them , the one after - quarter of them ... and so on .



I'm thinking about O(n) run-time where involving throwing a coin for each node in
the original linked-list , whether or not for a specific node , should I go up or not , and create another duplicate node for the current node upstairs ...
Eventually this algorithm would produce O(n) , is there any better algorithm ?



Regards





how to control a combo box by using another combo box swing

I have two combo box the items first one is (women and men).I want when user select women in first combo box the list of women's dress will appear in second combo box and when men is selected the list of men's dress will appear in second one.Can do this functionality by using JCombo box? if yes how can I do that give me example please.
any help will be appreciated.





Populate UITableView with custom objects?

I am unsuccessfully trying to populate a UITable from a NSMutableArray that contains a custom object.



My Student object



Student {
NSString name,
int age
}


In UITableView there is a method that displays the row's content:



cellForRowAtIndexPath
{
// there is more code here
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
}


Should my Student class implement a method that returns a String representation of the object? And then how can I display the content of the NSMutableArray in the UITableView.



Any help will be appreciated.





Counting the number of DIVs placed into a DIV via drag and Drop

I have had a look about the site and found some code and tried it out but its not working in any shape or form.



I am wanting to count the number of DIVs thats placed into another DIV by the user dragging and dropping but only to count the 'correct' ones then if all the correct ones are in the DIV display an alert saying well done then rest the 'game'. Also need to show how many more is needed to go to 'win'.



This is what I have so far:



JS:



    $('.drop').each(function(){ 
var n = $(this).children('.draggable').length;
$(".count").text("There are " + n + " divs inside parent box detail.");
if(n == 2){
alert("You got them all right! :)");
}
});


HTML:



    <div class="foods">
<div class="draggable" id="draggable"><img src="images/fish.png" id="draggable"></div>

<div class="draggable" id="draggable"><img src="images/stone.png"></div>

<div class="wrong"><img src="images/tree.png"></div>
</div>

<div class="foods">
<div id="droppable" class="drop">
<p>Drop here</p>
</div>
</div>

<div class="foods">
<span class="count"></span>
</div>


JS Fiddle of the code: http://jsfiddle.net/JRLZK/



Thanks in advanced for any help!





malformed start tag error - Python, BeautifulSoup, and Sipie - Ubuntu 10.04

I just installed python, mplayer, beautifulsoup and sipie to run Sirius on my Ubuntu 10.04 machine. I followed some docs that seem straightforward, but am encountering some issues. I'm not that familiar with Python, so this may be out of my league.



I was able to get everything installed, but then running sipie gives this:



/usr/bin/Sipie/Sipie/Config.py:12: DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5

Traceback (most recent call last):
File "/usr/bin/Sipie/sipie.py", line 22, in <module>
Sipie.cliPlayer()


File "/usr/bin/Sipie/Sipie/cliPlayer.py", line 74, in cliPlayer
completer = Completer(sipie.getStreams())


File "/usr/bin/Sipie/Sipie/Factory.py", line 374, in getStreams
streams = self.tryGetStreams()


File "/usr/bin/Sipie/Sipie/Factory.py", line 298, in tryGetStreams
soup = BeautifulSoup(data)


File "/usr/local/lib/python2.6/dist-packages/BeautifulSoup-3.1.0.1-py2.6.egg/BeautifulSoup.py", line 1499, in __init__
BeautifulStoneSoup.__init__(self, *args, **kwargs)


File "/usr/local/lib/python2.6/dist-packages/BeautifulSoup-3.1.0.1-py2.6.egg/BeautifulSoup.py", line 1230, in __init__
self._feed(isHTML=isHTML)


File "/usr/local/lib/python2.6/dist-packages/BeautifulSoup-3.1.0.1-py2.6.egg/BeautifulSoup.py", line 1263, in _feed
self.builder.feed(markup)


File "/usr/lib/python2.6/HTMLParser.py", line 108, in feed
self.goahead(0)


File "/usr/lib/python2.6/HTMLParser.py", line 148, in goahead
k = self.parse_starttag(i)


File "/usr/lib/python2.6/HTMLParser.py", line 226, in parse_starttag
endpos = self.check_for_whole_start_tag(i)


File "/usr/lib/python2.6/HTMLParser.py", line 301, in check_for_whole_start_tag
self.error("malformed start tag")


File "/usr/lib/python2.6/HTMLParser.py", line 115, in error
raise HTMLParseError(message, self.getpos())


HTMLParser.HTMLParseError: malformed start tag, at line 100, column 3



I looked through these files and the line numbers, but since I am unfamiliar with Python, it doesn't make much sense. Any advice on what to do next?





Handling sessions with procedural PHP

I would like to dedicate this page to handling sessions using procedural php.



I'll begin with how I start most of my projects:



session_name('Easy_App');
session_start();

if (!isset( $_SESSION['ip'] )){
$_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
}

if (!isset( $_SESSION['created'] )){
$_SESSION['created'] = time();
}

if (!isset( $_SESSION['overall_views'] )){
$_SESSION['overall_views'] = 1;
}
else {
$_SESSION['overall_views']++;
}

if (!isset( $_SESSION['username'] )){
$_SESSION['username'] = "";
}

if (!isset( $_SESSION['logged_in'] )){
$_SESSION['logged_in'] = 0;
}

/*A quick method to keep pageviews to < 5 pages per 1 second per session*/
if (!isset($_SESSION['first_action'])){
$_SESSION['first_action'] = time();
}

$first_action = $_SESSION['first_action'];
if (!isset( $_SESSION['action'] )){
$_SESSION['action'] = 1;
}
else{
$_SESSION['action']++;
}

$action=$_SESSION['action'];
if ($action>=5){
unset($_SESSION['action']);
unset($_SESSION['first_action']);
if((time() - $first_action) <=1){
exit("Please Don't Hammer My Site ");
}
}


So We have a starting point:




  1. The Start of a session with a few regularly used parameters

  2. In the last few lines, prevention of hammering by casual users.



My question is this:



Where would you go from here? Improvements of the above code or a brief snippet of how you handle sessions using procedural php would be greatly appreciated.





dpi for downloadable images

its simple my doubt.
The app have 4 directories(ldpi, mdpi, hdpi, xhdpi) with same images but different dpi . For mdpi is 160dpi, the one im using atm.



What happens with the images i download from the web? i have a news reader and that means each new have one image at least. And i want to have a decent image for all the smartphones.



Do i need different type of images or just download the same for all?
Can i know which resolution is best for each particular smartphone?



I couldn't find the "official" way to handle this so i dont know if its important dpi for images that we plan to download.



Regards!





Algorithm Complexity Time

I am currently having trouble identifying and understanding the complexity time of the following algorithm.



Background: There is a list of files, each containing a list of candidate Ids. Both, number of files and number of candidates within them are not fixed.



How would you calculate the time complexity for an algorithm which is responsible for:
Reading each file and adding all the unique candidate Ids into a Hashset?



Thanks.





Python: How can add words to a list?

Okay, the Title is a bit vague, but what I'm trying to do is download data online, parse it and then put the parsed 'data' into an excel file.



I'm getting stuck in trying to put the data into a vector or list. Note that, the data can be either words or numbers. Also, I the length of the data is unknown. I tried the code below:



class MyHTMLParser(HTMLParser):
def handle_data(self, data):
d=[]
d=d.append(data)

parser = MyHTMLParser()
parser.feed('<html><head><title>Test</title></head>'
'<body><h1>Parse me!</h1></body></html>')

d

Traceback (most recent call last):
File "<pyshell#34>", line 1, in <module>
d
NameError: name 'd' is not defined


I looked around the forum for an answer, but didn't seem to encounter anything. I am a beginner, so may I'm missing something basic? Thanks, for the help...





android xml loads fine in api 8 with WVGA, but crashes with api 14 with WXGA720 (tablet)

The program loads ok, and I can go through a couple screens, but when the main.xml tries to load, the program crashes only on api 14.



logcat output:



04-26 09:02:14.290: E/AndroidRuntime(566): FATAL EXCEPTION: main
04-26 09:02:14.290: E/AndroidRuntime(566): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.surreall.yacht/com.surreall.yacht.yatzee}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.os.Looper.loop(Looper.java:137)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread.main(ActivityThread.java:4340)
04-26 09:02:14.290: E/AndroidRuntime(566): at java.lang.reflect.Method.invokeNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): at java.lang.reflect.Method.invoke(Method.java:511)
04-26 09:02:14.290: E/AndroidRuntime(566): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-26 09:02:14.290: E/AndroidRuntime(566): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566): at dalvik.system.NativeStart.main(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
04-26 09:02:14.290: E/AndroidRuntime(566): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-26 09:02:14.290: E/AndroidRuntime(566): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.Activity.setContentView(Activity.java:1835)
04-26 09:02:14.290: E/AndroidRuntime(566): at com.surreall.yacht.yatzee.onCreate(yatzee.java:211)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.Activity.performCreate(Activity.java:4465)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
04-26 09:02:14.290: E/AndroidRuntime(566): ... 11 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.reflect.InvocationTargetException
04-26 09:02:14.290: E/AndroidRuntime(566): at java.lang.reflect.Constructor.constructNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-26 09:02:14.290: E/AndroidRuntime(566): ... 23 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.OutOfMemoryError
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.Bitmap.nativeCreate(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.content.res.Resources.loadDrawable(Resources.java:1937)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.View.<init>(View.java:2780)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.view.ViewGroup.<init>(ViewGroup.java:385)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
04-26 09:02:14.290: E/AndroidRuntime(566): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
04-26 09:02:14.290: E/AndroidRuntime(566): ... 26 more


i can't post the contents of main.xml due to the 30k character question limit on stack overflow, and it is more than that. suggestions of where to start?





How to store the id from the one table to another in ruby on rails 2

Hello i'm trying to make a simple review function on ruby on rails. i have create a scaffold with the following attributes




event_id:integer name:string review_text:text no_starts:integer




Then i made this change on the show (view) of my event




:review, :action => :new, :id => @event.id %>


now i configured the routes fine and on the controller of the review i made this changes.
on the new i have added this




@review = Review.new(:event_id => params[:id])
and removed this
@review = Review.new




Then the page loads the event id it cites on the page but when i'm trying to save it is not stored. i thing the problem is when i move from the new method to create it doesnt transfer the id of the event thats why but i'm still what i'm doing wrong in the new?





update field values based on current field values content provider android

I cannot get to update the field values of a content provider as a function of current field values.
For a single column, I try to do



...
ContentValues values = new ContentValues();
values.put(TableInOut.INOUT, TableInOut.INOUT + " + 1"); (*)
int numRowsUpdated = getContentResolver().update(TableInOut.CONTENT_URI_PRESENCE, values, "time_details > lastSafeEpoch.toString()", null);
values.clear();
...


LogCat says that numRowsUpdated are the expected ones, but there is no update?!
Any ideas please?



(*)
No luck even with these



values.put(TableInOut.INOUT,  "88 + 1"); 
values.put(TableInOut.INOUT, "\"" +TableInOut.INOUT + "\"" + " + 1");


These work, but they do not use current values



values.put(TableInOut.INOUT,  77); 
values.put(TableInOut.INOUT, "77");




Change textblock from class#.cs windows phone

I want change text of textblock (or property of any object) by a class file. but when i call that class i just know name of object?



example:



<TextBlock VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="25" Margin="25,220,0,0" Name="txbuser">Username :</TextBlock>


and i have file class.cs



how can i chan text obj when i just know Name obj is "txbuser"?
thanks all





mysql join query with sum retuns null

If article_payments table is null the query returns null. How shoul i set the query yo get recors if doesnt exist in SUM(payment_total) like 0.00 ?



SELECT article_name,user_real_name,user_name,SUM(`article_payment`) as holding,paid
FROM article_articles AS t1
JOIN article_users ON (t1.article_name=article_users.user_id)
JOIN (SELECT user_id,SUM(`payment_total`) as paid FROM article_payments GROUP BY user_id) AS t2 ON (t1.article_name=t2.user_id)
GROUP BY t2.user_id




how can I handle either-or with Rx?

I need to handle an either-or type situation with the Reactive-Extensions.



I have 2 events I'm receiving (A or B). When event A comes in followed by an event B within 2 seconds I want to generate a C. If an A is not followed by B then I'd like to generate a D.



Is there some way to express that with Rx??



Thanks





set values for 2nd selectbox from the selection of 1st selecbox

I have 2 select box as below. i want to make




  1. when user select A on 1st select box: only the value 100, 300 will appear on the 2nd select box

  2. when user select B on 1st select box: only the value 300, 900 will appear on the 2nd select box

  3. when user select C on 1st select box: only the value 100, 600, 900 will appear on the 2nd select box

  4. when user select D on 1st select box: only the value 100, 300, 900 will appear on the 2nd select box




    Select 1st
    A
    B
    C
    D


    Select 2nd
    100
    300
    600
    900