Search Results

Search found 1647 results on 66 pages for 'ben thompson'.

Page 57/66 | < Previous Page | 53 54 55 56 57 58 59 60 61 62 63 64  | Next Page >

  • Could this be considered a well-written class (am I using OOP correctly)?

    - by Ben Dauphinee
    I have been learning OOP principals on my own for a while, and taken a few cracks at writing classes. What I really need to know now is if I am actually using what I have learned correctly, or if I could improve as far as OOP is concerned. I have chopped a massive portion of code out of a class that I have been working on for a while now, and pasted it here. To all you skilled and knowledgeable programmers here I ask: Am I doing it wrong? class acl extends genericAPI{ // -- Copied from genericAPI class protected final function sanityCheck($what, $check, $vars){ switch($check){ case 'set': if(isset($vars[$what])){return(1);}else{return(0);} break; } } // --------------------------------- protected $db = null; protected $dataQuery = null; public function __construct(Zend_Db_Adapter_Abstract $db, $config = array()){ $this->db = $db; if(!empty($config)){$this->config = $config;} } protected function _buildQuery($selectType = null, $vars = array()){ // Removed switches for simplicity sake $this->dataQuery = $this->db->select( )->from( $this->config['table_users'], array('tf' => '(CASE WHEN count(*) > 0 THEN 1 ELSE 0 END)') )->where( $this->config['uidcol'] . ' = ?', $vars['uid'] ); } protected function _sanityRun_acl($sanitycheck, &$vars){ switch($sanitycheck){ case 'uid_set': if(!$this->sanityCheck('uid', 'set', $vars)){ throw new Exception(ERR_ACL_NOUID); } $vars['uid'] = settype($vars['uid'], 'integer'); break; } } private function user($action = null, $vars = array()){ switch($action){ case 'exists': $this->_sanityRun_acl('uid_set', $vars); $this->_buildQuery('user_exists_idcheck', $vars); return($this->db->fetchOne($this->dataQuery->__toString())); break; } } public function user_exists($uid){ return($this->user('exists', array('uid' => $uid))); } } $return = $acl_test->user_exists(1);

    Read the article

  • Can first descendent be selected directly?

    - by Ben Huh
    I am currently using find() and first() method to select the first descendent element from each of the <div> elements that contains the parent class. But I find this quite cumbersome since find() method would produce a set of matched elements before the first element is being picked. The following is the skeleton of my code: HTML <div class=parent> <ul> <li>random characters</li> <li>random characters</li> <li>random characters</li> <li>random characters</li> </ul> </div> <div class=parent> <ul> <li>random characters</li> <li>random characters</li> <li>random characters</li> <li>random characters</li> </ul> </div> <div class=non-parent> <ul> <li>random characters</li> <li>random characters</li> <li>random characters</li> <li>random characters</li> </ul> </div> <div class=parent> <ul> <li>random characters</li> <li>random characters</li> <li>random characters</li> <li>random characters</li> </ul> </div> // .....the list continues Javascript $('.parent').each(function() { $(this).find('ul li').first().css('color', 'red'); // do other stuff within each loop }); I have seen people using $(".parent li:first") selector. But, because I am doing it in a loop, I am not sure how or whether if this could be done and would like some advice. Thanks.

    Read the article

  • C++ Filling an 1D array to represent a n-dimensional object based on a straight line segment

    - by Ben
    I'm struggling to find a good way to put this question but here goes. I'm making a system that uses a 1D array implemented as double * parts_ = new double[some_variable];. I want to use this to hold co-ordinates for a particle system that can run in various dimensions. What I want to be able to do is write a generic fill algorithm for filling this in n-dimensions with a common increment in all direction to a variable size. Examples will serve best I think. Consider the case where the number of particles stored by the array is 4 In 1D this produces 4 elements in the array because each particle only has one co-ordinate. 1D: {0, 25, 50, 75}; In 2D this produces 8 elements in the array because each particle has two co-ordinates.. 2D: {0, 0, 0, 25, 25, 0, 25, 25} In 3D this produces 12 elements in the array because each particle now has three co-ordinates {0, 0, 0, 0, 0, 25, 0, 0, 50, ... } These examples are still not quite accurate, but they hopefully will suffice. The way I would do this normally for two dimensions: int i = 0; for(int x = 0; x < parts_size_ / dims_ / dims_ * 25; x += 25) { for(int y = 0; y < parts_size_ / dims_ / dims_ * 25; y += 25) { parts_[i] = x; parts_[i+1] = y; i+=2; // Indentation hates me today .< How can I implement this for n-dimensions where 25 can be any number? The straight line part is because it seems to me logical that a line is a somewhat regular shape in 1D, as is a square in 2D, and a cube in 3D. It seems to me that it would follow that there would be similar shapes in this family that could be implemented for 4D and higher dimensions via a similar fill pattern. This is the shape I wish to set my array to represent.

    Read the article

  • How do I write to command line from a WPF application?

    - by ben
    Hi I know how to write to console but if I write to console in my program and call my program from the command line it won't display anything. How do I make it so that when I say Console.WriteLine or Console.Out.Writeline ir prints to the command prompt from which it was called and not somewhere else? Once again I know how to do Console.WriteLine so it's not that :-p unless I'm doing it wrong. From what I can tell it's probably something to do with Console.SetOut(TextWriter t) this is a WPF application and I need it to post its data to the command line while still retaining the GUI at startup. I've triple checked and my code hits the print lines, I can actually see the lines being printed to the Visual Studio output window, it just won't display in the command line when I run it manually without VS. If possible I need to conditionally have the console display. ie if run from command line (or even with command arguments), display or post to the prompt, otherwise do not.

    Read the article

  • join same rails models twice, eg people has_many clubs through membership AND people has_many clubs through committee

    - by Ben
    Models: * Person * Club Relationships * Membership * Committee People should be able to join a club (Membership) People should be able to be on the board of a club (Committee) For my application these involve vastly different features, so I would prefer not to use a flag to set (is_board_member) or similar. I find myself wanting to write: People has_many :clubs :through = :membership # :as = :member? :foreign_key = :member_id? has_many :clubs :through = :committee # as (above) but I'm not really sure how to stitch this together

    Read the article

  • Rails nested association issue

    - by Ben Langfeld
    Ok, so I'm new to both Ruby and Rails and I'm trying to do what I believe is called a nested association (please correct me if this is the wrong terminology). I currently have a User model and a Domains model and I have many to many associations setup (using has_many :through) between the two, and this works fine. I now want to extend this to allow for a single role per domain per user (eg User1 is a member of Domain1 and has the role "Admin"). I have setup a Roles model with a single field (name:string) and have created three roles. I have also added a role_id column to the join table (memberships). I expected (and this is probably the issue) to be able to just use user1 = User.find(1) user1.domains.first => <some domain object> user1.domains.first.role => <some role object> but this returns a method not defined error. Can anyone tell me what I'm failing to grasp here? My model classes can be seen at http://gist.github.com/388200

    Read the article

  • How do I setup a shared session between two users on my Ruby on Rails powered site?

    - by ben
    Hey guys, The website that I'm building includes a section where two users can interact. I think I know how to do most of it, except the actual session sharing part. I'm using Ruby on Rails & Javascript (jquery), and I've got user login and session management all working okay. Would the best way to create a shared session be to have a SharedSession model, with accompanying database table, with participant1ID, participant2ID etc? Is there a better way? Thanks so much for reading!

    Read the article

  • Building a document server

    - by Ben
    Hey, I'm just looking for some rough guidance here on the feasibility of a project. I have say a few thousand text documents and I want to create a web based system to serve them up to users in a OS X application. It's just a tiny aside for my family's small business, so it doesn't need to be amazing at the moment, we just want to see if we can can anyone to use it. I can't believe it can be that hard to do this? -Some sort of SQL backend database to manage permissions for users? -Download through the application? -For the moment just want to view the raw text files. -If we want people to pay, how would we go about incorporating that? Sorry for the vague outline. I'm still not 100% sure on what we want. Thanks for any help.

    Read the article

  • Ruby 1.8.7 and RSPEC tutorial

    - by Ben Nelson
    I'm just diving into ruby development for a class assignment and the machines at my Uni have only got ruby 1.8.7 on them so I need to develop for that. I have found tutorials on the web for ruby = 1.9 and rspec that are really good but I haven't found anything for ruby 1.8.7 (I'm guessing it's pretty dated?). Does anyone have anything using rspec testing and has an indepth discussion on ruby 1.8.7 for me? I'd really appreciate it! Thanks!

    Read the article

  • Does the iPhone 3G/3Gs camera put metadata in its images? (and how do you get it?)

    - by Ben Collins
    I've been trying to figure how whether the iPhone (either 3G or 3Gs) camera puts metadata into it's images. Anecdotally, it appears that it does (e.g., I've seen images posted on the web that included a bunch of metadata), but I can't find reference to it anywhere in the SDK documentation. So....does anyone have a definitive answer? Also, if there is metadata, how do I get at it?

    Read the article

  • Summary statistics in visual basic

    - by ben
    Below I am trying to write a script the goal of which is to calculate some summary statistics for a few different columns of numbers. I have gotten some help on it up to the "Need help below" mark. But beyond that I am flabergasted as to how to calculate the simple stats (sum, mean, standard deviation, coefficient of variation). I know VB has scripts for these stats, which I have included in my code, but I guess I need to do some extra declaring or something. Advice much appreciated. Thanks. Sub TOAinput() Const n As Integer = 648 Dim stratum(n), hybrid(n), acres(n), hhsz(n), offinc(n) Dim s1 As Integer Dim s2 As Integer Dim i As Integer For i = 1 To n stratum(i) = Worksheets("hhid level").Cells(i + 1, 2).Value Next i s1 = 0 s2 = 0 For i = 1 To n If stratum(i) = 1 Then s1 = s1 + 1 Else: s2 = s2 + 1 End If Next i Dim acres1(), hhsz1(), offinc1(), acres2(), hhsz2(), offinc2() ReDim acres1(s1), hhsz1(s1), offinc1(s1), acres2(s2), hhsz2(s2), offinc2(s2) 'data infiles: acres, hh size, off-farm income, For i = 1 To n acres(i) = Worksheets("hhid level").Cells(i + 1, 4).Value hhsz(i) = Worksheets("hhid level").Cells(i + 1, 5).Value offinc(i) = Worksheets("hhid level").Cells(i + 1, 6).Value Next i s1 = 0 s2 = 0 For i = 1 To n If stratum(i) = 1 Then s1 = s1 + 1 acres1(s1) = acres(i) hhsz1(s1) = hhsz(i) offinc1(s1) = offinc(i) Else: s2 = s2 + 1 acres2(s2) = acres(i) hhsz2(s2) = hhsz(i) offinc2(s2) = offinc(i) End If Next i '**************************** 'Need help below '**************************** Dim sumac1, sumac2, mhhsz1, mhhsz2, cvhhsz1, cvhhsz2 sumac1 = Sum(acres1) sumac2 = Sum(acres2) mhhsz1 = Average(hhsz1) mhhsz2 = Average(hhsz2) cvhhsz1 = StDev(hhsz1) / Average(hhsz1) cvhhsz2 = StDev(hhsz2) / Average(hhsz2) End Sub

    Read the article

  • (UNITY3D) Get slerp to work just as LookAt(,Vector3.right) does

    - by Ben Rokah
    Ive been working over a sidescroller shooter game. Ive got my sidescroller shooter character to look around with these : chest.LookAt(mousepos,Vector3.right); & chest.LookAt(mousepos,Vector3.left); (Left when the character is turned to the left and right when the character is turned to the right) so it wont aim in to any other axis... But when the mouse gets to cross the middle of the character and not around it it gets the rotation to make a small transportation between frames and it wont get all the way to there.. It'll just teleport to its correct rotation like lookat should. Well the question is, how do I get any quaternion slerp which works with a Time.deltTime to work as same as LookAt(,Vector3.right)? I must have the Vector3.right and left so it'll move trough 1 axis. Many thanks to anyone who helps me out. :)

    Read the article

  • C++ Function Calling Itself

    - by Ben
    Suppose I wish to have a function that fills an array either in pattern x,y,x,y,x,ywhere x and y are variables defined by some algorithm and x,y,z,x,y,z where x, y and z are variables defined by the same algorithm. This should continue for all number of variables. Is this a viable way to implement it. int recurse_n(int n) { while(n > 0) { --n; recurse_n(n); n = 0; // Use algorithm here } }

    Read the article

  • read the dictionary value from array

    - by ben martin
    CALORIES = \ { 'Beef' : 200, \ 'Chicken' : 140, \ } class Food(): __slots__ = ( 'cal' # Calories ) def mkFood( name ): """Create and return a newly initialized Food item""" result = Food() result.cal = calorie in dict(CALORIES[1]) return result Is that a proper way to the value of the target item in Calories? Like getting 200, 140, such like that. result.cal = calorie in dict(CALORIES[1])

    Read the article

  • Can I get.seed() somehow?

    - by a different ben
    In reference to the statement set.seed(), can I get the seed instead after running some code if I didn't set it explicitly? I've been re-running some code containing a function that randomises some sample of the input data (the function is part of the kohonen package). After playing with it for some time to see the variety of output (it was an 'unstable' problem), I noticed one result that was pretty interesting. I of course had not used set.seed(), but wondered if I could get the seed after running the code to reproduce the result? In ?set.seed I see .Random.seed saves the seed set for the uniform random-number generator But I don't know how that helps.

    Read the article

  • Opposite of .find()

    - by Ben
    Is there an opposite of .find()? Where $('.myclass').except('#myid'); Would grab all elements with .myclass except the element with #myid. I know I could do $('.myclass[id=myid]') in this example, but seems like it would be helpful in other cases. Thanks

    Read the article

  • [Bash] Save part of matching pattern to variable

    - by Ben
    I want to extract a substring matching a pattern and save it to a file. An example string: Apr 12 19:24:17 PC_NMG kernel: sd 11:0:0:0: [sdf] Attached SCSI removable disk I want to extract the part between the brackets, in this case []. I tried to do something like grep -e '[$subtext]' to save the text in the brackets to a variable. Of course it doesn't work, but I am looking for a way similar to this. It would be very elegant to include a variable in a regex like this. What can I do best? Thanks!

    Read the article

< Previous Page | 53 54 55 56 57 58 59 60 61 62 63 64  | Next Page >