Posts

apache - Python 3.4 causes UnicodeEncodeError on Apache2 server (Mac) but works fine in command line -

i'm trying python 3.4 cgi script , apache output 'ü' character in browser (same problem occurs other unicode character, matter). python 3.4 cgi script causes unicodeencodeerror in apache while similar python 2.7 code works fine on same server. both scripts 3.4 , 2.7 work fine command line. this error while running python 3.4 script: unicodeencodeerror: 'ascii' codec can't encode character '\xfc' in position 23: ordinal not in range(128) here's code causes error: #!/usr/local/bin/python3 # -*- coding: utf-8 -*- print ("content-type: text/html; charset=utf-8\n\n") print ("""\ <html> <head> <meta charset="utf-8"> </head> <body> """) print ("u umlaut (python 3.4): ü<br>") print ("""\ </body> </html> """) the python 2.7 script below on same server displays ü , other unicode characters correctly: (so it...

Ansible get the username from the command line -

in playbooks reference username (exclusively "ubuntu") lot. is there built in way "get value passed in command line"? i know can do ansible-playbook <task> -u <user> -k --extra-vars "user=<user>" and can use {{user}} in playbook, feels odd defining user twice. as woodham stated, ansible variable represents connecting user is {{ ansible_user }} (ansible < 2.0 {{ ansible_ssh_user }} ) but don't have define in inventory file per se. you can define in: 1. play, if use ansible-playbook: see manual on playbooks - name: play hosts: remote_user: ubuntu 2. in inventory file: see manual on inventory [all] other1.example.com ansible_user=ubuntu (ansible < 2.0 ansible_ssh_user) 3. stated, on commandline: ansible-playbook -i inventory -u ubuntu playbook.yml 4. ansible config file remote_user directive. see manual on config file the ansible config file can placed in current folder ansi...

Php download on the same page without redirecting -

i have question how can make sure when android apk file download trigger, index.php page remain without being redirected blank. index.php page <head> //the javascript loading progress bar fake simulation how kb left. <script> $(document).ready(function() { $('body').on('click', '.btn', function(event) { $('#init').hide(); $('#progress').show(); progress_bar(3210, 'kb'); }); }); </script> </head> <body> <a href="download.php?appid=100&sid=12345" class="btn">download & install</a> </body> download.php $appid= $_request['appid']; $sid= $_request['sid']; if($appid==100)//offer download url { $url= "http://yeahmobi.go2cloud.org/aff_c?offer_id=20374&aff_id=18009&aff_sub=".$sid; header(...

ios - UIView viewwithtag method in swift -

i'm trying learn swift. programmatically add labels. want change properties later. the viewwithtag method returns uiview, how access uilabel this? cheers you need use typecast. code it: if let thelabel = self.view.viewwithtag(123) as? uilabel { thelabel.text = "some text" }

Saving bitmap to SdCard Android -

i writng code convert png file bmp , save on sdcard. current code. fileinputstream in; bufferedinputstream buf; try { in = new fileinputstream("file_path_to_read.png"); buf = new bufferedinputstream(in); byte[] bmaparray= new byte[buf.available()]; buf.read(bmaparray); bitmap bmap = bitmapfactory.decodebytearray(bmaparray, 0, bmaparray.length); //code segment save on file int numbytesbyrow = bmap.getrowbytes() * bmap.getheight(); bytebuffer bytebuffer = bytebuffer.allocate(numbytesbyrow); bmap.copypixelstobuffer(bytebuffer); byte[] bytes = bytebuffer.array(); fileoutputstream fileouputstream = new fileoutputstream("file_path_to_save.bmp"); fileouputstream.write(bytes); fileouputstream.close(); if (in != null) { in.close(); } if (buf != null) { buf.close(); } } catch (exception e) { }...

c# - Entity Framework doesn't recognise methods like Add, Remove -

i working entity framework on asp.net mvc3 visual studio 2010 , have problem: after changed database , moved project 1 computer another, no longer recognize methods of dbcontext such add , remove , , not know how reproduce them. mention code worked on computer. did not nothing relevant changes on database model. on following example, db dbcontext , tmsentities name of instance. public class categorycontroller : controller { // // get: /category/ private tmsentities db = new tmsentities(); [httppost] public actionresult addcategory(category model) { bool success = true; string status = string.empty; category item = new category(); item.name = model.name.trim(); item.description = model.description; if (string.isnullorempty(item.name)) { success = false; status += "category name can not empty! <br />...

python - Why are Pickle files in Pickle protocol 4 twice as large as those in protocol 3 without having any gains in speed? -

i testing python 3.4, , noticed pickle module has new protocol. therefore, benchmark 2 protocols. def test1(): pickle3=open("pickle3","wb") in range(1000000): pickle.dump(i,pickle3,3) pickle3.close() pickle3=open("pickle3","rb") in range(1000000): pickle.load(pickle3) def test2(): pickle4=open("pickle4","wb") in range(1000000): pickle.dump(i, pickle4,4) pickle3.close() pickle4=open("pickle4","rb") in range(1000000): pickle.load(pickle4) test1 mark: 2000007 function calls in 6.473 seconds test2 mark: 2000007 function calls in 6.740 seconds protocol 4 slower protocol 3. kind of difference can ignored. however, hard disk usage different. pickle3 uses 7,868,672 bytes. pickle4 uses 16,868,672 bytes. that's no reason. continue dig out. after read pep3154 , understand protocol. for tuple(1,2,3,4,5,6,7) of protocol 3 ...