Posts

Adding Command Line Arguments to Python Twisted -

i still new python keep in mind when reading this. i have been hacking away @ existing python script "put" few different people. the script designed load it's 'configuration' using module named "conf/config.py" python code. setting_name='setting value' i've modified instead read it's settings configuration file using configparser: import configparser config_file_parser = configparser.configparser() config_file_name = "/etc/service_settings.conf" config_file_parser.readfp(open(r'' + config_file_name)) setting_name = config_file_parser.get('basic', 'setting_name') the problem having how specify configuration file use. have managed working (somewhat) having multiple tac files , setting "config_file_name" variable there using module hold variable value. example, have module 'conf/configloader.py": global config_file_name then tac file has: import conf.configloader ...

javascript - What is the Best way to assign attributes by their index -

i have wrapper has children need specific positions. let's have markup so: <div class="wrapper"> <div class="slider" data-position=""></div> <div class="slider" data-position=""></div> <div class="slider" data-position=""></div> </div> the last child should have position of infront, second last child should have position of behind , every other slider should have position of limbo. demo: http://jsfiddle.net/l5lpp/1/ i'm not fan of massive chain of if , else statements.... is there better more elegant way achieve this? try this: var sliders = $("div.slider").data("position", "limbo"); sliders.last().data("position", "infront"); sliders.eq(-2).data("position", "behind"); edit: using classes: var sliders = $("div.slider").removeclass("l...

Rails encoded url query plus sign not properly decoded -

raw email abc+2@gmail.com for haml file, have javascripts this $('#search_email').on('click', function(e){ var val = encodeuricomponent($('#search_email').val()); window.location.search = 'email='+val; }); in query url, shows correctly as url?email=abc%2b2%40gmail.com however, controller, when use debugger monitor, shows only params[:email] = "abc 2@gmail.com" does know happens, why rails decodes directly , in wrong way. thanks.

python - Re-Parsing JSON -

i have tweet data need parse: "{u'contributors': none, u'truncated': false, u'text': u'', u'in_reply_to_status_id': none, u'id': 325495490122772480l, u'favorite_count': 0, u'source': u'<a href=""http://itunes.apple.com/us/app/imdb-movies-tv/id342792525?mt=8&uo=4"" rel=""nofollow"">imdb movies & tv on ios</a>', u'retweeted': false, u'coordinates': none, u'entities': {u'symbols': [], u'user_mentions': [{u'indices': [56, 68], u'id_str': u'244186942', u'screen_name': u'ploughman71', u'name': u'paul hughes', u'id': 244186942}], u'hashtags': [{u'indices': [50, 55], u'text': u'imdb'}], u'urls': [{u'url': u'...', u'indices': [27, 49], u'expanded_url': u'...', u'display...

Multiple forms in a single page using flask and WTForms -

i have multiple form on same page send post request same handler in flask. i generating forms using wtforms. what best way identify form submitted ? i using action="?form=oneform" . think there should better method achieve same? i've been using combination of 2 flask snippets. the first adds prefix form , check prefix validate_on_submit(). i use louis roché's template determine buttons pushed in form . to quote dan jacob: example: form1 = forma(prefix="form1") form2 = formb(prefix="form2") form3 = formc(prefix="form3") then, add hidden field (or check submit field): if form1.validate_on_submit() , form1.submit.data: to quote louis roché's: i have in template : <input type="submit" name="btn" value="save"> <input type="submit" name="btn" value="cancel"> and figure out button passed server side have in views.py file: if reque...

design patterns - Javascript: How can two self executing function access each other -

i javascript self executing anonymous function is: (function(){ console.log('hello world!'); })(); and can pass in parameters: (function(window){ window.location(...); })(window); but if have 2 self executing anonymous functions, can each 1 access other? specifically, how can first function call method second, passing variable? (function(){ function foo () { return 'foo'; } // how can call "bar('my name is')" })(); (function(){ function bar (str) { return str + ' bar' ; } })(); thanks listening. they can't , that's kinda point. wrapping code this, inaccessible outside. if don't care such accessibility protections other things is: function foo() { bar() } // call bar foo(); // execute function bar() { // stuff } bar(); // execute

Is it OK to use `git push` to restore a remote repository? -

suppose have lost remote repository, because accidentally typed following command. rm -rf ourrepo.git in order restore it, plan use 1 of top-voted answers earlier question. however, observed none of solutions mentions following three-step strategy. use git init --bare recreate remote repository. set new remote git remote add origin <new repository url> . use git push origin master 1 of machines has up-to-date copy of repo i have tried on toy respository , appears work, 1 of colleagues claims there problem without being able pinpoint why. can either confirm or deny whether reasonable way restore lost remote? no, there shouldn't wrong proposed strategy, , in fact typical way restore remote repository (though not way). don't forget push tags along branches: git push origin --tags --all that command push branches under .git/refs/heads/ , tags under .git/refs/tags/ . if don't want push of branches, name each branch want push instead ...