Posts

How do you write a Rails model method to return a list of its associations? -

what i'm trying write method return of model's outing_locations, has has_many relationship. class outing < activerecord::base attr_accessible :description, :end_time, :start_time, :title, :user_id belongs_to :user has_many :outing_locations has_many :outing_guests has_one :time_range, :foreign_key => "element_id", :conditions => { :element_type => "outing" } validates :title, :presence => true validates :start_time, :presence => true # regex validates :end_time, :presence => true # regex def host_name return user.find(self.user_id).full_name end end i'm trying block in particular work. there's model called outinginvite, contains id of particular outing. need use grab proper outing , pull said outing's associated outing locations. here's rough sample: <%@outing_invites.each |invite|%> ... <% @party = outing.where(:id => invite.outing_id) %> <% @party.out...

Access inner array in php -

i have folowing array: outerarray{ "id": "20154", "from": { "name": "xyz", "id": "10004" }} now how access element name ? it json , decode first using json_decode() , access: $arr = json_decode($yourjson, true); echo $arr['from']['name']; // xyz or $arr = json_decode($yourjson); echo $arr->from->name; // xyz http://php.net/manual/en/function.json-decode.php

android - How to prevent screen autorotation but prevent activity from rotating -

this may sound newbie question anyway i'm new android development. basically need prevent activity changing rotation meanwhile need detect device orientation change i.e. if device orientation has been changed top botton, or top left-portrait etc. in ios there analogue - (bool)shouldautorotatetointerfaceorientation can handle device orientation change , tell view if want autorotate or not. please pay attention no manual data handling of accelerometer data. so want detect device's orientation change , prevent activity rotating. i'm playing data sensor detect shake. internally android filtration of signals in order decide when rotate ui. need catch event. can ? simple formulation of question : i need detect android device orientation change without playing manually sensor data, while keeping activity orientation stick orientation this need if want fix 1 orientation landscape, go androidmanifest , in activity <activity android:label="@strin...

HTML5 Video in Safari -

little bit confused @ moment, have 2 .mp4 files, both h.264 encoded video. | #safari | video 1 | video 2 | | windows | failed | played | | osx | played | played | my code <video width="550" height="400" controls> <source src="test/charlie.mp4" type="video/mp4" /> <source src="test/charlie.ogv" type="video/ogg" /> nope. </video> video 1 status: http/1.1 200 ok date: wed, 27 jun 2012 09:19:02 gmt server: apache/2.2.22 (debian) last-modified: wed, 27 jun 2012 08:06:41 gmt etag: "aff04e8-49c7f3-4c36fb1f12640" accept-ranges: bytes content-length: 4835315 connection: close content-type: video/mp4 video 2 status: http/1.1 200 ok date: wed, 27 jun 2012 09:18:37 gmt server: apache/2.2.22 (debian) last-modified: mon, 28 dec 2009 05:06:33 gmt etag: "aff04eb-45de48-47bc2de762840" accept-ranges: bytes content...

mysql - Including a php file in Joomla! 1.5 that calls another php file -

i include php program joomla! article, program calls different php files used display want, have tried install different plugins such jumi, directphp , others, keep getting following error: application raised exception class edatabaseerror message 'cannot connect database server:mysql error: [0: connection error server '' user ''] in connect(, '', ' * *', ) ' the program runs fine standalone, not work when i'm running on joomla. the connection parameters obtained include "config.php" seems won't includes included php file. also when try include menu have made, works standalone, redirects me index.php of joomla! root dir. thanks. i've done things similar this, have had install couple of extensions them work. first, use jce wysiwyg. installed place anywhere (which lets place modules inside articles) create new module, type=custom html code php there... i know isn't you're describing, it'...

c++ - Strange runtime error when iterating over std::deque -

consider following piece of code: 1 typedef std::deque<int> mydeque_t; 2 mydeque_t mydeque; 3 4 mydeque_t::iterator start = mydeque.begin(); 5 6 (int = 0; != 1000; ++i) 7 mydeque.push_back(i); 8 9 (mydeque_t::iterator myint = start; myint != mydeque.end(); ++myint) 10 *myint += 1; when executing runtime error on line 10 (live example: http://ideone.com/juqaa ). when change line 6 for (int = 0; != 100; ++i) code works fine. the code fixed moving start definition (line 4) behind first loop, in example need stay before it. think should run fine, can explain me why not? after call push_back() , iterators invalidated. deque::push_back() : appends given element value end of container. all iterators invalidated . no references invalidated. guess : code works fine 100 , not 1000 internal storage of deque did not have reallocated accomodate 100 elements resulting in begin() iterator remaining valid.

java execution by inheriting from file from shared folder -

i have 2 files, 1 in local machine , in shared folder(from machine). my class on localmachine has inherit class in file in shared folder. how can perform inheritance? i tried giving set classpath=%classpath%;//(machineno)/(foldername); did not work. the urlclassloader can used develop application capable of loading classes , resources remote servers. first, need define urls searched classes. url ends '/' assumed refer directory, otherwise url assumed refer jar file opened needed. once instance of urlclassloader constructed, loadclass(string name) method of classloader class used load class specified name. once class has been loaded, instance can created (this means constructor invoked). import java.net.*; import java.io.*; public class myloader { public static void main (string argv[]) throws exception { urlclassloader loader = new urlclassloader(new url[] { new url("http://www.javacourses.com/classes/") }); // load class clas...