Posts

Featured post

c# - Are delegates created via lambda expressions guaranteed to be cached? -

it seems working way, stated somewhere in spec or implementation detail can't depend on? i'm trying speed property/field name extraction faster creating expression tree once , caching it. wrapping tree in lambda , using key cache. , break down miserably if runtime decides create new delegate every time hits same lambda expression. // keyvaluepair<string, t> getpair<t>(func<expression<func<t>>> val)... var item = new item { num = 42 }; var pair = getpair(() => () => item.num); // guaranteed same instance? // pair.key = "num" // pair.value = 42 edit: ok, here full thing. seems works , doesn't seem generate garbage in process. another edit: ok, changed it, doesn't seem capture anything, , works faster! using system; using system.diagnostics; using system.linq.expressions; using system.runtime.compilerservices; class program { static void main(string[] args) { var pair = new pair<int>();

c - sscanf() double showing zeros -

i'm having troubles sscanf() function read doubles. have comma separated text file this: abc,def,0.465798,0.754314 ghi,jkl,0.784613,0.135264 mno,opq,0.489614,0.745812 etc. so first line fgets() , use sscanf() 2 string , 2 double variables. fgets(buffer, 28, file); sscanf(buffer, "%4[^,],%4[^,],%lf[^,],%lf[^\n]", string1, string2, &double1, &double2); printf("%s %s %f %f\n", string1, string2, double1, double2); but output is: abc def 0.465798 0.000000 ghi jkl 0.784613 0.000000 mno opq 0.489614 0.000000 so somehow doesn't scan last float. i've tried %lf[^ \t\n\r\v\f,] , %lf still doesn't work. change "%4[^,],%4[^,],%lf[^,],%lf[^\n]" to int result; result = sscanf(buffer, "%4[^,],%4[^,],%lf,%lf", string1, string2, &double1, &double2); if (result != 4) // handle error notice & on double1 , double2 - likley typo. also strongly recommend check result 4. not checking sscanf(

wordpress - Get images used in, but not attached to page? -

i want of images used in page. code i'm using: function get_page_images($id) { $photos = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'asc', 'orderby' => 'menu_order id') ); $results = array(); if ($photos) { foreach ($photos $photo) { // correct image html selected size $results[] = wp_get_attachment_image($photo->id, $size); } } return $results; } this gets images uploaded page, if have reused image uploaded different page/post, aren't retrieved (as attached post uploaded to, not posts reused in). know way all images used in page/post? use built-in php dom parser grab images located in content. code untested, should started in right direction: <

php - Select element from other table on the form zf2 -

i have 2 table manytoone relation on database between client , sale , want select id_client on sale form . o used . saleform : public function __construct(clienttable $table) { parent::__construct('vente'); $this->setattribute('method', 'post'); $this->clienttable = $table; $this->add(array( 'name' => 'id', 'attributes' => array( 'type' => 'hidden', ), )); $this->add( array( 'name' => 'id_client', 'type' => 'select', 'attributes' => array( 'id' => 'id_client' ), 'options' => array( 'label' => 'catégory',

camera - code work on android 4.1 but don't on 4.2 (possible?) -

i'm writing application record video front camera. possible app can't work on android 4.2? i've tried tablet 4.1.1, customer says not work in tablet. this code related recording: //create surface view public void surfacecreated(surfaceholder holder) { mcamera= camera.open(1); setcameradisplayorientation( this, 1, mcamera); viewgroup.layoutparams params = msurfaceview.getlayoutparams(); parameters parameters = mcamera.getparameters(); list<size> sizes = parameters.getsupportedpreviewsizes(); params.width = (sizes.get(0).width / 4); params.height = (sizes.get(0).height / 4); msurfaceview.setlayoutparams(params); } i things error in code edit i have insert lot of log... app freezing when stopping recorder. call on trycatch.. try{ appendlog(&

node.js - REFERENCE KEY in node-orm2 -

i working on rest api based on node.js , chose postgresql database store data. suppose database has 2 tables names user , comment . comment belongs 1 user , when decide remove user , comment 's of him/her must removed. so, designed table follows: create table user( user_id serial, username varchar(32) not null, password varchar(32) not null, constraint pk_user primary key (user_id), constraint uq_user unique (username) ) create table comment( comment_id serial, user_id integer not null, content text not null, constraint pk_cmnt primary key (comment_id), constraint fk_cmnt foreign key (user_id) references user(user_id) on update cascade on delete cascade ) but don't run code , use node-orm2 instead. designed 2 simple models handle simple code: var user = db.define('user', { username: { type: 'text', size: 32, // varchar(32) required: true, // not null unique: true

command line - Python: find current directory of remote "cmd.exe" processes -

i write script among other things erases directory using shutil.rmtree i have ensure no "cmd.exe" opened in directory (and blocking me erasing directory). i can killing "cmd.exe" on remote computer: process_name = "cmd.exe" computer_name = "atacama6" try: subprocess.check_call('taskkill.exe /s {} /u admin1 /p abc$ /im {}'\ .format(computer_name, process_name)) except subprocess.calledprocesserror: # no matches found - thats ok! pass but afraid of killing "cmd.exe" processes opened in other directories , need run. how can kill ones opened in specific directory?