Posts

c++ - Is it safe to cast away const if never call any non-const methods -

is still undefined behavior cast away const pointer object if const methods ever called after cast? i'm trying implement both iterator , const_iterator class dereferenced iterator proxy object small amount of state , pointer parent object (simplified below) although const qualified proxy calls const methods on parent still requires non-const pointer in constructor. class query { public: int (int r, int c) const; void set (int r, int c, int v); class iterator { iterator (query *q, int r) : m_qry(q), m_row(r) {} row operator* const () { return row(m_qry, m_row); } query *m_qry; int m_row; }; class const_iterator { const_iterator (const query *q, int r) : m_qry(q), m_row(r) {} const row operator* const () { // protected constructor row needs cast return row(const_cast<query *>(m_qry), m_row); } const query *m_qry; int m_row; ...

php - How to simplify an API without sacrificing Dependency Injection? -

let's have rectangle class. use i'd do: $rectangle = new rectangle( 100, 50, new color('#ff0000') ); however public api, want simplify end-users as possible. preferably accept hex string: $rectangle = new rectangle( 100, 50, '#ff0000'); the problem need instantiate color object inside rectangle class class rectangle { protected $width; protected $height; protected $fillcolor; function __construct( $width, $height, $fillcolor ){ $this->width = $width; $this->height = $height; $this->fillcolor = new color( $fillcolor ); } } having learned dependency injection considered bad. or it? what's best approach? i use factory class, accepts array (possibly) of arguments , returns ready instantiated rectangle object. there many possibilities how that, depending on design , api specification. class myapifactory { public function createrectangle($params) { // checks of para...

javascript - d3.js - how to actualize the graph data? transition? -

i trying learn d3.js (with no javascript background) created simple scatter plot . now, looking how render graph random data, each time user click on next button. in link above, there tried far. i know it's newbie question , there thousands of example looking explained solution (not code). thanks ps: please change external ressource this if graphs won't show up.

How to Convert Table Into Columns R -

how convert datatables columns, example: ab cd ef jk lm x 6 0 5 0 0 y 0 7 0 0 0 z 0 0 8 0 0 0 0 0 9 0 b 0 0 0 6 10 to v1 v2 x ab 6 x ef 5 y cd 7 z ef 8 jk 9 b lm 10 b jk 6 one option convert 'data.frame' 'matrix', melt it, , subset 'value' not '0'. library(reshape2) subset(melt(as.matrix(df1)), value!=0) or library(dplyr) library(tidyr) add_rownames(df1, 'rn') %>% gather(v1, v2, -rn) %>% filter(v2!=0)

python - Django login does nothing -

i'm using django's pre-packaged login, , reason, refreshes page, without login in, , without giving me of messages have set in view. here html: <div class="col-md-9 col-md-offset-2" style="background-color: white; margin-top:10px; border-radius: 8px;"> {% if message %} <b>{{message}}</b> {% endif %} <form id="form" method="post" action="">{% csrf_token %} <table>{{form}}</table> <div class="col-lg-9 col-lg-offset-2"> <button type="submit" class="btn btn-primary">submit</button> </div> </form> </div> here url: url(r'^login', 'users.views.login', name='login'), and here view: from django.shortcuts import render deck1.models impo...

javascript - How can I bring a circle to the front with d3? -

first of all, using d3.js display different sized circles in arrays. on mouse over, want circle being moused on become bigger, can do, have no idea how bring front. currently, once it's rendered, it's hidden behind multiple other circles. how can fix this? here's code sample: .on("mouseover", function() { d3.select(this).attr("r", function(d) { return 100; }) }) i tried using sort , order methods, didn't work. i'm pretty sure didn't correctly. thoughts? you have change order of object , make circle mouseover being last element added. can see here: https://gist.github.com/3922684 , suggested nautat , have define following before main script: d3.selection.prototype.movetofront = function() { return this.each(function(){ this.parentnode.appendchild(this); }); }; then have call movetofront function on object (say circles ) on mouseover: circles.on("mouseover",function(){ var sel = d3.select...

Difficulty creating proper RavenDB query -

i trying implement logic below in ravendb query, receive system.notsupportedexception: not understand expression related scores.any expression. understand why is, i'm having hard time coming working option. public iravenqueryable<person> apply(iravenqueryable<person> query) { var scores = new list<string>(); if (_a) scores.add("a"); if (_b) scores.add("b"); if (_c) scores.add("c"); if (_u) { scores.add(""); scores.add(" "); scores.add("\t"); scores.add(null); } return p in query scores.any(score => score == p.score) select p; } the trick ravendb linq provider isn't operating on list scores.any() makes 0 sense -- compiles can see dies @ runtime. the trick reverse field bit , ask if p.score in array of scores if recall correctly.