Posts

Showing posts from August, 2014

c++ - Using Templates to resolve virtual methods -

this issue involves using templates resolve virtual members in dispatch pattern. note: not same virtual template method questions asked on stackoverflow . * edit 1: corrected syntax errors, added clarifications. given following: #include <string> #include <iostream> class field_interface { public: virtual std::string get_field_name(void) const = 0; }; class field_integer : public field_interface { public: std::string get_field_name(void) const { return "int";} }; class field_string : public field_interface { public: std::string get_field_name(void) const { return "varchar";} }; class field_double : public field_interface { public: std::string get_field_name(void) const { return "double";} }; class abstract_visitor { public: virtual void visit(const field_integer& fi) = 0; virtual void visit(const field_string& fi) = 0; virtual void visit(const field_double& fi) = 0;

/ operand not working as expected in python 3 -

Image
i'm reading book tkinter gui application development hotshot based on python 2, , have code: from tkinter import * rows = 5 un = 2 bp = 2 columns = un * bp root = tk() right_frame = frame(root) right_frame.pack() button = [[0 x in range(columns)] x in range(rows)] in range(rows): j in range(columns): active = false color = '#f3f3f3' if (j / bp) % 2 else '#9a72a9' button[i][j] = button(right_frame, bg=color, relief='flat', width=1) button[i][j].grid(row=i, column=j) root.mainloop() and have result: need this: . tkinter works when run tkinter , python 2 unexpected result when running in python 3 , tkinter, cause behaviour? the difference due how python 2.x , python 3.x handle division operator. lengthy description can found here: http://legacy.python.org/dev/peps/pep-0238/

python - Find Largest Element in 2 Ordered Lists which does not occur in one list -

hi i've searched here can't find answer problem. i'm using python , have 2 lists. both ordered. first list longer 1 (approx 10,000 elements) , never changes. second 1 shorter grows program runs same length. the lists might this: [1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 10, 11, 12, 13, 16, 18, 19, 20] [1, 1, 2, 2, 3, 4, 16, 18, 19, 20] in case, want return 13 because it's maximum element in list 1 not in list 2. now repeatedly list 1 needs remain unchanged. both lists contain duplicate values. my naive way of doing far slow: def removeitems(list2, list1): list1copy = list(list1) item in list2: if item in list1copy: list1copy.remove(item) return list1copy so create new list , remove items exist in shorter list , value want end value in list1copy. there must faster way of doing using dicts or something? so far none of answers have been given take advantage of fact lists ordered , want largest value l1 not i

Generating Shake Rules from Actions -

i find of 'makefiles' in project , generate rules based them. however, looks (purposely) nothing can escape action. so, instead lifted 'makefile' scanner io operation before shake function. main = makefiles <- findmakefiles shake skakeoptions $ generate_rules makefiles is there better way? firstly, don't think there's wrong current approach. shake package uses similar approach built in ninja , makefile interpreters, see details makefile interpreter or the sake interpreter . long processing makefile sufficiently quick not matter (which is) writing interpreter custom build syntax using shake, works nicely. there couple of reasons avoid approach, example, if processing of makefile expensive, or if makefile has other dependencies. in situation can use combination of newcache parse makefile once, , addoracle rules can depend on subset of makefile require. however, approach tricker right, since forces layer of indirection, , have make assu

java - Difference between "file:///" and "file://" -

i tried both , both did same. there difference (only interest)? i have webview loads local data , able hand on url that. example: webview.loadurl("file://storage/emulated/0/folder1/folder2/hello.html" going spec file://storage/emulated/0/folder1/folder2/hello.html invalid. storage here should represent host name. while using file uri scheme may choose ignore host represents path. described on wiki page, quote below. a file uri takes form of file://host/path where host qualified domain name of system on path accessible, , path hierarchical directory path of form directory/directory/.../name. if host omitted, taken "localhost", machine url being interpreted. note when omitting host, slash not omitted ("file:///foo.txt" valid, while "file://foo.txt" not, although interpreters manage handle latter). my guess webview.loadurl lenient , accepts file uris not conform spec. uri.fromfile() provides examp

c# - Domain to ViewModel Design? -

i wondering best design following. have domain models like: public class car { public string name { get; set; } //other common properties removed brevity } in domain model have models fuel specific cars inherit car like: public class dieselcar : car { public bool runonbiodiesel { get; set; } //other diesel specific properties removed brevity } public class petrolcar : car { public int nosparkplugs { get; set; } //other petrol specific properties removed brevity } on view have common car view model. common properties used , depending on fuel type render partial view either diesel or petrol - again partial view takes complete carview model there common properties on each partial view well. however rather map multiple properties view model domain in controller , domain view model in view model builder wanting take adavantage of automapper this. however think mean having below in automapperbootstrapper (and i'm not sure work correctly??) mapper.c

Get "Terminated due to Memory error" for ios 8 custom keyboard Extension -

i developing ios 8 custom keyboard extension. run charm start. but "receive memory warning" in xcode. custom keyboard extension terminate sometimes. but run custom keyboard in host app. there don't have problem. don't "receive memory warning" in xcode. don't terminate. anybody can me? if app have limit size extension use? terminated due memory error http://i62.tinypic.com/ra41lz.png apple mentions in app extension programming guide memory limits app extensions significantly lower limits imposed on foreground apps. additionally types of extensions may have lower limits others. apple not explicit these memory limits far can tell , it's unclear if dependent on device , how memory other apps consuming. ethan mentioned, keyboard extensions should aim less 30mb avoid crashing. it's important test extension when not running in xcode or using debug build configuration. seems memory limits debug builds higher.

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

i have button on website when clicked, reveals map. button can seen when page first loads up, when clicked, section holding map slides open , goes out of screen since page loads @ top (normal). want page scroll down bottom of div select when button pushed, if map out of screen. if page scrolled down, , clicks show map button, don't want page jump bottom of map. i tried figure out myself, no luck. seasoned jquery coders able give me guidance? many thanks! map = mapdiv.gmap3("get"); infobox = new infobox({ pixeloffset: new google.maps.size(-220, -310), closeboxurl: '', enableeventpropagation: true }); mapdiv.delegate('.infobox .close','click',function () { infobox.close(); }); jquery(".slidingdiv").hide(); jquery(".show_hide").show(); jquery('.show_hide').click(function(){ lastcenter=map.getcenter(); jquery(".slidingdiv&quo

java - The method done(ParseObject, ParseException) from the type new FindCallback<ParseUser>(){} is never used locally -

Image
below error getting: the method done(parseobject, parseexception) type new findcallback<parseuser>(){} never used locally from line public void done(parseobject object,parseexception e) { i not sure if section of code wrongly placed in code, have added multiple log messages , realized skips entire section of code. below section: public void done(parseobject object,parseexception e) { log.d(constants.log, "pardeobject"); parsequery<parseobject> query = parsequery.getquery("user"); query.getfirstinbackground(new getcallback<parseobject>() { public void done(parseobject object, parseexception e) { if (object != null) { log.d(constants.log, "object != null"); parsefile file = (parsefile)object.get("profilepicture"); file.getdatainbackground(new getdatacallback() { public void done(byte[] data, parseexception e) { if (e == null) { bitmap bitma

objective c - Is it possible to change predicates from a UIButton? -

i have set of words in core data model. have buttons filter based on category, adjectives, verbs, etc. i have code below, table not reload.. > - (ibaction)selectadjectives:(id)sender { > nslog(@"%s", __function__); > predicateswitch = 3; // int > [nsfetchedresultscontroller deletecachewithname:nil]; > [self.wordtable reloaddata]; } > > - (nspredicate*)predicate { > nslog(@"%s", __function__); > nspredicate *predicate = [[nspredicate alloc] init]; > switch (predicateswitch) { > case 0: > predicate = nil; > break; > > case 1: > ... > break; > > case2: > ... > > case3: > predicate = [nspredicate predicatewithformat:@"self.category contains[c] %@",@"adjective"]; > break; > >

Using PHP variables in an HTML element class with Blade -

i'm using laravel , blade on small project , trying dynamically assign class names generated elements in loop. however, generated elements generating literally, such " <div class='form_q' .$i> ". @for($i = 0; $i < count($formdata['form2']); $i++) <div class='form_q'.$i> html::attributes('class') <div class='q'.$i.'-header'> <h1>{{ form::label($formdata['form2']['q'.($i + 1)]['question'], $formdata['form2']['q'.($i + 1)]['type'], array('class' => 'btn btn-primary'))}}</h1> </div> </div> @endfor what's proper syntax concatenating string , variable , assigning class/attribute? alternatively, proper blade syntax generating "div" element assigned class? you need tell blade or php want print output. ether surround $i variables {{ $i }} or <?php echo $i ?> . bl

python - Penalize error on one category svm sklearn? -

i've got ~100 data elements 1 class, , ~6000 class. when create svm using data, returns majority category label every new element try predict on. there way penalize misclassification of minority category sklearn svm, can use data elements , not have sample 100 elements majority category use in testing? svc has following parameter can use class_weight : {dict, 'auto'}, optional set parameter c of class class_weight[i]*c svc. if not given, classes supposed have weight one. 'auto' mode uses values of y automatically adjust weights inversely proportional class frequencies.

c# - Is that necessary to dispose objects inside static functions? -

Image
ok having major problem atm. my software using extremely high amount of ram. using lot of htmlagilitypack.htmldocument objects big size pages sources. however of objects used inside static functions , htmlagilitypack.htmldocument isn't idisposable so need set every variable explicitly null ? even if inside static functions ? for example need set these variables null @ end of function below the variables asking : lstdrwlist ? or since inside disposed automatically ? should call explicitly garbage collector ? c# .net 4.5 wpf application private static void func_checkwaitingtoprocesspages(object state) { paralleloptions myoptions = new paralleloptions(); myoptions.maxdegreeofparallelism = publicsettings.ir_how_many_tasks_for_per_pages_process; list<datarow> lstdrwlist = new list<datarow>(); using (datatable dtmytable = dbconnection.db_select_datatable(srselecttopprocesspagesquery)) { foreach (datarow drw in dtmytable.

r - Function generation; change defaults of other functions (partial) -

i have need function generator takes function , arguments of function , sets new defaults. thought @hadley's pryr::partial magic function. want except can't change new default. here can change sep in new paste function not new default of collapse = "_bar_" . how can make partial perform way (i.e., default collapse = "_bar_" enable setting collapse = null if desired)? if not possible partial there way rewrite code partial this: https://github.com/hadley/pryr/blob/master/r/partial.r library(pryr) .paste <- pryr::partial(paste, collapse = "_foo_") .paste(1:5) .paste(1:5, letters[1:5], sep="_bar_") .paste(1:5, collapse=null) > .paste(1:5) [1] "1_foo_2_foo_3_foo_4_foo_5" > .paste(1:5, letters[1:5], sep="_bar_") [1] "1_bar_a_foo_2_bar_b_foo_3_bar_c_foo_4_bar_d_foo_5_bar_e" > .paste(1:5, collapse=null) error in paste(collapse = "_foo_", ...) : formal argument "col

c# - Why Windows Form TextBox won't update from outside class? -

newbie here. i'm running visual studio c# express 2008. have 2 windows forms, each textbox. textboxes update within same class not result of invoked method outside class. need able update tbrooms.text when updatelistofrooms() method invoked. i've outlined problem in pseudo-code below. appreciate help! flocations.cs flocations_load() { this.tblocations.text = properties.settings.default.locationid + " locationsload"; --updates } dgvlocations_selectionchanged() { var rooms = new frooms(); rooms.tbrooms.text = properties.settings.default.locationid + " locationssselectionchanged"; --updates rooms.updatelistofrooms(); } frooms.cs frooms_load() { this.tbrooms.text = properties.settings.default.locationid + " roomsload"; --updates } updatelistofrooms() { this.tbrooms.text = properties.settings.default.locationid + " roomsupdatelistofrooms"; --does not update; still says "roomsload" } updat

ios - How to make UIViewControllerSubclass a subclass of UITableViewController -

Image
i'm going through xcode tutorial , it's asking me create uiviewcontrollersubclass file , make subclass of uitableviewcontroller. i'm using xcode 5.1.1 , still cannot find uiviewcontrollersubclass template in creating new file. someone please tell me how in latest version of xcode. here tutorial reference https://www.youtube.com/watch?v=2p8gctq62ou (21:15) thanks in advance uitableviewcontroller is subclass of uiviewcontroller, when create new uitableviewcontroller, subclass of both uitableviewcontroller , uiviewcontroller. to create subclass of uitableviewcontroller in xcode, either go file -> new file, or hit command+n, select cocoa touch under ios, , select objective-c class: you prompted window below. name new class , select uitableviewcontroller in subclass drop-down box. "newtableviewcontroller" subclass of uitableviewcontroller, subclass of uiviewcontroller described above.

How to hide close button in WPF window? -

i'm writing modal dialog in wpf. how set wpf window not have close button? i'd still windowstate have normal title bar. i found resizemode, windowstate, , windowstyle, none of properties allow me hide close button show title bar, in modal dialogs. wpf doesn't have built-in property hide title bar's close button, can few lines of p/invoke. first, add these declarations window class: private const int gwl_style = -16; private const int ws_sysmenu = 0x80000; [dllimport("user32.dll", setlasterror = true)] private static extern int getwindowlong(intptr hwnd, int nindex); [dllimport("user32.dll")] private static extern int setwindowlong(intptr hwnd, int nindex, int dwnewlong); then put code in window's loaded event: var hwnd = new windowinterophelper(this).handle; setwindowlong(hwnd, gwl_style, getwindowlong(hwnd, gwl_style) & ~ws_sysmenu); and there go: no more close button. won't have window icon on left side of tit

Polymer element's on-keypress won't fire -

i bind on-keypress event on element declarative event mapping , keypresshandler wont fire. did try answer another question , still same. here dome , element gdg-slider.html , , codes on github . <link rel="import" href="bower_components/polymer/polymer.html"> <link rel="import" href="bower_components/core-icons/core-icons.html"> <link href="bower_components/core-animated-pages/core-animated-pages.html" rel="import"> <link href="bower_components/core-animated-pages/transitions/cross-fade.html" rel="import"> <link href="bower_components/core-animated-pages/transitions/slide-from-right.html" rel="import"> <link rel="import" href="bower_components/paper-shadow/paper-shadow.html"> <link rel="import" href="bower_components/paper-fab/paper-fab.html"> <polymer-element name="gdg-slider

How to get first n elements in an array in Hive -

i use split function create array in hive, how can first n elements array, , want go through sub-array code example select col1 table split(col2, ',')[0:5] '[0:5]'looks likes python style, doesn't work here. this tricky one. first grab brickhouse jar here add hive : add jar /path/to/jars/brickhouse-0.7.0-snapshot.jar; now create 2 functions usings : create temporary function array_index 'brickhouse.udf.collect.arrayindexudf'; create temporary function numeric_range 'brickhouse.udf.collect.numericrange'; the query : select a, n array_index, array_index(split(a,','),n) value_from_array ( select "abc#1,def#2,hij#3" dual union select "abc#1,def#2,hij#3,zzz#4" dual) t1 lateral view numeric_range( length(a)-length(regexp_replace(a,',',''))+1 ) n1 n explained : select "abc#1,def#2,hij#3" dual union select "abc#1,def#2,hij

c# - ObservableCollection is not reflecting UI -

i beginner wpf , mvvm. while coding it, came across issue listitems variable in vehicleaddviewmodel class, of type observablecollection list. binding view viewmodel proper, listitems getting updated, onpropertychanged method working when add new list listitems, not reflecting ui. at other end, if make listitems object static, starts working. don't know why happening. i anxious know why happening this. i have bunch of files, putting relevant ones working , non-working versions, please let me know if need other file. listofvehicle.xaml <window x:class="seris.listofvehicle" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="listofvehcle" height="600" width="700" xmlns:l="clr-namespace:seris.viewmodels" xmlns:cnv="clr-namespace:seris.converters"> <wi

How to Increment values dynamically in SQL select statement -

i want display values a-z , these values auto increment in select statemnet my output should this desk desk b desk c .... .... desk z i stuck here desk no = (select 'desk'+'') thanks in advance. you this, assuming mean tsql and assuming have table you're selecting. if want independently, want make numbers table. select 'desk ' + char(65 + (((row_number() over(order [somecolumn])) - 1) % 26)) tablename of course, becomes million times easier if table has id column has identity set. select 'desk ' + char(65 + ((id - 1) % 26)) tablename on other hand, if have numbers table, that's easier. select 'desk ' + char(65 + (value % 26)) numbers

asp.net mvc - Data annotation validation does not work -

i developing application in mvc using smart admin in use data annotations validation purpose. code is: public class employeedto { [key] public int id { get; set; } [required(errormessage = "name required")] [stringlength(50, errormessage = "name can accept maximum 50 characters.")] [regularexpression("^([a-za-z]{1}[a-za-z '-.(-,)-/&]*)$", errormessage = "please enter valid name.")] public string name { get; set; } } and view is <script src="~/smartadmin/js/libs/jquery-2.0.2.min.js"></script> <script src="@url.content("~/scripts/jquery.validate.min.js")" type="text/javascript"></script> <script src="@url.content("~/scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script> @model hbseworld.admin.dto.employeedto @{ v

java - Image getting printed with low resolution -

Image
i have requirement create pdf images printing. adding high resolution image pdf using itext. it's reducing quality 72 dpi. resulting in poor quality of image after printing. the original image resolution 2549*3304 , dpi (300). i tried below options image.scaleabsolute(2549*.24 ,3304*.24 ); image.setdpi(300,300); image.scaletofit(2549*.24 ,3304*.24 ); current code looks this document document = new document(pagesize.letter); document.open(); image image = image.getinstance("c:/project/bg.png"); image.setabsoluteposition(0,0); image.scalepercent(24); document.add(image); document.close(); i went through threads ( adding image pdf using itextsharp , scale properly ) still not able solve problem can please me on better image quality while printing? the setdpi() method irrelevant in code, dpi of original image. pixels treated points in itext. means adding image as-is result in having 72 pixels per inch. you scale image 24 percent o

php - Image uploading error while hosting -

i new in web development , came across error when trying upload image server using php. has solution problem? appreciated. security alert the file uploading rejected server. contents viruses or trojans can damage website not attempt upload again ip address may blocked.

installation - Setup Sitecore 7.1 using SQL Windows Authentication -

how can install sitecore 7.1 using sql server windows credentials? it's asking sql server authentication have windows authentication. there 3 things need set allow sitecore using windows authentication while connection mssql server database: allow chosen user account on sql server set application pool web application use chosen user account identity set integrated security=true in connectionstrings.config file

c# - How to get the values of all the elements in an XML into an array? -

for example : i have following xml, <?xml version="1.0" encoding="utf-8"?> <test> <name>testrun</name> <syncbyte>ff</syncbyte> <som>53</som> <pdadd>7e</pdadd> <lenlsb>08</lenlsb> </test> i values tags "syncbyte", "som", "padd" , "lenlsb" single array. there option within xml accomplish this? p.s. there close 20+ tags in xml , not tags contain values time. hence if there single command values of xml, great. with linq xml: var xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <test> <name>testrun</name> <syncbyte>ff</syncbyte> <som>53</som> <pdadd>7e</pdadd> <lenlsb>08</lenlsb> </test>"; var doc = xdocument.parse(xml); string[] values = doc.ro