Posts

python - How do you find which value occurs the most in a dictionary? -

in dictionary keys , list of values, how find value in lists of values frequently? i'm assuming use loops , append lists unsure of how so. want print value occurring frequently? thank you! please keep in mind i'm new programming , not familiar lambda or other complicated ways solve this. one way use collections.counter from collections import counter >>> d = {'a': 5, 'b': 3, 'c': 5, 'd': 1, 'e': 5} >>> c = counter(d.values()) >>> c [(5, 3), (1, 1), (3, 1)] >>> c.most_common()[0] (5, 3) # value, , number of appearances

symfony - Duplicate index on sqlite, not on mysql -

i have entity definition works on dev , production envs (mysql), not on test (sqlite): /** * invoice * * @orm\table(name="invoice", indexes={ * @orm\index(name="ref_idx", columns={"ref"}), * @orm\index(name="created_at_idx", columns={"created_at"}), * @orm\index(name="paid_idx", columns={"paid"}), * @orm\index(name="is_valid_idx", columns={"is_valid"}), * @orm\index(name="canceled_idx", columns={"canceled"}) * }) * @orm\entity(repositoryclass="appbundle\repository\invoicerepository") */ class invoice // [...] when run doctrine:schema:create or doctrine:schema:update --force on test env, have following error: [doctrine\dbal\dbalexception] exception occurred while executing 'create index created_at_idx on invoice (created_at)': sqlstate[hy000]: gener...

angularjs - $compile not compiling templates in Karma/Jasmine -

i have tested both phantomjs , chrome. following this question i'm trying access generated html code in unit tests karma: it('should something', inject(function ($rootscope, $templatecache, $compile) { var scope = $rootscope.$new(); scope.$digest(); var template = $templatecache.get('/app/views/mytemplate.html'); var compiler = $compile(template); var compiledtemplate = compiler(scope); console.log(compiledtemplate); })); what i've found template being fetched correctly, , corresponds raw html file on computer. compiledtemplate never compiled correctly; basically, angular removing ng-tagged divs , replacing them comments, regardless of values should be. for example, <ol ng-repeat = "foo in foos"> <li>foo</li> </ol> will replaced with: <!-- ngrepeat: foo in foos --> even if set scope.foos array in unit test. have tried adding waitsfor , settimeout methods force karma wait 8 seconds, , st...

php - symfony2 form, collection of objects, issue updating existing object property -

the form consists of 1 question has several answers, answers can dynamically created each question. stuff works fine: public function buildform(formbuilderinterface $builder, array $options) { $builder ->add('question','textarea') ->add('answers', 'collection', array( 'type'=>new answertype(), 'allow_add'=>true, 'allow_delete'=>true, 'label' => false )) ; } here form code answertype: $builder ->add('answer','text', array( 'attr'=>array( 'class'=>'form-control' ), 'label'=>false )) ->add('isgoodanswer', 'checkbox', array( 'label'=>'good?', 'required'=>false )) ; i using prototype template popula...

ruby on rails - How to tell if GIF is animated? -

i have rails app paperclip image uploads -- how check if image animated gif rmagick? you can count scenes associated image. in rmagick means doing this: image = magick::imagelist.new(image_file) if image.scene == 0 #this not animated gif else #this animated gif end

How to check if a non binary tree is a subtree of another -

Image
i'm working trees , need know how check if if non binary tree subtree of another. these trees have n nodes , n levels, , children's order not important. know if tree subtree of another the problem me how recursion , compare both tree @ same time recursion. for create exemple demonstrate want do. i know roots of both tree , i;m trying in ruby on rails, know justa want know pseudo code or logic. someone can me? thanks i try use ideas hash tree or merkle tree : a hash tree or merkle tree tree in every non-leaf node labelled hash of labels of children nodes. hash trees useful because allow efficient , secure verification of contents of large data structures. see hashing tree structure

404 in Chrome, not IE, using asp.net bundles -

the issue when bundles minified , @ network tab in chrome see 404 url : http://localhost:57000/bundles/underscore-min.map no such directory exists. if remove reference underscore.js in bundle 404 url : http://localhost:57000/bundles/angular-sanitize.min.js.map this doesn't happen in ie. i've moved order around , there 1 file, , one, generate 404. here's bundles generate issue. bundles.add(new scriptbundle("~/bundles/scripts") .include("~/scripts/angular/angular.js") .include("~/scripts/angular/angular-resource.js") .include("~/scripts/angular/angular-route.js") .include("~/scripts/angular/angular-animate.js") .include("~/scripts/angular/angular-touch.js") .include("~/scripts/angular/angular-sanitize.js") ...