Search Results

Search found 968 results on 39 pages for 'lambda'.

Page 24/39 | < Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >

  • django sort by manytomany relationship

    - by Marconi
    I have the following model: class Service(models.Model): ratings = models.ManyToManyField(User) Now if I wanna get all the service with ratings sorted in descending order I did something: services_list = Service.objects.filter(ratings__gt=0).distinct() services_list = list(services_list) services_list.sort(key=lambda service: service.ratings.all().count(), reverse=True) As you can see its a three step process and I don't feel right about this. Anybody who knows a better way to do this?

    Read the article

  • Trouble using South with Django and Heroku

    - by Dan
    I had an existing Django project that I've just added South to. I ran syncdb locally. I ran manage.py schemamigration app_name locally I ran manage.py migrate app_name --fake locally I commit and pushed to heroku master I ran syncdb on heroku I ran manage.py schemamigration app_name on heroku I ran manage.py migrate app_name on heroku I then receive this: $ heroku run python notecard/manage.py migrate notecards Running python notecard/manage.py migrate notecards attached to terminal... up, run.1 Running migrations for notecards: - Migrating forwards to 0005_initial. > notecards:0003_initial Traceback (most recent call last): File "notecard/manage.py", line 14, in <module> execute_manager(settings) File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/app/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/app/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/app/lib/python2.7/site-packages/south/management/commands/migrate.py", line 105, in handle ignore_ghosts = ignore_ghosts, File "/app/lib/python2.7/site-packages/south/migration/__init__.py", line 191, in migrate_app success = migrator.migrate_many(target, workplan, database) File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 221, in migrate_many result = migrator.__class__.migrate_many(migrator, target, migrations, database) File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 292, in migrate_many result = self.migrate(migration, database) File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 125, in migrate result = self.run(migration) File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 99, in run return self.run_migration(migration) File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration migration_function() File "/app/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda> return (lambda: direction(orm)) File "/app/notecard/notecards/migrations/0003_initial.py", line 15, in forwards ('user', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User'])), File "/app/lib/python2.7/site-packages/south/db/generic.py", line 226, in create_table ', '.join([col for col in columns if col]), File "/app/lib/python2.7/site-packages/south/db/generic.py", line 150, in execute cursor.execute(sql, params) File "/app/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute return self.cursor.execute(sql, params) File "/app/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute return self.cursor.execute(query, args) django.db.utils.DatabaseError: relation "notecards_semester" already exists I have 3 models. Section, Semester, and Notecards. I've added one field to the Notecards model and I cannot get it added on Heroku. Thank you.

    Read the article

  • Connecting slots and events in PyQt4 in a loop

    - by LukaD
    Im trying to build a calculator with PyQt4 and connecting the 'clicked()' signals from the buttons doesn't as expected. Im creating my buttons for the numbers inside a for loop where i try to connect them afterwards. def __init__(self): for i in range(0,10): self._numberButtons += [QPushButton(str(i), self)] self.connect(self._numberButtons[i], SIGNAL('clicked()'), lambda : self._number(i)) def _number(self, x): print(x) When I click on the buttons all of them print out '9'. Why is that so and how can i fix this?

    Read the article

  • why the class of subclass is superclass

    - by Raj
    def singleton_class class << self self end end end class Human proc = lambda { puts 'proc says my class is ' + self.name.to_s } singleton_class.instance_eval do define_method(:lab) do proc.call end end end class Developer < Human end Human.lab # class is Human Developer.lab # class is Human ; oops Why Developer.lab is reporting that it is Human ?

    Read the article

  • How can I improve the recursion capabilities of my ECMAScript implementation?

    - by ChaosPandion
    After some resent tests I have found my implementation cannot handle very much recursion. Although after I ran a few tests in Firefox I found that this may be more common than I originally thought. I believe the basic problem is that my implementation requires 3 calls to make a function call. The first call is made to a method named Call that makes sure the call is being made to a callable object and gets the value of any arguments that are references. The second call is made to a method named Call which is defined in the ICallable interface. This method creates the new execution context and builds the lambda expression if it has not been created. The final call is made to the lambda that the function object encapsulates. Clearly making a function call is quite heavy but I am sure that with a little bit of tweaking I can make recursion a viable tool when using this implementation. public static object Call(ExecutionContext context, object value, object[] args) { var func = Reference.GetValue(value) as ICallable; if (func == null) { throw new TypeException(); } if (args != null && args.Length > 0) { for (int i = 0; i < args.Length; i++) { args[i] = Reference.GetValue(args[i]); } } var reference = value as Reference; if (reference != null) { if (reference.IsProperty) { return func.Call(reference.Value, args); } else { return func.Call(((EnviromentRecord)reference.Value).ImplicitThisValue(), args); } } return func.Call(Undefined.Value, args); } public object Call(object thisObject, object[] arguments) { var lexicalEnviroment = Scope.NewDeclarativeEnviroment(); var variableEnviroment = Scope.NewDeclarativeEnviroment(); var thisBinding = thisObject ?? Engine.GlobalEnviroment.GlobalObject; var newContext = new ExecutionContext(Engine, lexicalEnviroment, variableEnviroment, thisBinding); Engine.EnterContext(newContext); var result = Function.Value(newContext, arguments); Engine.LeaveContext(); return result; }

    Read the article

  • Should I invest time in learning Java language these days? (question from a greenhorn)

    - by dave-keiture
    Hi experts, Assuming you've already had a chance to look through the lambda syntax proposed for Java7 (and the other things that have happened with Java, after Oracle has bought Sun + obvious problems in Java Community Process), what do you think is the future of Java language? Should I, as a Java greenhorn, invest time in learning Java language (not talking about the core JVM, which definitely will survive anything, and worth investments), or concentrate on Scala, Groovy, or other hybrid languages on the JVM platform (I've came into Java world from PHP/Ruby). Thanks in advance.

    Read the article

  • Rails: three most recent records by unique belongs_to associated record

    - by Dennis Collective
    class User has_many :comments end class Comment belongs_to :user named_scope :recent, :order => 'comments.created_at DESC' named_scope :limit, lambda { |limit| {:limit => limit}} named_scope :by_unique_users end what would I put in the :by_unique_users so that I can do Comment.recent.by_unique_users.limit(3), and only get one comment per user on sqlite named_scope :by_unique_user, :group = "user_id" works, but makes it freak out on postgres, which is deployed on production PGError: ERROR: column "comments.id" must appear in the GROUP BY clause or be used in an aggregate function

    Read the article

  • Race condition for thread startup

    - by Ozzah
    A similar question was asked here, but the answers generally all seem to relate to the lambda notation. I get a similar result without the lambda so I thought I'd ask for some clarification: Say I have something like this: for (int i = 0; i < 5; i++) (new Thread(new ThreadStart(delegate() { Console.WriteLine("Thread " + i); }))).Start(); One would expect the following output: Thread 0 Thread 1 Thread 2 Thread 3 Thread 4 Now I realise that the threads aren't started in any particular order, so let's just assume that the above lines can come out in any order. But that is not what happens. What instead happens: Thread 3 Thread 4 Thread 4 Thread 4 Thread 4 or something similar, which leads me to believe that rather than passing the value if i, it is passing the reference. (Which is weird, since an int is a value type). Doing something like this: for (int i = 0; i < 5; i++) (new Thread(new ThreadStart(delegate() { int j = i; Console.WriteLine("Thread " + j); }))).Start(); does not help either, even though we have made a copy of i. I am assuming the reason is that it hasn't made a copy of i in time. Doing something like this: for (int i = 0; i < 5; i++) { (new Thread(new ThreadStart(delegate() { Console.WriteLine("Thread " + i); }))).Start(); Thread.Sleep(50); } seems to fix the problem, however it is extremely undesirable as we're wasting 50ms on each iteration, not to mention the fact that if the computer is heavily loaded then maybe 50ms may not be enough. Here is a sample with my current, specific problem: Thread t = new Thread(new ThreadStart(delgate() { threadLogic(param1, param2, param3, param4); })); t.Start(); param1 = param2 = param3 = param4 = null; with: void threadLogic(object param1, object param2, object param3, object param4) { // Do some stuff here... } I want threadLogic() to run in its own thread, however the above code gives a null reference exception. I assume this is because the values are set to null before the thread has had a chance to start. Again, putting a Thread.Sleep(100) works, but it is an awful solution from every aspect. What do you guys recommend for this particular type of race condition?

    Read the article

  • Approaching Java from a Ruby perspective

    - by Travis
    There are plenty of resources available to a Java developer for getting a jump-start into Ruby/Rails development. The reverse doesn't appear to be true. What resources would you suggest for getting up-to-date on the current state of java technologies? How about learning how to approach DRY (don't repeat yourself) without the use of metaprogramming? Or how to approach various scenarios where a ruby developer is used to passing in a function (proc/lambda/block) as an argument (callbacks, etc)?

    Read the article

  • Free JVM profilers for websites

    - by 2Real
    I'm looking for a JVM profiler (preferably open source) so I can look at the heap and cpu usage of my personal website. I've used Lambda Probe, and I like it because it provides a web interface for my remote Unix computer that has no display. I was wondering what else is available Thanks,

    Read the article

  • Passing arguments to scope_procedure in searchlogic

    - by Greg
    I'd like to use searchlogic's scope_procedure feature like so class MyModelObject < ActiveRecord::Base scope_procedure :my_scope_proc, lambda { |p1, p2| { :conditions => "p1 >= #{p1} AND p2 < #{p2}" }} end Then, I am doing the search: scope = MyModelObject.search(:my_scope_proc => true) scope.all The above code obviously doesn't work because I didn't pass p1 and p2 parameters to my named scope. I can't figure out how to pass parameters to the named scope.

    Read the article

  • small & readable scheme interpreter in C++ ?

    - by anon
    Anyone know of a good / small scheme interpreter in C++? Perferably something < 2000 LOC, with a simple garbage collectro (either compacting or mark & sweep), no need to support all of R5RS, just basics of if/lambda/set!/cons/car/cdr and some basic operations. Thanks!

    Read the article

  • Any PHP MVC framework planning to use 5.3 features?

    - by alexandrul
    I would like to get started with PHP, and 5.3 release seems to bring many nice features (namespaces, lambda functions, and many others). I have found some MVC frameworks, and some of them support only PHP 5: PHP Frameworks PHP MVC Frameworks Model–view–controller on Wikipedia but can anyone recommend one of those MVC frameworks that plans to actively use PHP 5.3 features, not just being compatible with PHP 5.3? Update Results so far: Zend Framework 2.0 (in development) Lithium (in development, based on CakePHP) Symfony (in development) FLOW3 (in development, alpha)

    Read the article

  • Dealing with &rest-parameters in common lisp

    - by Patrick
    I want define a functions that accepts &rest - parameters and delegates them to another function. (html "blah" "foo" baz) = "blahfoobaz" I did not find a better way than this one: (defun html (&rest values) (concatenate 'string "" (reduce #'(lambda(a b) (concatenate 'string a b)) values :initial-value "") "")) But this looks somewhat glumbsy to me, since line 4 does no more than concatenating the &rest parameter "values". I tried (concatenate 'string "" (values-list values) "") but this does not seem to work (SBCL). Could someone give me an advice? Kind regards

    Read the article

  • Are incremental Macro definition possible?

    - by Davorak
    I often find the following type of incremental definition useful: (define (foo) (display "bar")) (foo) ;prints bar (define foo (let ((bar foo)) (lambda () (display "foo") (bar)))) (foo) ;prints foobar How do I preform this type of incremental definition with macros? I could not get let-syntax to provide the same functionality. Currently I use plt scheme, but would like to see answers in different lisp implementations as well.

    Read the article

  • Translate SQL statement into named_scope?

    - by keruilin
    How can I translate this SQL into a named_scope? Also, I want the total comments param to be passed through a lambda. "select users., count() as total_comments from users, comments where (users.id = comments.user_id) and (comments.public_comment = 1) and (comments.aasm_state = 'posted') and (comments.forum_user_id is null) group by users.id having total_comments 25"

    Read the article

  • Python shortcuts

    - by lyrae
    Python is filled with little neat shortcuts. For example: self.data = map(lambda x: list(x), data) and (although not so pretty) tuple(t[0] for t in self.result if t[0] != 'mysql' and t[0] != 'information_schema') among countless others. In the irc channel, they said "too many to know them all". I think we should list some here, as i love using these shortcuts to shorten & refctor my code. I'm sure this would benefit many.

    Read the article

  • how to made a "admin-only" for in html page (not view.py),has this method :user.is_superuser ??

    - by zjm1126
    in views.py: @user_passes_test(lambda u: u.is_superuser) def h_view(request): return render_to_response('mytest/news.html',context_instance=RequestContext(request)) but i want to show this page when admin login,and my now page is : <li id="tab_mytest"><a href="{% url mytest_list %}" class="{% block mytest_css_name %}{% endblock %}">{% trans "mytest" %}</a></li> how to change it, has this method :user.is_superuser ?? thanks

    Read the article

  • Can I add Boost source+header files to my own (Open Source) project?

    - by rubenvb
    Is it allowed by the Boost License to just add the source code of the stuff I need to my project (accompanied by the license of course?). I couldn't find any "descriptive" confirmation. I would have seperate Include/boost and Source/boost directories for easy access. PS: Seeing as boost::filesystem is going into C++0x TR2, and lambda's are already in c++0x TR1, I don't see any reason to be juggling with C functions like realpath, getcwd and the like. They don't work well anyways...

    Read the article

  • Good advanced book on developing robust C# modules

    - by AlexKuznetsov
    I have some experience with C#, and would like to improve my knowledge of its latest improvements. I am in the middle of reading and enjoying "Effective C#" by Bill Wagner right now. However, I would appreciate more examples, especially with lambda expressions and such. Any suggestions are greatly appreciated. High quality resources are preferable, and it does not matter much if they are free or not.

    Read the article

  • Is incremental Macro definition possible?

    - by Davorak
    I often find the following type of incremental definition useful: (define (foo) (display "bar")) (foo) ;prints bar (define foo (let ((bar foo)) (lambda () (display "foo") (bar)))) (foo) ;prints foobar How do I preform this type of incremental definition with macros? I could not get let-syntax to provide the same functionality. Currently I use plt scheme, but would like to see answers in different lisp implementations as well.

    Read the article

  • Is there an existing delegate in the .NET Framework for comparison?

    - by Neil Barnwell
    The .NET framework provides a few handy general-use delegates for common tasks, such as Predicate<T> and EventHandler<T>. Is there a built-in delegate for the equivalent of CompareTo()? The signature might be something like this: delegate int Comparison<T>(T x, T y); This is to implement sorting in such a way that I can provide a lambda expression for the actual sort routine (ListView.ListViewItemSorter, specifically), so any other approaches welcome.

    Read the article

  • new JDK 7 features

    - by xdevel2000
    I wish to test the new features that will came with the next JDK like project coin, project lambda etc. but the last JDK 7 to download will not have any already implemented! From which build can I test them? I think it's incredible that, now in may 2010 at few months to the official final release (november 2010????) for we developers there is no possibility to test any of this features!!

    Read the article

< Previous Page | 20 21 22 23 24 25 26 27 28 29 30 31  | Next Page >