Posts

Showing posts from January, 2011

android - Custom drawable on mapview -

Image
rectangle.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:layout_weight="100"> <solid android:color="#ffffff"/> <stroke android:width="3dp" android:color="#ff000000"/> <padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp"/> <corners android:radius="30dp"/> </shape> my map activity //drawable d = getresources().getdrawable(r.drawable.chart); <-- drawn on map drawable rect = getresources().getdrawable(r.drawable.rectangle); // <-- wont overlayitems itemizedoverlay = new overlayitems(rect, this); could please explain why cant add custom shapes on mapview? normal png file works well, if try make custom shape , add it, wont appear. makes no sense me since theyre both drawables? did mi...

multithreading - Is this python code thread safe (thread with twisted)? -

i writing application collect udp messages , process them every 1sec. application prototype looks like: from twisted.internet.protocol import datagramprotocol twisted.internet import reactor import threading import time class udplistener(datagramprotocol): messages = [] def datagramreceived(self, data, (host, port)): self.messages.append(data) class messenger(threading.thread): listener = none def __init__(self): threading.thread.__init__(self) def run(self): while true: time.sleep(1) recivedmessages = self.listener.messages length = len(recivedmessages) messagestoproccess = recivedmessages[0:length] #dosomethingwithmessages(messagestoproccess) del self.listener.messages[0:length] print(length) listener = udplistener() messenger = messenger() messenger.listener = listener messenger.start() reactor.listenudp(5556, listener) reactor.run() i not sure if can remove beginning values list (del self.listener.messages[0:length]) without risk incoming message changes list , application cras...

php - What is the difference between double quotes and single quotes in mysql query -

i found issue , insert query works, don't understand why. here current working query: $add_movie = mysql_query("insert ownedmovies values ('', '{$movie_data['title']}', '{$movie_data['year']}', '{$movie_data['rated']}', '{$movie_data['runtime']}', '{$movie_data['genre']}', '{$movie_data['director']}', '{$movie_data['writer']}', '{$movie_data['actors']}', \"{$movie_data['plot']}\", '{$movie_data['imdbrating']}')"); notice used double quotes around plot field , normal around else. when did plot field same way others, not error nothing inserted table... works perfectly. could enlighten me on why is? thank you i suspect plot string contains single quote. avoid problem should escaping string values using mysql_real_escape_string , or (better) use parameterized queries. your "solution" of ch...

html - Jquery: Display error with animated and multiple divs on hover -

i have written little jquery, has nice hover effect. however, on mouse hovers, sccipt seems faulty, seems cause loop of animate effects. (mostly when hover between 2nd , 3rd div) does have suggestion how fix issue? http://test.gifix.de/index.php sorry poor description of problem, sure see once hover bit on example ;) thanks every help, scott your animations queuing up. prevent this, use jquery stop function: http://api.jquery.com/stop/ i updated code include use of stop function. works me. here updated code: <script type="text/javascript">//<![cdata[ $(window).load(function(){ $('#blue-top').mouseenter(function(){ $('#blue-top').stop(true).animate({height:'200'}, 500); $('#blue-middle').stop(true).animate({height:'80'}, 500); $('#blue-bottom').stop(true).animate({height:'80'}, 500); }); $('#blue-top').mouseleave(function(){ $('#blue-top').stop(true).animate({height:'120'}, 50...

Perl: Should Math64::Int64 work inside a "Safe" Compartment? -

(my first post stack overflow, hope using right format) i have need evaluate code manipulates 64-bit integers in "safe" compartment. since supply both script , code evaluated, normal eval, wanted try make things more robust unintentional errors using 'safe". should expect math::int64 should work inside "safe" compartment? conflicting results across different bitness of perl versions, integer bit-width, , oses. (see below). all fail in same way inside debugger. i sure making incorrect assumption place, can't figure out where. thanks can give. code example (dummy.pl) use strict; use warnings; use exporter; use safe; use math::int64 qw(int64 hex_to_int64); #use math::int64 ':native_if_available'; $safe = new safe 'root'; $safe->permit( qw(:browse) ); $safe->share( qw/int64 hex_to_int64 my_sprintf/ ); $x = 0xff & (hex_to_int64("0xaa12345678") >> 4); print my_sprintf("x ",$x); $z = evalme('$x = ...

wordpress get excerpt by id -

i'm using options framework and can't work out why doesnt work $x = of_get_option('post_number'); $content_post = get_post($x); echo $content_post->post_excerpt; its odd because echo of_get_option('post_number'); works , outputs number and according get_post code should work yet echo produces nothing, not error message so must handeling get_post() incorrectly somehow, clues? edit var dump http://pastebin.com/zegq5wpn reveals post_content full post_excerpt empty how regenerate excerpt? edit [resolved] i decided manualy overwrite excerpt option missing, found this and used add_post_type_support( 'page', 'excerpt' ); to manualy write excerpt $text = apply_filters('the_excerpt', get_post_field('post_excerpt', $post_id));

sqlite ON CONFLICT difference between ABORT and FAIL -

from http://www.sqlite.org/lang_conflict.html abort when applicable constraint violation occurs, abort resolution algorithm aborts current sql statement sqlite_constrait error , backs out changes made current sql statement; changes caused prior sql statements within same transaction preserved , transaction remains active. default behavior , behavior proscribed sql standard. fail when applicable constraint violation occurs, fail resolution algorithm aborts current sql statement sqlite_constraint error. fail resolution not out prior changes of sql statement failed nor end transaction. example, if update statement encountered constraint violation on 100th row attempts update, first 99 row changes preserved changes rows 100 , beyond never occur. both preserve changes made before statement caused constraint violation , not end transaction. so, suppose difference fail resolution not let further changes made, while abort conflicting statement. did right? the answer simple: fail not ...

java - Get byte representation of int, using only 3 bytes -

what's nice, readable way of getting byte representation (i.e. byte[] ) of int , using 3 bytes (instead of 4)? i'm using hadoop/hbase , bytes utility class has tobytes function use 4 bytes. ideally, i'd nice, readable way of encoding few bytes possible, i.e. if number fits in 1 byte use one. please note i'm storing in byte[] , know length of array , variable length encoding not necessary. finding elegant way cast. a general solution impossible. if possible, apply function iteratively obtain unlimited compression of data. your domain might have constraints on integers allow them compressed 24-bits. if there such constraints, please explain them in question. a common variable size encoding use 7 bits of each byte data, , high bit flag indicate when current byte last. you can predict number of bytes needed encode int a utility method on integer : int n = 4 - integer.numberofleadingzeros(x) / 8; byte[] enc = new byte[n]; while (n-- > 0) enc[n] = (byte) (...

jquery - Possible to loop over each in coffeescript? -

i'm trying programmatically create javascript buttons toggle visibility on page (for snappy tag filtering). works 1 tag: trigger = ".sales-focus-btn" target = ".sales-focus" jquery -> $(trigger).toggle -> $("#primary-content").find('.container').hide() $("#primary-content").find(target).show() , -> $("#primary-content").find('.container').show() is possible similar in coffeescript, arrays, e.g. trigger = [ ".sales-focus-btn" ".service-focus-btn" ".other-focus-btn" ... ] target = [ ... ] is possible loop on , create toggle each type of tag? update yes it's possible. use form: myfunction = (el) -> console.log el myfunction elem elem in array of course it's possible: content = $('#primary-content') container = content.find('.container') tags = [ '.sales-focus' '.service-focus' '.other-focus' ] $.each tags, (tag) -> ...

Obtaining Unique Line from Unix 'join' -

given these 2 files file1.txt ------ foo bar file2.txt ------ foo 1 foo 2 bar 31 how can obtain first line of successful join in file2.txt? expected result after joining is: foo 1 bar 31 i tried didn't work: join file1.txt file2.txt what's right join command? the join tried print both instances of foo file2 . if want pick one, use sort ensure there unique entries in both files before actual join: join <(sort file1) <(sort -k1,1 -u file2)

arrays - How to use NSPredicate with NSPredicateEditor on different data (Multiple Predicates?) -

i've got array of filepaths , i've got nspredicateeditor setup in ui user can combine nspredicate find file . should able filter name, type, size , date . there several problems have now: i can only 1 predicate object editor. when use "predicateforrow:" returns (null) if user wants filter file name , size or date, can't use predicate on array anymore because information not contained in it can split predicate different predicates without converting nsstring object, search every @" or " | @" , " , seperating components array , converting every nsstring new predicate? in nspredicateeditor settings i've options "left expression": keypaths, constant values, strings, integer numbers, floating point numbers , dates . want display dropdown menu user "name", "type", "date", "size". generated predicate automatically looks this: "name" matches[c] "nametest" or "...