raulzito234

A nerd blog about cs

Detecting iPhone versus iPad


if([deviceType isEqualToString:@"iPhone Simulator"] || [deviceType isEqualToString:@"iPhone"])

{

NSLog(@"É iPhone seu viado!");

NSLog(@"%@", deviceType);

}

else {

NSLog(@"é iPad seu baitola");

NSLog(@"%@", deviceType);

// Movie explaining what to do!

NSString *stringPath = [[NSBundle mainBundle] pathForResource:@"Scan" ofType:@"MOV"];

NSURL *url = [NSURL fileURLWithPath:stringPath];

mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];

[mpc.view setFrame:CGRectMake(40, 100, 310, 310)];

[mpc setRepeatMode:MPMovieRepeatModeOne];

[mpc setScalingMode:MPMovieScalingModeAspectFill];

[[self view]addSubview:mpc.view];

[mpc prepareToPlay];

[mpc play];

mpc.view.backgroundColor = [UIColor grayColor];

[mpc setControlStyle:MPMovieControlStyleNone];

[self.view addSubview:mpc.view];

}

Deploying app to Iphone 5.

When building (or archiving) an app to the IPhone (Need to choose the target) it’s necessary to remove the armv7s on the building info. Then you should archive the app.

When building to the simulator, then add again the armv7s.

How to get the database sqlite from the documents directory

http://stackoverflow.com/questions/6620691/how-to-get-sqlite-database-file-when-application-is-running-on-device

Connecting the Storyboard to a ViewController Class.

It’s hard to find how to link a Storyboard View Controller to a ViewController Class. The way to do this is to modify the property shown in the picture.Screen Shot 2013-08-14 at 4.58.12 PM

Run Matlab code in csail condor clusters.

So let’s say you write a bunch of matlab code but you have a lot of data to process. You submit your code to some clusters doing the following and the following.

But when you submit your code, it doesn’t run!!! Why? Because you don’t have enough licenses to do it. So instead of crying you can use octave,

If you are using the csail clusters octave v3.0 will be probably installed on the filesystem. But if you need more capabilities (like I do) you will probably need to download and install a new version of octave and then compile it.

 

NOTE: https://lists.cs.wisc.edu/archive/htcondor-users/2010-May/msg00139.shtml

How to Create multiple Condor jobs

If you want to know how to create a single condor job, please follow this post.

My code runs matlab code. To run many jobs I created a script that creates a script per job the name of the script of each single job is matlab.sh.  The following script creates such a script:

#!/bin/sh

bashstring="#!/bin/sh"
prefix="matlab -nodisplay -nodesktop -nosplash -nojvm -r \"SimilarityMeasureWithInput('"
sufix="')\""
FILES=./Fragments/Training/*
for f in $FILES
do
 echo $bashstring$'\n'$prefix$f$sufix >> matlab.sh
 chmod u+x matlab.sh
 condor_submit mat.submit
 rm matlab.sh
done

The above code checks all files under the directory ./Fragments/Training and loops through them, it then prints the content of the concatenated string $bashstring$’\n’$prefix$f$sufix to the file matlab.sh. For example a script file matlab.sh will look like this:


#!/bin/sh

matlab -nodisplay -nodesktop -nosplash -nojvm -r "SimilarityMeasureWithInput('./Fragments/Training/14_2_1.jpg')"

It makes the script file runnable by the user with the command chmod and then submits the job. The submit file is named mat.submit in this case, but it can be named anything. Don’t forget to create the submit file.

Installing OpenNi and Kinect Body Tracker

Follow the instruction here:

http://decyborg.wordpress.com/2013/01/19/kinect-on-os-x-10-8-and-processing/

For coding use the reference page:
http://kinectcar.ronsper.com/docs/openni/introduction.html

When the NITE application finds the hand it prints the following:

Session start: (685.803162,182.640594,2355.797607)
** 2
Point (685.803162,182.640594,2355.797607) -> (487.627411,195.358078,2355.797607)
Point (685.803162,182.640594,2355.797607) -> (487.627411,195.358078,2355.797607)

The number after ** is the number of times that it found the hand since the start of the application.

Is Neymar the best brazilian striker player?

Today Barcelona is unveiling Neymar. They bought him for a very large sum, not only because of his skills because he is an idol in Brazil. His image is very valuable as well.

Neymar

But one question that I was wondering was Is he actually a good soccer player?

So as a Computer Scientist I went ahead and grabbed some stats for the most famous soccer players in Brazil. And also for the rest of the world. I used 2 different metrics from us soccerway. The metrics are goals per minute for Domestic Leagues and National Team.

They are representative of how well they play because each player played a significant amount of minutes on the domestic leagues and for the national team.

Domestic Leagues

DomesticLeagues

According to this list, Hulk unexpectedly is the best, followed by Fred, then Neymar, Pato and Lucas. Hulk might be so ahed because he plays for a Russian team and played for a Portuguese team for quite a while. Both leagues are not known for their competitiveness.

But Fred, Neymar, Pato and Lucas have played quite a while in Brazil. Therefore the rank Fred >> Neymar >> Pato >> Lucas might be very representative of how well they play.
International Cups

International

Again what we see is the rank Fred >> Neymar >> Pato >> Lucas. These numbers show that Hulk is actually not better than the other players but played against weaker teams. Hulk is better than Lucas in both of the measures, but Hulk is a forward player as Lucas is midfielder/winger. Even tough Hulk appears to be the 1st in the rank for domestic cups, he is probably not a good choice for the Brazilian National Team. He was elected as one of the biggest disappointments in the Russian Cup by Life Sports.

Fred is 32% better in the national team stats and 4% better in the domestic league stats, showing that he is better than Neymar in average and therefore is the best brazilian striker player.

But given that Neymar is the 2nd best brazilian striker (excluding Hulk) and is such an iconic figure, Barcelona probably was smart on buying him.

There were other questions that I always had and since I had the numbers in my  hand I was able to answer them. Here they are:

Does Messi play better in Barcelona compared to Argentina?

Let’s look at the numbers again:

Messi

Messi scores a lot of goals compared to any other brazilian player (except Hulk), but when it comes to the National Team he is behind Fred, Neymar and Pato. The team is an important part of how players perform and shouldn’t be  undermined. Actually Messi has 42% of the performance in his National Team (Argentina) compared to the performance he has in Barcelona.

If you look at other players, they do not underperform like Messi does when playing for a national team (Except Hulk). Therefore Messi plays much better for Barcelona compared to Argentina.

Who is the best striker?

Now let’s compare all the best strikers. The metrics used are the same. Here they are:

DomesticLeague

David Villa presents the best numbers for Domestic Leagues. Who would expect that? Messi comes in second place and then Ronaldinho!!! David Villa and Messi perform much better than the rest of the players. Now let’s look at the national teams performance:

NationalTeam

We can notice that David Villa was both 1st and 2nd on both metrics. He is definitely the player that has the biggest average compared to other players. David Villa is the best striker playing nowadays.

Installing ROS (Robot Operating System) on MAC

I’m following the manual here: ROS Manual Page When I try to make the program:


make -j8

I’m getting the following error:


Linking CXX shared library ../devel/lib/librospack.dylib

Linking CXX shared library ../devel/lib/librosconsole.dylib

Undefined symbols for architecture x86_64:
 "boost::filesystem3::path::wchar_t_codecvt_facet()", referenced from:
 boost::filesystem3::path::codecvt() in rospack.cpp.o

Undefined symbols for architecture x86_64:
 "boost::this_thread::get_id()", referenced from:
 ros::console::print(ros::console::FilterBase*, log4cxx::Logger*, ros::console::levels::Level, char const*, int, char const*, char const*, ...) in rosconsole.cpp.o
 ros::console::print(ros::console::FilterBase*, log4cxx::Logger*, ros::console::levels::Level, std::basic_stringstream<char, std::char_traits, std::allocator > const&, char const*, int, char const*) in rosconsole.cpp.o
 ros::console::ThreadToken::getString(log4cxx::helpers::ObjectPtrT const&) in rosconsole.cpp.o
ld: symbol(s) not found for architecture x86_64
 "boost::filesystem3::path::m_erase_redundant_separator(unsigned long)", referenced from:
 boost::filesystem3::path& boost::filesystem3::path::append(std::string const&, std::codecvt<wchar_t, char, __mbstate_t> const&) in rospack.cpp.o
 "boost::filesystem3::path::m_append_separator_if_needed()", referenced from:
 boost::filesystem3::path& boost::filesystem3::path::append(std::string const&, std::codecvt<wchar_t, char, __mbstate_t> const&) in rospack.cpp.o
 "boost::filesystem3::path::operator/=(boost::filesystem3::path const&)", referenced from:
 rospack::Rosstackage::exports_dry_package(rospack::Stackage*, std::string const&, std::string const&, std::vector<std::string, std::allocator >&) in rospack.cpp.o
 boost::filesystem3::operator/(boost::filesystem3::path const&, boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::current_path(boost::system::error_code*)", referenced from:
 boost::filesystem3::current_path() in rospack.cpp.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [devel/lib/librosconsole.dylib] Error 1
 "boost::filesystem3::detail::dir_itr_close(void*&, void*&)", referenced from:
make[1]: *** [rosconsole/CMakeFiles/rosconsole.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
 boost::filesystem3::detail::dir_itr_imp::~dir_itr_imp() in rospack.cpp.o
 "boost::filesystem3::detail::create_directory(boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::create_directory(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::directory_iterator_construct(boost::filesystem3::directory_iterator&, boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::directory_iterator::directory_iterator(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::detail::directory_iterator_increment(boost::filesystem3::directory_iterator&, boost::system::error_code*)", referenced from:
 boost::filesystem3::directory_iterator::increment() in rospack.cpp.o
 "boost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)", referenced from:
 boost::filesystem3::is_directory(boost::filesystem3::path const&) in rospack.cpp.o
 boost::filesystem3::is_regular_file(boost::filesystem3::path const&) in rospack.cpp.o
 boost::filesystem3::exists(boost::filesystem3::path const&) in rospack.cpp.o
 "boost::filesystem3::path::parent_path() const", referenced from:
 rospack::Rosstackage::inStackage(std::string&) in rospack.cpp.o
 "boost::filesystem3::path::filename() const", referenced from:
 rospack::Rosstackage::isStackage(std::string const&) in rospack.cpp.o
 rospack::Rosstackage::crawlDetail(std::string const&, bool, int, bool, std::vector<rospack::DirectoryCrawlRecord*, std::allocator<rospack::DirectoryCrawlRecord*> >&, boost::unordered_set<std::string, boost::hash, std::equal_to, std::allocator >&) in rospack.cpp.o
 rospack::Rosstackage::inStackage(std::string&) in rospack.cpp.o
 rospack::Rosstackage::addStackage(std::string const&) in rospack.cpp.o

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

make[2]: *** [devel/lib/librospack.dylib] Error 1

make[1]: *** [rospack/CMakeFiles/rospack.dir/all] Error 2

make: *** [all] Error 2

The problem is when linking the following libraries: rospack and rosconsole To compile and link the libraries, the ROS package is using:

CMake

Cmake is a tool for helping software compilation. It creates the Makefiles necessary for compiling. To achieve that, it’s necessary to create files that will inform the dependencies and whatnot into the packages being built. These files containing the information of how to compile and what is necessary to compile these files are CMakeLists.txt. There is a command to include external libraries called find_package The problem seems to be that when finding the package, CMake is including a newer version of the library that I need (in my case boost). To include a specific version of a library, you can write the following:


find_package(<library_name> <version_number> EXACT)

In my case I wrote:


find_package(boost 1.47 EXACT)

Then when I tried to build the packages running:


make VERBOSE=1

It said that the library installed was not the one required, it was a new one in /usr/local/. So I installed an older version of the library with homebrew. Using the following commands:

$ brew versions boost
$ git checkout 57665ff /usr/local/Library/Formula/boost.rb
$ brew install boost
$ git checkout master

EDIT #1: It seems that this is a known issue.

EDIT #2: Running gdb with the program appears to show the probable problem that is causing the program to present the malloc issue. GDB is a tool to debug running code, allowing to see what is going on “inside” the program. I ran the following code:


$ gdb rospack

which outputs the following message:


warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_operations.o" - no debug information available for "v2_operations.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_path.o" - no debug information available for "v2_path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v2/src/v2_portability.o" - no debug information available for "v2_portability.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/operations.o" - no debug information available for "operations.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/path.o" - no debug information available for "path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/portability.o" - no debug information available for "portability.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/codecvt_error_category.o" - no debug information available for "codecvt_error_category.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/path_traits.o" - no debug information available for "path_traits.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/unique_path.o" - no debug information available for "unique_path.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/filesystem/build/darwin-4.2.1/release/threading-multi/v3/src/utf8_codecvt_facet.o" - no debug information available for "utf8_codecvt_facet.cpp".

.
warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/cmdline.o" - no debug information available for "cmdline.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/config_file.o" - no debug information available for "config_file.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/options_description.o" - no debug information available for "options_description.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/parsers.o" - no debug information available for "parsers.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/variables_map.o" - no debug information available for "variables_map.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/value_semantic.o" - no debug information available for "value_semantic.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/positional_options.o" - no debug information available for "positional_options.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/utf8_codecvt_facet.o" - no debug information available for "utf8_codecvt_facet.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/convert.o" - no debug information available for "convert.cpp".

warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/program_options/build/darwin-4.2.1/release/threading-multi/split.o" - no debug information available for "split.cpp".

.
warning: Could not find object file "/private/tmp/boost-HXkH/boost_1_47_0/bin.v2/libs/system/build/darwin-4.2.1/release/threading-multi/error_code.o" - no debug information available for "error_code.cpp".

Running Condor (CSAIL cluster)

Runing Code:

Create 2 files:

  1. Description file.
  2. Script.

Create this two files under the directory

/data/scratch/

1. The description file, in this case will be called echo.submit and it’s content is:

###standard condor headers for CSAIL###
# preserve your environment variables<br />GetEnv = True
# use the plain nothing special universe<br />Universe = vanilla
# only send email if there's an error<br />Notification = Error
# Allows you to run on different "filesystem domains"
#by copying the files around if needed
should_transfer_files = IF_NEEDED
WhenToTransferOutput = ON_EXIT
###END HEADER###
###job specific bits###
Executable = echo.sh
#Arguments =<br /># queue log (doesn't like to be on NFS due to locking needs)
Log = /tmp/echo.$ENV(USER).log
#What to do with stdin,stdout,stderr
# $(PROCESS) is replaced by the sequential
# run number (zero based) of this submission<br /># see "queue" below
#Input = input.$(PROCESS)
Error = err.$(PROCESS)
Output = out.$(PROCESS)
# how many copies of this job to queue
queue 1
####END job  specific bits###

2. The script contains the code that will run in the machine, in this case echo.sh:

<br /><br />#!/bin/sh<br />echo $PATH<br /><br />

Don’t forget to make the file runnable by you (the user):

>> chmod u+x echo.sh

Then run the code:

 >> condor_submit <description_file>

In my case I ran the command:

>> condor_submit echo.submit

Errors:

If you get the following error:

ERROR: Failed to parse command file (line 3).

Probably you are not using the correct description file or your description file does not contain the correct text.

When running the code I got the following error because I was entering the script file instead of the description file.

Managing Jobs:

The following code allows to manage submitted code:

>> condor_status -submitters

I’m able to see that the code that I submitted is being held. Therefore if you want to see if the code is run, then use the above code.

The following code may not show what jobs are queued or held:

For managing the submitted jobs, the manual says to use the following command to see all the submitted jobs by all users:

>> condor_q

Or the following command (to find jobs submitted by my user):

>> condor_q $USER

When I ran the above code the first times, I got the following response:

— Submitter: borg-login-1.csail.mit.edu : : borg-login-1.csail.mit.edu
ID OWNER SUBMITTED RUN_TIME ST PRI SIZE CMD

0 jobs; 0 completed, 0 removed, 0 idle, 0 running, 0 held, 0 suspended

I.e. the code that I submitted to the clusters seemed to not be submitted.

Some days after the command seemed to be working normally (weird).

Releasing Jobs (Held Jobs):

For many reasons your jobs can be held. One possible reason, for example, is that if you are running matlab you might not have sufficient licenses to run the program. After you run many jobs and have solved such issues you can free your jobs from being on hold using the following command:

>> condor_release -all

This command will release all held jobs. For more information on this go here.

Removing Jobs:

>> condor_rm $USER