Posts

python - hid.find_all_hid_devices() in asyncio coroutine -

in order access a usb hid device connected on computer use function find_all_hid_devices() from pywinusb package. now access hid device asyncio coroutine. following code @asyncio.coroutine def main(): pywinusb import hid = hid.find_all_hid_devices() the following error returned: traceback (most recent call last): file "c:\python34\lib\site-packages\pywinusb\hid\core.py", line 122, in find_all_hid_devices interface_data in winapi.enum_device_interfaces(h_info, guid): file "c:\python34\lib\site-packages\pywinusb\hid\winapi.py", line 466, in enum_device_interfaces byref(dev_interface_data) ): ctypes.argumenterror: argument 1: <class 'overflowerror'>: int long convert the same call hid.find_all_hid_devices() works on own, in plain main without asyncio. is due fact i'm trying access within coroutine? proper way achieve this? pywinusb library synchronous design, should call in thread pool. @asyncio.corout...

if statement - Android Studio If Else Conditions -

i require in forming if else code show message. example, if more or equal 50, message "green mark certified" showed in textview box. below codes did simple calculator. need when int sum>=50 , <75, show "green mark certified" in textview box. please kindly show me how code if want achieve it. public void onbuttonclick(view v){ edittext e1 = (edittext)findviewbyid(r.id.edittext); edittext e2 = (edittext)findviewbyid(r.id.edittext2); edittext e3 = (edittext)findviewbyid(r.id.edittext3); edittext e4 = (edittext)findviewbyid(r.id.edittext4); edittext e5 = (edittext)findviewbyid(r.id.edittext5); textview t1 = (textview)findviewbyid(r.id.textview); int num1 = integer.parseint(e1.gettext().tostring()); int num2 = integer.parseint(e2.gettext().tostring()); int num3 = integer.parseint(e3.gettext().tostring()); int num4 = integer.parseint(e4.gettext().tostring()); int num5 = integer.parseint(e5.gettext().tostring()); ...

Unable to send ICMP packets from a raw socket in Python -

i have raw python socket initialized so: mysocket = socket.socket(socket.af_inet, socket.sock_raw, socket.ipproto_raw) mysocket.setsockopt(socket.ipproto_ip, socket.ip_hdrincl, 1) my problem can't send packet socket protocol field in ip header specified '1' (icmp). if field else it'll work fine, including '17' (udp) example. don't errors, packet doesn't display in wireshark, , can't receive on server. i'm generating ip header so: def getipheader(src, dst, proto): version = 4 ihl = 5 dscp = 0 ecn = 0 totallength = 40 identification = 333 flags = 0 fragmentoffset = 0 timetolive = 128 protocol = proto headerchecksum = 0 sourceip = socket.inet_aton(src) destip = socket.inet_aton(dst) options = 0 version_ihl = (version << 4) | ihl dscp_ecn = (dscp << 2) | ecn flags_fragmentoffset = (flags << 13) | fragmentoffset # '!' ensures arguments conve...

ruby - weird ActiveRecord time zone behavior in Rails on multiple servers -

our application hosted on aws 8 app servers (unicorn) + 3 rds (1 master + 2 read replica) + 2 redis (master + slave) located in 1 region 8 app servers have bst time zone , 2 redis, have applied time zone 'london' in application.rb, the problem on show page start date, end date displayed value displayed start date friday 01-10-2015 - 18:30 , friday 01-10-2015 - 19:30 value reflect of refresh (ctrl + f5). has faced similar problem? ravi you can fix issue, adding around filter in application_controller override weird behaviour of active_record - timezone. around_filter :use_time_zone private def use_time_zone(&block) time.use_zone('london', &block) end so, whenever default timezone changed utc, override , set bst.

C++ template class confusion -

so experienced c programmer took dive c++ toy-compiler writing. "modernizing" c++ code because current code looks more ansi-c , c++ thing takes advantage of std::vector. so decided use iterators instead of manually iterating through containers , arrays via loop count variable. noticed need middle of several iterators wrote static class function that. now extending function not return iterator middle element return vector of iterators several parts of container. using templates make code more generic, kind of stuck implementation of current function. here definition of class: namespace dbc { template<typename generic_iterator_t> class itertools { public: /* returns iterator points middle element, * same calling get_fraction_iterator fraction = 2 */ static generic_iterator_t get_middle_iterator( generic_iterator_t begin, generic_iterator_t end ); /* splits container several chunks , returns * iterators in vector */ te...

python - Matplotlib plot_surface mplot3d with masked array and custom palette gives wrong color -

Image
i'm trying plot surface in 3d using mplot3d matplotlib. want custom color palette values above 1.0 green, below -1.0 blue, 0.0 red(invalid values) , other values according greyscale. i've been able of these right except condition 0.0 should red. following this example thought may able set 0.0 "bad value" in masked array fails. this snippet try plot values: import numpy np import matplotlib.pyplot plt import matplotlib.colors colors matplotlib import cm mpl_toolkits.mplot3d import axes3d ... fig = plt.figure() ax = fig.add_subplot(111, projection='3d') masked_array = np.ma.masked_equal(z,0.0) palette = cm.gray palette.set_over('g', 1.0) palette.set_under('b', 1.0) palette.set_bad('r', 1.0) ax.plot_surface(x,y,masked_array, rstride=1, cstride=1, cmap=palette, norm = colors.normalize(vmin = -1.0, vmax = 1.0, clip = false)) plt.savefig('plot.png') now run z set 2d numpy array many 0.0 values: >>...

Python: Storing data in a text file and appending particular/individual lines -

this computer science project i've been working on. test scores saved in text file against students name. example: rob 21 terry 12 mike 33 i can program want read lines of text file , identify if name in existence. if so, should add next score onto end of line. if terry takes test again scores should read: rob 21 terry 12 23 mike 33 this relevant piece of code. starts after test complete , user has input name, class , received score. import fileinput print("well done " +name+ ", score "+ (str(score))) entry = (name +" "+ (str(score))) if classchoice == "a": classfile = open("classa.txt") line in classfile: if name in line: oldline = line newline = (oldline+" "+(str(score))) print (newline) classfile.close() else: classfile = open("classb.txt","a") ...