Pretend you're at an interview. The interviewer asks:
What is the decimal value of this binary number?
10110101
What is the first thing you responsed with?
I need to search through a list of folders that could have more folders inside it,
and add a new folder depending what folder is its parent.(the path is stored as a String for eg = "root/MyCom/home/") Then i fill in a field with a new folder name and add it to the final folder(eg "home/").
Below as you can see , I can navigate to the right location and add the new folder to a current folder, My trouble is that i cannot ensure that currentFolder element is placed back in the list it came from
how could i add a folder to a list of folders, that could be within a list of folders,that could be within a list of folders and endless more?
YFUser user = (YFUser)getSession().getAttribute(SESSION_USER);
Folder newFolder = new Folder();
newFolder.setFolderName(foldername);
// this is the path string (root/MyCom/home/) split in the different folder names
String folderNames[] = folderLocationString.split("/");
int folderNamesLength = folderNames.length;
Folder root = user.getRoot();
Folder currentFolder = root;
for(int i=0;i<=folderNamesLength; i++){
// because root is folderNames[i]
String folderName = folderNames[i++];
int currentFolderSize = currentFolder.getChildren.getSize();
for(int o=1; o<= currentFolderSize ; o++){
if(currentFolder.getChildren().get(o) instanceof Folder){
if(folderName.equals(currentFolder.getChildren().get(o).getFolderName())){
currentFolder = currentFolder.getChildren().get(o);
if (i == counter){
//now i am inside the correct folder and i add it to the list of folders within it
//the trouble is knowing how to re add this changed folder back to the list before it
currentFolder.getChildren.add(newFolder);
}
}
}
}
}
I have a user control that is emmitting javascript using the ClientId function. For example:
Out &= "ValidatorHookupControlID(" & Quote & ddlMonth.ClientID & Quote & "), document.all(" & Quote & CustomValidator1.ClientID & Quote & "));" & vbCrLf
It appears to me that the ClientID function DOES not return the ultimate ID that is sent to the browser. Instead, the ClientID function only appears to be aware of its current parent control, which in this case is a the User Control and so the ID that is returned is the ID "dtmPassportExpirationDate_ddlMonth"
When in fact the usercontrol is included in a master page and the ultimate ID that is used is:
"ctl00_phPageContent_dtmPassportExpirationDate_ddlMonth"
I may be nuts, but that's what it appears to be doing. I expect that the ClientID function would return the ultimate ID used in the HTML.
Am I missing something?
I am trying to list all of the functions a namespace has in it (warning - I'm really new to Tcl, so I'll probably use the wrong words for parts of Tcl). For example, I have a tcl shell someone compiled for me (if that's the right way to phrase it), and I know at least one function exists, let's call it
blah::do_something
I know in ruby there are ways to list all the functions in a module/namespace. How would I find out what other functions are available in the blah namespace in Tcl?
Thanks in advance
Hello guys
I am new to php dom and trying to get the mysql data transfer into xml. My current xml output is like this
<markers>
<city>
<name>Seattle</name>
<size>medium</size>
<name>New York</name>
<size>big</size>
<city>
<markers>
but I want to change it to
<markers>
<city>
<name>Seattle</name>
<size>medium</size>
<city>
<city>
<name>New York</name>
<size>big</size>
</city>
<city>
<markers>
my php
$dom=new DOMDocument("1.0");
$node=$dom->createElement("markers");
$parnode=$dom->appendChild($node);
$firstElement=$dom->createElement("city");
$parnode->appendChild($firstElement);
$getLocationQuery=mysql_query("SELECT * FROM location",$connection);
header("Content-type:text/xml");
while($row=mysql_fetch_assoc($getLocationQuery)){
foreach ($row as $fieldName=>$value){
$child=$dom->createElement($fieldName);
$value=$dom->createTextNode($value);
$child->appendChild($value);
$firstElement->appendChild($child);
}
}
I can't figure out how to change my php code. Please help me about it. Thanks a lot.
Hi friends,
I have incorporated ClientLogin into my python application to retrieve contact list of the user , I like to know how to get the name of the user who has logged in.My code to get the names from the contact list of the user is as given below
gd_client = gdata.contacts.service.ContactsService()
gd_client.email = yemail
gd_client.password = ypass
gd_client.source = 'GoogleInc-ContactsPythonSample-1'
gd_client.ProgrammaticLogin()
query = gdata.contacts.service.ContactsQuery()
query.max_results=150
feed = gd_client.GetContactsFeed(query.ToUri())
for i, entry in enumerate(feed.entry):
#print '\n%s %s' % (ctr+i+1, entry.title.text)
na=entry.title.text
names.append(na)
Please help me to know how to get the name of the user who has logged in
Thanks
ganesh
Hello all. I'm currently stuck trying to figure out how to sort my array files. I have a simple news posting system that stores the content in seperate .dat files and then stores them in an array. I numbered the files so that my array can sort them from lowest number to greatest; however, I have run into a small problem. To begin here is some more information on my system so that you can understand it better.
The function that gathers my files is:
function getNewsList() {
$fileList = array();
// Open the actual directory
if($handle = opendir(ABSPATH . ADMIN . "data")) {
// Read all file from the actual directory
while($file = readdir($handle)) {
if(!is_dir($file)) {
$fileList[] = $file;
}
}
}
// Return the array.
return $fileList;
}
On a seperate file is the programming that processes the news post. I didn't post that code for simplicity's sake but I will explain how the files are named. The files are numbered and the part of the post's title is used... for the numbering I get a count of the array and add "1" as an offset. I get the title of the post, encode it to make it file-name-friendly and limit the amount of text so by the end of it all I end up with:
// Make the variable that names the file that will contain
// the post.
$filename = "00{$newnumrows}_{$snipEncode}";
When running print_r on the above function I get:
Array (
[0] => 0010_Mira_mi_Soledad.dat
[1] => 0011_WOah.dat
[2] => 0012_Sinep.dat
[3] => 0013_Living_in_Warfa.dat
[4] => 0014_Hello.dat
[5] => 001_AS.dat
[6] => 002_ASASA.dat
[7] => 003_SSASAS.dat
...
[13] => 009_ASADADASADAFDAF.dat
)
And this is how my content is displayed. For some reason according to the array sorting 0010 comes before 001...? Is there a way I can get my array to sort 001 before 0010?
my superview is UItabelview and my subviews are UITabelview and UIDatePicker.
for my subviews didn't able to call
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
why?
bcoz this method calls when view rotates and at that time i want to set autoresizingmask method for that view so that when my subview rotates from Portrait to landscape mode it's view resizes automatically?
A sequence is bitonic if it monotonically increases and then monotonically de-
creases, or if it can be circularly shifted to monotonically increase and then
monotonically decrease. For example the sequences 1, 4, 6, 8, 3, -2 ,
9, 2, -4, -10, -5 , and 1, 2, 3, 4 are bitonic, but 1, 3, 12, 4, 2, 10 is not
bitonic.
please help me to determine if given sequence is bitonic?
Here is example from J. Richter book "CLR via C#":
Nullable<Int32> y = null;
How exactly this works? Nullable is a struct, and I can not figure out is this compiler special support or implicit boxing of null value or something else.
How do i read in char type by users if they are a- , b+ , o+ ? I don't seem to have problem reading in char like a , b , c or d. i am using read(X) . Can someone help me out with this ? Thanks in advance.
Hi all,
This is my first year learning C++ so bear with me. I am attempting to dynamically allocate memory to the heap and then delete the allocated memory. Below is the code that is giving me a hard time:
// String.cpp
#include "String.h"
String::String() {}
String::String(char* source)
{
this->Size = this->GetSize(source);
this->CharArray = new char[this->Size + 1];
int i = 0;
for (; i < this->Size; i++) this->CharArray[i] = source[i];
this->CharArray[i] = '\0';
}
int String::GetSize(const char * source)
{
int i = 0;
for (; source[i] != '\0'; i++);
return i;
}
String::~String()
{
delete[] this->CharArray;
}
Here is the error I get when the compiler tries to delete the CharArray:
0xC0000005: Access violation reading location 0xccccccc0.
And here is the last call on the stack:
msvcr100d.dll!operator delete(void * pUserData) Line 52 + 0x3 bytes C++
I am fairly certain the error exists within this piece of code but will provide you with any other information needed. Oh yeah, using VS 2010 for XP.
Thanks for any and all help!
Hi,
I know that encapsulation is binding the members and its behavior in one single entity. And it has made me think that the members have to be private. Does this mean if a class having public members is not following 100% Encapsulation rule?
Thanks
I'm trying to fill selects with json data from a web service. I'm getting error 'Object doesn't support this property or method.' when I do this $(this).html(options.join''));
Any ideas what I'm doing wrong?
;(function($) {
$.fillSelect = {};
$.fn.fillSelect = function(url, map) {
var jsonpUrl = url + "?callback=?";
$.getJSON(jsonpUrl,
function(d) {
var options = [];
var txt = map[0];
var val = map[1];
options.push('<option>--Select--</option>');
$.each(d, function(index, item) {
options.push('<option value="' + item[val] + '">' + item[txt] + '</option>');
});
$(this).html(options.join('')); //getting error Object doesn't support this property or method
}
};
})(jQuery);
By using left hand rule, I rotate one object left and right using y axis, and rotate up/down using x axis.
After first object is rotated to the right, the up/down rotation should be using z axis.
However, when I try to rotate using z axis, after the first rotation, it has the same effect when I rotate using y axis.
Anyone has any ideas?
Thanks
Hey guys,
I'm working on tile collision. Currently, I just draw the tile map the normal way (two for loops) and there is no scrolling. Right now, to check if my player is over a tile, I use tileX = (int)person1v.X / 16;
tileY = (int)person1v.Y / 16;
However, I want to detect collision before I hit the tile so it could act as a wall. How do I detect collision before even making the move?
using (TransactionScope scope = new TransactionScope())
{
int updatedRows1 = custPh.Update(cust.CustomerID, tempPh1, 0);
int updatedRows2 = custPh.Update(cust.CustomerID, tempPh2, 1);
int updatedRows3 = cust.Update();
if (updatedRows1 > 0 && updatedRows2 > 0 && updatedRows3 > 0)
{
scope.Complete();
}
}
Is the above TransactionScope code structured correctly? This is my first time using it so i'm trying to make as simple as i can.
I have a person object, which can have unlimited number of first names. So the first names are another object.
ie
person --- name
--- name
--- name
What I want to do is write an nhiberate query using which will get me a person who has certain names.
so one query might be find someone whose names are alison and jane and philippa, then next query may be one to find someone whose names are alison and jane.
I only want to return people who have all the names I'm search on. So far I've got
ICriteria criteria = session.CreateCriteria(typeof (Person));
criteria.CreateAlias("Names", "name");
ICriterion expression = null;
foreach (string name in namesToFind)
{
if (expression == null)
{
expression = Expression.Like("name.Value", "%" + name + "%");
}
else
{
expression = Expression.Or(
expression,
Expression.Like("name.Value", "%" + name + "%"));
}
}
if (expression != null)
criteria.Add(expression);
But this is returning every person with ANY of the names I'm searching on, not ALL the names.
Can anyone help me out with this? Thanks!
Hello, I'm a newbie to threading, and I don't really know how to code a particular task. I would like to handle a mouse click event on a window that will kick off a while loop in a seperate thread. This thread, which is distinct from the UI thread, should call a function in the while loop which updates a label on the window being serviced by the UI thread. The while loop should stop running when the left mouse button is no longer being pressed. All the loop does is increment a counter, and then repeatedly call the function which displays the updated value in the window. The code for the window and all of the threading is given below (I keep getting some error about STA threading, but don't know where to put the attribute). Also, I'm hoping to use this solution, if it ever works, in another project that makes asynchronous calls elsewhere to a service via wcf, so I was hoping not to make any application-wide special configurations, since I'm really new to multi-threading and am quite worried about breaking other code in a larger program... Here's what I have:
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication2"
Name="MyMainWindow"
Title="MainWindow" Width="200" Height="150"
PreviewMouseLeftButtonDown="MyMainWindow_PreviewMouseLeftButtonDown">
<Label Height="28" Name="CounterLbl" />
</Window>
And here's the code-behind:
using System.Windows;
using System.Windows.Input;
using System.Threading;
namespace WpfApplication2
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private int counter = 0;
public MainWindow()
{
InitializeComponent();
}
private delegate void EmptyDelegate();
private void MyMainWindow_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Thread counterThread = new Thread(new ThreadStart(MyThread));
counterThread.Start();
}
private void MyThread()
{
while (Mouse.LeftButton == MouseButtonState.Pressed)
{
counter++;
Dispatcher.Invoke(new EmptyDelegate(UpdateLabelContents), null);
}
}
private void UpdateLabelContents()
{
CounterLbl.Content = counter.ToString();
}
}
}
Anyways, multi-threading is really new to me, and I don't have any experience implementing it, so any thoughts or suggestions are welcome!
Thanks,
Andrew
Hi,
I'm setting up a group / user based security system.
I have 4 tables as follows:
user
groups
group_user_mappings
acl
where acl is the mapping between an item_id and either a group or a user.
The way I've done the acl table, I have 3 columns of note (actually 4th one as an auto-id, but that is irrelevant)
col 1 item_id (item to access)
col 3 user_id (user that is allowed to access)
col 3 group_id (group that is allowed to access)
So for example
item1, peter, ,
item2, , group1
item3, jane, ,
so either the acl will give access to a user or a group. Any one line in the ACL table with either have an item - user mapping, or an item group.
If I want to have a query that returns all objects a user has access to, I think I need to have a SQL query with a UNION, because I need 2 separate queries that join like..
item - acl - group - user AND
item - acl - user
This I guess will work OK. Is this how its normally done? Am I doing this the right way?
Seems a little messy. I was thinking I could get around it by creating a single user group for each person, so I only ever deal with groups in my SQL, but this seems a little messy as well..
I am trying to do an app, to where when it launches, it will detect audio, and then play it back automatically. NO BUTTONS, nothing to press. Just a picture of something then, it listens for audio, then plays it back. Similar to the Talking Carl app in the App Store. Any ideas/help? Would appreciate it, if i could use the code with IB.
In my Cocoa program, wouldn't a really simple way of dealing with autoreleased objects be to just create a timer object inside the app delegate that calls the following method e.g. every 10 seconds:
if (pool) {
// Release & drain the current pool to free the memory.
[pool release];
}
// Create a new pool.
pool = [[NSAutoreleasePool alloc] init];
The only problems I can imagine are:
1) If the above code runs in a separate thread, an object might get autoreleased between the release call to the old pool and the creation of the new pool - that seems highly unlikely though.
2) It's obviously not that efficient, because the pool might get released if there's nothing in it. Likewise, in the 10 second gap, many many objects might be autoreleased, causing the pool to grow a lot.
Still, the above solution seems pretty suitable to small and simple projects. Why doesn't anybody use it? What's the best practice of using NSAutoreleasePools?
In Effective Java, the author states that:
If a class implements Cloneable,
Object's clone method returns a
field-by-field copy of the object;
otherwise it throws
CloneNotSupportedException.
What I'd like to know is what he means with field-by-field copy. Does it mean that if the class has X bytes in memory, it will just copy that piece of memory? If yes, then can I assume all value types of the original class will be copied to the new object?
class Point {
private int x;
private int y;
@Override
public Point clone() {
return (Point)super.clone();
}
}
If what Object.clone() does is a field by field copy of the Point class, I'd say that I wouldn't need to explicitly copy fields x and y, being that the code shown above will be more than enough to make a clone of the Point class. That is, the following bit of code is redundant:
@Override
public Point clone() {
Point newObj = (Point)super.clone();
newObj.x = this.x; //redundant
newObj.y = this.y; //redundant
}
Am I right?
I know references of the cloned object will point automatically to where the original object's references pointed to, I'm just not sure what happens specifically with value types. If anyone could state clearly what Object.clone()'s algorithm specification is (in easy language) that'd be great.
Thanks