Open Side Menu Go to the Top

07-11-2014 , 10:36 PM
Anyone help me out. I'm trying to run this code in IDLE but it's not returning anything:

Code:
numberOfLoops = 0
numberOfApples = 2
while numberOfLoops < 10:
    numberOfApples *= 2
    numberOfApples += numberOfLoops
    numberOfLoops -= 1
print "Number of apples: " + str(numberOfApples)
All I get is >>> with nothing following it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
07-11-2014 , 10:47 PM
Quote:
Originally Posted by animas
Anyone help me out. I'm trying to run this code in IDLE but it's not returning anything:

Code:
numberOfLoops = 0
numberOfApples = 2
while numberOfLoops < 10:
    numberOfApples *= 2
    numberOfApples += numberOfLoops
    numberOfLoops -= 1
print "Number of apples: " + str(numberOfApples)
All I get is >>> with nothing following it.
Trace through what happens with numberOfLoops. Let me know when you finish.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-11-2014 , 10:53 PM
Good eye!

I guess this one of the problems were the answer is error lol. Thank you! I might try to tinker a bit and see if I can get it to run right.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 06:17 AM
While I was dusting off the algorithms I found this gem (they have one for all the standard sorts):


[x] awesome
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 10:27 AM
Is there a reliable way to do this?

My site has a main page which will have all the standard sign up, login, about, legal, etc...

The crux of the site is a single page app as myhost.com/feed

I want to redirect to myhost.com/feed if the user is signed in, unless they try to visit myhost.com from somewhere on the same domain. Seems like the ability to capture a referrer path is negated if they manually type in myhost.com from event myhost.com/feed.

Is it bad form to just basically disallow viewing of the splash page if logged in? I could have a link that has a no_redirect parameter or something within the feed, but largely I just want people to hit the feed immediately upon typing in our URL with a redirect. I suppose it's not too different from having a different layout for logged in people at the main URL (as many SPA do).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 12:10 PM
I think I have something I'm relatively happy with on this Python OO stuff. I pulled the common stuff out and put it and created a new module (it took me more than 5 minutes to successfully import the modules, thus it is way to ****ing hard).

Code:
class OrderQuery(Universal):
    def creation_time(self, from_date, to_date):
        self.query['CreateTimeFrom'] = from_date
        self.query['CreateTimeTo'] = to_date
        return self

    def include_final_value(self):
        self.query['IncludeFinalValue'] = True
        return self

    def modified_between_dates(self, from_date, to_date):
        self.query['ModTimeFrom'] = from_date
        self.query['ModTimeTo'] = to_date
        return self

    def by_day(self, days):
        if days <= 30:
            self.query['NumberOfDays'] = days
        return self

class Query(OrderQuery):
    KEYS = ['IncludeFinalValue',
            'NumberOfDays',
            'Order_status',
            'EntriesPerPage'
            'PageNumber',
            'ModTimeFrom',
            'ModTimeTo',
            'Pagination']

    def __init__(self, **kwargs):
        self.query = {}
        for k in kwargs:
            self.query = dict(zip(self.KEYS[k], value))
The chaining was a terrible idea. It was ugly, and for some reason, order seems to matter. Also discovered that multiple inheritance doesn't quite work the way I'd expect it to.

Since this would be abstracted away, using this strategy is better, IMO:

Code:
dd = Query()
dd.by_day(6)
dd.modified_between_dates('then', 'now')
dd.get_pagination(5, 4)
dd.include_final_value()
dd.sorting_order('Ascending')
dd.by_status('Active')
Thus:

Code:
print(dd.query)

{'Pagination': {'EntriesPerPage': 5, 'PageNumber': 4}, 
'ModTimeTo': 'now', 
'ModTimeFrom': 'then', 
'SortingOrder': 'Ascending', 
'NumberOfDays': 6, 
'IncludeFinalValue': True, 
'Order_status': 'Active'}
OO is pretty hard: I definitely see why people struggle to go from OO to FP.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 12:23 PM
Found an interesting quote:

During the 2008 United States Presidential Campaign, candidate Barack Obama was asked to perform an impromptu analysis when he visited Google. Chief executive Eric Schmidt jokingly asked him for “the most efficient way to sort a million 32-bit integers.” Obama had apparently been tipped off, because he quickly replied, “I think the bubble sort would be the wrong way to go.”[1]

[1]But if you get a question like this in an interview, I think a better answer is, “The fastest way to sort a million integers is to use whatever sort function is provided by the language I’m using. Its performance is good enough for the vast majority of applications, but if it turned out that my application was too slow, I would use a profiler to see where the time was being spent. If it looked like a faster sort algorithm would have a significant effect on performance, then I would look around for a good implementation of radix sort.”

Not sure what to think of this one. I was under the impression that radix had a slower amortized run-time than other sorts. Is the author saying this is the best trade-off between asymptotic and accuracy? Or is a "good" Radix implementation built on other algorithms?

Aside from the fact that this answer probably goes against the spirit of the question, which I guess would make you look obnoxious.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 01:02 PM
Quote:
Originally Posted by Nchabazam
Is it bad form to just basically disallow viewing of the splash page if logged in? I could have a link that has a no_redirect parameter or something within the feed, but largely I just want people to hit the feed immediately upon typing in our URL with a redirect. I suppose it's not too different from having a different layout for logged in people at the main URL (as many SPA do).
Let users sign out if they want to see the splash page imo. Maybe set up a route for /home or something that renders the splash page too. Otherwise I guess you have to play around with some short lived cookies to signal whether to redirect or not.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 01:36 PM
Quote:
Originally Posted by clowntable
While I was dusting off the algorithms I found this gem (they have one for all the standard sorts):


[x] awesome
lol, that is pretty cool. Im taking an algorithms class on coursera right now, and so I just literally learned all these
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 02:21 PM
Quote:
Originally Posted by daveT
Found an interesting quote:

During the 2008 United States Presidential Campaign, candidate Barack Obama was asked to perform an impromptu analysis when he visited Google. Chief executive Eric Schmidt jokingly asked him for “the most efficient way to sort a million 32-bit integers.” Obama had apparently been tipped off, because he quickly replied, “I think the bubble sort would be the wrong way to go.”[1]

[1]But if you get a question like this in an interview, I think a better answer is, “The fastest way to sort a million integers is to use whatever sort function is provided by the language I’m using. Its performance is good enough for the vast majority of applications, but if it turned out that my application was too slow, I would use a profiler to see where the time was being spent. If it looked like a faster sort algorithm would have a significant effect on performance, then I would look around for a good implementation of radix sort.”

Not sure what to think of this one. I was under the impression that radix had a slower amortized run-time than other sorts. Is the author saying this is the best trade-off between asymptotic and accuracy? Or is a "good" Radix implementation built on other algorithms?

Aside from the fact that this answer probably goes against the spirit of the question, which I guess would make you look obnoxious.
https://en.wikipedia.org/wiki/Radix_sort

After reading the wiki page, it looks like this can be a controversial claim. If I'm understanding correctly, a fastest approach would be a combination of radix and bucket, polished off with insertion sort as N gets small, which isn't surprising or unexpected, but still seems like there are memory issues and considerations of cores, etc.I guess the key here is that all of the numbers are 32-bit.

Using a trie + linked list combo mentioned at the end apparently speeds it up a bit more, assuming all the numbers are the same size (in binary?), but wouldn't the 0 bucket become prohibitively large at some point?

I'm guessing using a random-based algorithm would probably suck with large numbers.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 07:39 PM
So there's a very popular browser extension to Reddit called RES that has a functionality of "view all images" i.e. expands them all out inline so that you don't need to click on every single one. This is nice and all, but there's no option to make it fire by default on page load (you have to hit the "view all images" button over and over every time you load a page), and when I dug into that I found that the authors don't want to make it an option as they "don't want to waste Imgur's bandwidth" or something, which I find pretty ridiculous. So obviously I spent 10 minutes figuring it out by myself and hacking it into RES. Would making a Gist be a total ******* thing to do? Or should I just not bother?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 08:19 PM
Seems fine to me. They can make requests, but have no right to tell you how to use your own browser, or not to share code you've written on github.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 08:25 PM
Quote:
Originally Posted by Grue
So there's a very popular browser extension to Reddit called RES that has a functionality of "view all images" i.e. expands them all out inline so that you don't need to click on every single one. This is nice and all, but there's no option to make it fire by default on page load (you have to hit the "view all images" button over and over every time you load a page), and when I dug into that I found that the authors don't want to make it an option as they "don't want to waste Imgur's bandwidth" or something, which I find pretty ridiculous. So obviously I spent 10 minutes figuring it out by myself and hacking it into RES. Would making a Gist be a total ******* thing to do? Or should I just not bother?
Maybe if you're concerned imgur will shutdown the function...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 09:11 PM
My automated testing journey with protractor is getting intense. So much flakey behavior. But still hope that it will work reasonably well running 6-10 tests in parallel. I'm hoping to really go upriver with it next week.

My company is in a real quandry. We are splitting our monster AT6/Webl0gic (trust me you never want to let them know you're leaving - they will rape you to death with licensing fees) site into a bunch of smaller node apps and scala/play APIs that all run off shared libraries. One major section of the site is done and about 3 more to go. Of course then we still have to migrate all CMS content from AT.g and some day hopefully even get off 0racle. Baby steps.

We pay $27M licensing a year for Webl0gic/0racle. Getting off one doesn't help because they just jack up your licensing for the other. Synergy at its finest.

Anyway, we know this will never work without some kind of automated unit and/or integration testing to validate all of the apps any time we want to update the shared libraries. But the mountain we have to climb from a cultural, skill and technology POV is huge. We generally don't like to fund or put a lot of effort into anything that doesn't result in an immediate tangible change the business can see and quantify. Kicking the can down the road on stuff like refactoring and quality process improvements is the norm. I honestly don't know what's going to happen.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-13-2014 , 10:18 PM
Now I really want to know where you work. I'm in a dinosaur fortune 100 company and during a recent all hands the CTO said "we really need to look into this FOSS stuff, I've heard its pretty good, we currently spend $7m a year on software" and I thought that was a pretty big number..
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 12:03 AM
Man, I really wish there was some sort of study group for SICP. There are a bunch of algorithms in there, that look really interesting, but are just too complex for me to wrap my head around.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 12:08 AM
Slow down a bit, man. SICP is a nice follow-up after mastering the material in an intro course, but definitely not worth going through before learning about infinite loops.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 12:19 AM
Yea, you are right. I mean I was only into the second chapter before I got caught up. I ran across this problem that dealt with finding combinations of different coins that add up to a dollar.

Code:
(define (count-change amount)
  (cc amount 5))
(define (cc amount kinds-of-coins)
  (cond ((= amount 0) 1)
        ((or (< amount 0) (= kinds-of-coins 0)) 0)
        (else (+ (cc amount
                     (- kinds-of-coins 1))
                 (cc (- amount
                        (first-denomination kinds-of-coins))
                     kinds-of-coins)))))
(define (first-denomination kinds-of-coins)
  (cond ((= kinds-of-coins 1) 1)
        ((= kinds-of-coins 2) 5)
        ((= kinds-of-coins 3) 10)
        ((= kinds-of-coins 4) 25)
        ((= kinds-of-coins 5) 50)))
I'm the type of person who orders one of everything when I'm at a restaurant and am real hungry. Forgive my eagerness, but that problem just seems so cool.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 12:43 AM
I'm pretty sure that is upside-down, but regardless, if you want to see how cool it is, try it for $1,000,000 and let me know when it finishes.

Last edited by daveT; 07-14-2014 at 12:44 AM. Reason: couldn't help myself, sorry.. don't do that.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 11:00 AM
Quote:
Originally Posted by jjshabado
pretty lol the economist is throwing up URLS with drupal default naming
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 03:02 PM
My head feels like it's going to explode when I try to read explanations and fixes for the "non-static method cannot be referenced from a static context" error in Java/greenfoot

And NO, that is NOT an invitation to make it worse
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-14-2014 , 08:53 PM
Quote:
Originally Posted by Low Key
My head feels like it's going to explode when I try to read explanations and fixes for the "non-static method cannot be referenced from a static context" error in Java/greenfoot

And NO, that is NOT an invitation to make it worse
Hmmm.... Python may be a better language to focus on for you based on the above statement. I'm guessing that the concept of static is not being fully grasped. That is ok and understandable because as a completely abstract concept it actually is hard to grasp in my view.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-15-2014 , 12:22 AM
Quote:
Originally Posted by Low Key
My head feels like it's going to explode when I try to read explanations and fixes for the "non-static method cannot be referenced from a static context" error in Java/greenfoot

And NO, that is NOT an invitation to make it worse
'you need a "this", dawg'
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-15-2014 , 08:38 AM
Quote:
Originally Posted by adios
Hmmm.... Python may be a better language to focus on for you based on the above statement. I'm guessing that the concept of static is not being fully grasped. That is ok and understandable because as a completely abstract concept it actually is hard to grasp in my view.
It's not that I'm not grasping it so much as we haven't even talked about it at all in classes, readings, or videos.

I had the same problem in learning French: I'd always try to make complex sentences that we hadn't learn how to do yet.

I just wish I could figure out about how far in i'd have to go to learn this stuff.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-15-2014 , 09:56 AM
If you have a class called MySuperClass static methods are called via the class directly and not from objects.

MySuperClass.staticMethod(); // static, no object, called directly on the class
vs.
MySuperClass x = new MySuperClass();
x.anotherMethod(); // nonstatic, object x needed to call

Or in other words...you need an object to call a non-static method.

Usually happens if you try something like
myMethod();
in the main part of the code and myMethod is not a static method. So if your class is MySuperClass and you have a method wtfWorkYouDumbMethod() and
Code:
// MySuperClass.java
...
public static void main(String[] args) {
...
wtfWorkYouDumbMethod(); // this causes the error
}
...
what you want is
Code:
// MySuperClass.java
...
public static void main(String[] args) {
...
MySuperClass hahaha = new MySuperClass();
hahaha.wtfWorkYouDumbMethod();
}
...

Last edited by clowntable; 07-15-2014 at 10:02 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m