Initialize class fields in constructor or at declaration?

Initialize class fields in constructor or at declaration?

I've been programming in C# and Java recently and I am curious where the best place is to initialize my class fields.Should I do it at declaration?:public class Dice{ private int topFace = 1; private Random myRand = new Random(); p

How to pick an image from gallery (SD Card) for my app?

How to pick an image from gallery (SD Card) for my app?

This question was originally asked for Android 1.6.I am working on photos options in my app. I have a button and an ImageView in my Activity. When I click the button it would redirect to the gallery and I would be able to select an image. T

Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten'

Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten'

I need to convert the Excel matrix FIRST in the table LATER: FIRST: P1 P2 P3 P4F1 XF2 X XF3 X XF4 X XLATER:F P VALUEF1 P1 XF1 P2F1 P3F1 P4F2 P1 XF2 P2 XF2 P3F2

How to parse JSON in Java

How to parse JSON in Java

I have the following JSON text. How can I parse it to get pageName, pagePic, post_id, etc.?{ "pageInfo": { "pageName": "abc", "pagePic": "http://example.com/content.jpg" } "posts": [ { "post_id":

Passing data in the body of a DELETE request

Passing data in the body of a DELETE request

I have two Spring MVC controller methods. Both receive the same data in the request body (in the format of an HTLM POST form: version=3&name=product1&id=2), but one method handles PUT requests and another DELETE:@RequestMapping(value = "aja

Problems filtering django datetime field by month and day

Problems filtering django datetime field by month and day

Can someone explain to me why the following filters are not working at the month and day level? Filtering by year seems to work, but not the other two.>>> clicks.count()36>>> date = clicks[0].created>>> date.month2>>> date.year2014>>> date

djangorestframework: Filtering in a related field

djangorestframework: Filtering in a related field

Basically, I want to filter out inactive users from a related field of a ModelSerializer. I tried Dynamically limiting queryset of related field as well as the following:class MySerializer(serializers.ModelSerializer): users = serializers.

Detecting EOF in C

Detecting EOF in C

I am using the following C code to take input from user until EOF occurs, but problem is this code is not working, it terminates after taking first input. Can anyone tell me whats wrong with this code. Thanks in advance.float input;printf("

Symfony2 Doctrine2 trouble with optional one to one relation

Symfony2 Doctrine2 trouble with optional one to one relation

I have a problem with Doctrine2 in Symfony2 and two relationed entities.There is a user-entity that can (not must) have a usermeta-entity referenced which contains information like biography etc.The usermeta is optional because user is impo

Facebook API for Android: how to get extended info regarding user`s friends?

Facebook API for Android: how to get extended info regarding user`s friends?

I`m working on small Android application, trying to add Facebook support.Main problem: I can get only basic info regarding user`s friends (id, name).List of app permissions (offline_access is here just for test, will be removed soon): Strin

auto-generate models for sequelize

auto-generate models for sequelize

I'm wanting to start using Sequelize, a module that allows ORM for mysql in node.js. I was wondering if it's possible to auto-generate the models like CakePHP does. In CakePHP, it will read the table's info, and automatically create the ass

How to handle view model with multiple aggregate roots?

How to handle view model with multiple aggregate roots?

At the moment, i got quite badly fashioned view model.Classes looks like this=> public class AccountActionsForm { public Reader Reader { get; set; } //something... }Problem is that Reader type comes from domain model (vi

How to upload multiple images in Django using Dropzone for multiple image fields

How to upload multiple images in Django using Dropzone for multiple image fields

I am working on a project where the functionality is the user can upload his multiple images with a drag-n-drop feature. I am developing using the Django-python. I have implemented the functionality of drag-n-drop in django template, but I

Replacing embedded document in array in MongoDB

Replacing embedded document in array in MongoDB

Is there an easy way to replace an entire embedded document in an array? Say replacing:{ "_id" : "2", "name" : "name2", "xyz..." : "xyz2..."}with:{ "_id" : "2", "name" : "name6", "xyz..." : "xyz5..." "

Go parser not detecting Doc comments on struct type

Go parser not detecting Doc comments on struct type

I am trying to read the assocated Doc comments on a struct type using Go’s parser and ast packages. In this example, the code simply uses itself as the source.package mainimport ( "fmt" "go/ast" "go/parser" "go/token")// FirstTy

Generic list of generic objects

Generic list of generic objects

Let's say I have an object that represents a field of data, that object needs the following properties: Name, Type, Value, Length. Here is the object:class Field{ public string Name { get; set; } public Type Type { get

exporting vertical lines in org mode table to LaTeX

exporting vertical lines in org mode table to LaTeX

I'm using emacs as my editor and I am toying with org-mode which looks rather useful.I'm generating a table (spreadsheet) in org mode and it is exported correctly to LaTeX apart from the vertical lines. Is there a way to export them? I want

Django rest framework user registration?

Django rest framework user registration?

I am following this tutorial but facing these problems I can't fix:Upon registering user, I can not log in with that user to the api because the password is not hashed"Invalid password format or unknown hashing algorithm." in adminI cannot

Is there something like Snoop (WPF) or FireBug (ASP.NET) for Windows Forms? [closed]

Is there something like Snoop (WPF) or FireBug (ASP.NET) for Windows Forms? [closed]

I want to point with the mouse on an area in my application and know the name of the UserControl. 1:I recommend WinSpy++ because its much easier to get hold of then the original Spy++ which comes as part of the Windows SDK.Just like Spy+

How to print current time (with milliseconds) using C++ / C++11

How to print current time (with milliseconds) using C++ / C++11

Currently I use this codestring now() { time_t t = time(0); char buffer[9] = {0}; strftime(buffer, 9, "%H:%M:%S", localtime(&t)); return string(buffer);}to format time. I need to add milliseconds, so the output has the format: 1

Django form __init__() got multiple values for keyword argument

Django form __init__() got multiple values for keyword argument

Hello, I'm trying to use a modified __init__ form method, but I am encountering the following error:TypeError__init__() got multiple values for keyword argument 'vUserProfile'I need to pass UserProfile to my form, to get to dbname field, an

cURL CSRF Token

cURL CSRF Token

I few months ago, my colleague created an calendar subscription by getting the work schedule. I believe he has done this by cURL.Now I'm building a website to have an overview about the tasks that should be done today.I want to retrieve the

LINQ: How to do JOIN using the linq extension method style on multiple fields?

LINQ: How to do JOIN using the linq extension method style on multiple fields?

In the Join below, I'd like to use multiple fields to do the join rather than just one field.var join = group.Join(procSums, g => g.DeptID, ps => ps.key.deptID, (g, ps)...All examples Ive found use the query style to do this and I can't tra

External system queries during Kafka Stream processing

External system queries during Kafka Stream processing

I'm trying to design a streaming architecture for streaming analytics.Requirements:RT and NRT streaming data inputStream processors implementing some financial analysisRT and NRT analysis output streamReference data requests during stream p

.NET Library For Fixed Length Text Files

.NET Library For Fixed Length Text Files

I'm looking for a .NET (much preferably open source in C#) library for dealing with fixed length field text files. It wouldn't be too much to write one, but existing, tested work is always nicer, to start with.I will be extracting data in