Open Side Menu Go to the Top

02-21-2016 , 12:41 AM
Quote:
Originally Posted by gaming_mouse
@ChrisV,
Does angular offer its routing as a separate tiny module, or do you have to bring in all of angular? Because if he only needs simple routing, he should just use a small routing library -- there are a ton of them.
Nah you need angular core.

Probably best to use a small routing library.
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread
02-21-2016 , 01:19 AM
Quote:
Originally Posted by RustyBrooks
I wrote my first programs with pencil and paper and typed them into a computer when I had access to it. Can you imagine?
I don't have to. That's how I started, and that was in 2011 or so. Imagine that!
Programming homework and newbie help thread Quote
02-21-2016 , 01:24 AM
Weird. I haven't been more than 3 steps from a computer since at least 2006. I have 3 computers in my garage, and that's not even a joke.
Programming homework and newbie help thread Quote
02-21-2016 , 12:58 PM
Lots of good advice. Thanks all! Definitely getting stressed out trying to big picture all at once instead of doing a component at a time. Like I said, just never really occurred to me that was an option.

Quote:
Originally Posted by gaming_mouse
This is good advice, and depending on what's acceptable for your class, you might be able to keep pretending -- that is, just use one of the new parse alternatives or firebase for you backend.
This is a good point. If the front end is pretty functional, it may not ultimately matter if the backend works. I'd much prefer to have designed and implemented the whole thing, but for the purposes of this class it likely doesn't matter.

For something that seems as simple as uploading and organizing documents, I have a hard time thinking I shouldn't be able to do the whole thing in three or four months, particularly if I keep up with my average of about 20 hours a week dedicated to this once class. (Maybe better focus and less hours would help?)
Programming homework and newbie help thread Quote
02-21-2016 , 04:19 PM
My brain is overloading from all the framework names I've read in the last 30 posts.

To that extent, I kind of get where "wow, learning programming is hard these days" is coming from.
Programming homework and newbie help thread Quote
02-21-2016 , 04:37 PM
Quote:
Originally Posted by goofyballer
My brain is overloading from all the framework names I've read in the last 30 posts.

To that extent, I kind of get where "wow, learning programming is hard these days" is coming from.
There are lots of good jokes about how ridiculous javascript frameworks have gotten. See IAmDeveloper twitter for examples

https://twitter.com/iamdevloper?ref_...Ctwgr%5Eauthor
Programming homework and newbie help thread Quote
02-21-2016 , 04:45 PM
Quote:
Just when you think you’ve removed McAfee AntiVirus from a relative’s PC, you realise you still have 7 more Horcruxes left to destroy.
omg thank you for this

Last edited by Loki; 02-21-2016 at 04:46 PM. Reason: Also I may make a callback hell framework called Horcrux
Programming homework and newbie help thread Quote
02-24-2016 , 03:08 PM
just playing around with paperclip in rails, wrote a small app to test the upload functionality of storing documents in the db. Seemed like nothing worked, and indeed running rails console and checking each document object sure made it seem like nothing worked. But after I swapped back to the master branch and deleted the branch I made for testing, it said something had changed in a folder i'd never looked in before: system > documents

I go there and check, and like 5 folders deep is the document i was trying to save to the database all along. Not sure what to think about that.
Programming homework and newbie help thread Quote
02-29-2016 , 08:32 AM
Hey guys, so I got a simple exercise:

Check if the integer values of a,b and c can give you a orthogonal triangle and give the complexity of the Algorithm.

So it's simple I have to check if a˛+b˛ = c˛ a˛+c˛ =b˛ and b˛+c˛ =a˛

now in this case the complexity is simply O(n) , but if I add more variables I quickly see that the complexity is (n*(n-1)/2) * (n-2).

So subquestions:

With the Big O notation I can make this as O(nł) right? I only have to look for the biggest growing part and can leave out all constants?
Is my example then growing as O(n) or O(nł) ? As you can see I can plug it in (3*(3-1)/2) * (3-2) = 3

Obious rule is that n>=3
Programming homework and newbie help thread Quote
02-29-2016 , 10:00 AM
What is "n" in this case? That is, what is the number that can potentially increase in your algorithm? As far as I can see you're always just given 3 numbers? Or do they want to give you N numbers and have you tell them if any subset of them can make a right triangle, or what?
Programming homework and newbie help thread Quote
02-29-2016 , 10:39 AM
Yes I'm only given 3 numbers, but when looking for a bigger input of variables I saw that it basically includes the gaussian sumformula(pretty reoccuring in the lectures), which made me unsure if it should be O(n) or O(nł).

But it does not say anything about it in the exercise, I just figured that I might have to think further in this case.

Anyways, am I right that I can leave out all constants in my formula and make it O(nł)?
Programming homework and newbie help thread Quote
02-29-2016 , 10:48 AM
As far as I can tell, it's O(1). There's no increasing value in your formula. I don't know what you mean by "bigger input of variables"
Programming homework and newbie help thread Quote
02-29-2016 , 10:52 AM
When instead of a,b,c you have a,b,c,d,e ... so you add more variables but still try to look for possible orthogonal triangles.

I see I didn't even think about it being O(1) ...
Programming homework and newbie help thread Quote
02-29-2016 , 10:57 AM
Quote:
Originally Posted by NiSash1337
When instead of a,b,c you have a,b,c,d,e ... so you add more variables but still try to look for possible orthogonal triangles.

So you write O(1) rather than O(n)?
Is there any indication that this is something your algorithm is supposed to do? Are you supposed to write it to support N variables?

If no, then it's a constant time algorithm - O(1)

If it's supposed to look for possible right triangles among N variables, then you need to gather all possible 3-tuples, which is N choose 3, also often written is C(N, 3).

C(N, K) = n! / (k! * (n-k)!)
C(N, 3) = n! / (3! * (n-3)!)
So,
C(N, 3) = n*(n-1)*(n-2) / 6
which clearly gives the complexity as O(n^3) as you noted,

This is the worst case complexity - there might be a more efficient way that is not immediately obvious.
Programming homework and newbie help thread Quote
02-29-2016 , 11:21 AM
No there was no indication for that, I just quickly saw that it is very similar to the gaussian sumformula (n*(n+1))/2 which I have seen countless times in my studies so far.

So I probably interpreted too much into it. But as far as your formula goes I'm not sure if I follow.

For n = 3

we have ab = c ac = b and bc=a --> 3 but you got 1

for n = 4

we got a,b,c,d :

ab = c,d
ac = b,d b,c = a,d
ad = b,c b,d = a,c c,d =a,b

Which is 6*2 = 12 where your formula gives 4
Programming homework and newbie help thread Quote
02-29-2016 , 11:25 AM
There's no point in trying all 3 combinations for a given tuple. The hypotenuse has to be the largest number.

If you sort your list of numbers first then you can arrange for this to always be in a specific place in the tuple.

Edit: but also, it doesn't matter 3*O(whatever) = O(whatever)

Multiplying by a constant doesn't change the big-O time of your algorithm.
Programming homework and newbie help thread Quote
02-29-2016 , 11:31 AM
Thank you that helped a lot.


Quote:
Edit: but also, it doesn't matter 3*O(whatever) = O(whatever)

Multiplying by a constant doesn't change the big-O time of your algorithm.
Yes I figured it didn't matter, just wanted to know where I made a mistake in my formula. Sorting it before hand didn't cross my mind which was interesting.
Programming homework and newbie help thread Quote
02-29-2016 , 12:00 PM
(n*(n+1))/2 doesn't matter in your thinking.

As a rule of thumb, you start increasing complexity when you are doing loops. In your case, you aren't doing loops, so it is, as noted above, constant time as presented.

Exchanging n for any number doesn't alter your complexity. Big O represent rate of change, so when you say "my algorithm has a complexity of n^2, you are saying that the expected computation, long term, is going to increase by a factor of n despite the size of my input, not "my algorithm slows down by the size of the input."
Programming homework and newbie help thread Quote
03-01-2016 , 12:45 PM
SQL 2 tables.

Q. How do I insert the date and what data type do I use for HIREDATE in the table below?


Code:
CREATE DATABASE emp;

USE emp;

CREATE TABLE dept_data
(
   DEPTNO int,
   DNAME varchar(50),
   LOC varchar(50),
   PRIMARY KEY (DEPTNO)
);


INSERT INTO dept_data ( DEPTNO, DNAME, LOC )
VALUES (10, 'ACCOUNTING', 'NEW YORK'), (20 ,'RESEARCH', 'DALLAS'),
(30, 'SALES', 'CHICAGO'), (40, 'OPERATIONS', 'BOSTON');


CREATE TABLE emp_data
(
  EMPNO int,
  ENAME varchar(50),
  JOB varchar(50),
  MGR int,
  HIREDATE ??
)
Programming homework and newbie help thread Quote
03-01-2016 , 01:12 PM
It depends somewhat on what database you're using. But there's usually a type called "date".

Inserting it will again depend somewhat on database. But there's usually a default date format, and inserting text that meets that format will usually convert to date just fine. For example, I have oracle configured to use a date format like "YYYY-MM-DD" and so I can do

insert into emp_data(empno, ename, job, mgr, hiredate)
values(1, 'Rusty', 'Clown', 0, '2016-01-01')
Programming homework and newbie help thread Quote
03-01-2016 , 01:34 PM
Cheers.
Programming homework and newbie help thread Quote
03-01-2016 , 03:33 PM
Hey guys. Have a homework assignment for my Operation Systems class, it has to do with process synchronization using semaphores.


Just before a swimming competition, all the participating swimmers S1, ..., Sn have a shower. The facility has only two showers and each shower shall only be occupied by one swimmer at a time.
Develop a solution that avoids busy-waiting, but uses semaphores to take care that at most two swimmers are taking a shower at the same time and that if two swimmers want to take a shower at the same time each of them chooses a shower that is not occupied.
To this aim, provide commented pseudocode for:
  • the initialization of shared variables and semaphores,
  • for an arbitrary swimmer Sn (the code for all swimmers shall be the same) that achieves the above co-ordination and contains among others a statement such as shower(1) to use shower 1.
Furthermore, note that semaphores alone will not be sufficient to solve the problem, but you also need some internal data structure to keep track of whether a shower is free or occupied (and you need to protect the access to this shared data structure).


The semaphore struct is as follows:
Code:
struct Semaphore {
  int count;
  queueType queue;

  init(int init_value){
    count = init_value;
    queue = empty;
  }

  wait(){
    count = count - 1;
    if(count < 0){
      //put this process in the semaphore's queue
      //block this process on OS level
    }
  }

  signal(){
    count = count + 1;
    if(count <= 0){
      //remove some process P from semaphore's queue
      //move process P to ready queue on OS level
    }
  }
}
And my first try at a solution looks like this:

Code:
Semaphore sem := sem.init(2);
boolean[] occupiedShower := { false, false }
runInParallel { S1 } ... { Sn }
Code:
Swimmer {
  run {
    sem.wait();
    if(occupiedShower[0])
      shower(1);
    else
      shower(0);
    sem.signal();
  }

  shower(int numOfShower){
    if(numOfShower == 1){
      occupiedShower[1] = true;
      //...thoroughly clean all body parts in the shower
      occupiedShower[1] = false;
    }
    else{
      occupiedShower[0] = true;
      //...thoroughly clean all body parts in another shower
      occupiedShower[0] = false;
  }
}
Now the obvious problem with this (I think) is that a Swimmer performs a check whether a shower is occupied ( if(occupiedShower[0]) ) and if it isn't then he occupies it. But two different swimmers might perform this check simultaneously, or at least before either one of them actually occupies the shower, and then we encounter a problem.

I think that the semaphore structure takes care so that there are never more than two swimmers trying to shower at the same time, because the 3rd and latter swimmers will enter the waiting queue instead of trying to shower. But when both showers are free and two swimmers want to shower at the same time, they might end up in the same shower.
The solution seems to be to make sure that if a swimmer checks whether a shower is free, he makes sure to occupy it before another swimmer can perform the same check of whether that shower is free. But how would you guys implement this?
Programming homework and newbie help thread Quote
03-01-2016 , 08:20 PM
This is the solution that I came up with
Code:
Initialization of shared variables and semaphores:
	Semaphore sem_condition.init(2);
	Semaphore sem_me.init(1);
	boolean[] occupiedShower = { false, false }
	//
	//sem_condition is responsible for condition synchronization, and only allows two swimmers 
	//  to enter the shower area at the same time. If more than two swimmers try to enter the showers at                
	//  the same time, only the first two can enter, others have to wait in line.
	//sem_me is responsible for mutual exclusion, to make sure that two swimmers in the shower area won't try 
        //  to occupy the same shower simultaneously.
	//occupiedShower knows whether the showers are occupied or not.
	
Swimmer code:
Swimmer {
	enterShowerArea {
		//Swimmer tries to enter shower area, waits if it's full.
		sem_condition.wait(); 
		
		//Swimmer tries to pick a shower, waits if another swimmer is picking a shower.
		sem_me.wait();  
		
		//Swimmer checks if first shower (shower 0) is occupied.
		if(occupiedShower[0]){  
			//If it is occupied, then swimmer occupies second shower (shower 1).
			occupyShower(1);
		}
		else {
			//If first shower isn't occupied, then swimmer occupies it.
			occupyShower(0);
		}
		
		//Swimmer signals that he has picked a shower,if another swimmer was waiting then now he can pick.
		sem_me.signal();
		
		//Swimmer signals that he has left the shower area, if another swimmer was waiting now he can enter.
		sem_condition.signal();
	}
	
	occupyShower(int showerNumber){
		occupiedShower[showerNumber] = true;
		//…Wash whole body thoroughly with soap before big swimming competition….
		occupiedShower[showerNumber] = false;
	}
}
It was simple/obvious enough, just using another semaphore for mutual exclusion. I knew it was pretty simple, just had a brief lapse of thought
Sorry about the big indentation
Programming homework and newbie help thread Quote
Programming homework and newbie help thread
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
Programming homework and newbie help thread

      
m