Automating the InvokeRequired code pattern

Automating the InvokeRequired code pattern

I have become painfully aware of just how often one needs to write the following code pattern in event-driven GUI code, whereprivate void DoGUISwitch() { // cruisin for a bruisin' through exception city object1.Visible = true; obje

What is the type of string literals in C and C++?

What is the type of string literals in C and C++?

What is the type of string literal in C? Is it char * or const char * or const char * const?What about C++? 1:In C the type of a string literal is a char[] - it's not const according to the type, but it is undefined behavior to modify th

Sorting in JavaScript: Shouldn't returning a boolean be enough for a comparison function?

Sorting in JavaScript: Shouldn't returning a boolean be enough for a comparison function?

I have always successfully sorted my arrays like this (when I did not want the standard lexicographic ordering):var arr = […] // some numbers or soarr.sort(function(a, b) { return a > b;});Now, someone told me this was wrong, and that I

Detecting which UIButton was pressed in a UITableView

Detecting which UIButton was pressed in a UITableView

I have a UITableView with 5 UITableViewCells. Each cell contains a UIButton which is set up as follows:- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ NSString *identifier = @"iden

Static initializer in Java

Static initializer in Java

My question is about one particular usage of static keyword. It is possible to use static keyword to cover a code block within a class which does not belong to any function. For example following code compiles:public class Test { private

How to handle both a single item and an array for the same property using JSON.net

How to handle both a single item and an array for the same property using JSON.net

I'm trying to fix my SendGridPlus library to deal with SendGrid events, but I'm having some trouble with the inconsistent treatment of categories in the API. In the following example payload taken from the SendGrid API reference, you'll no

How to count the occurrences of a list item?

How to count the occurrences of a list item?

Given an item, how can I count its occurrences in a list in Python? 1:If you only want one item's count, use the count method:>>> [1, 2, 3, 4, 1, 4, 1].count(1)3Don't use this if you want to count multiple items. Calling count in a loop

Encrypt and decrypt a string in C#?

Encrypt and decrypt a string in C#?

How can I encrypt and decrypt a string in C#? 1:EDIT 2013-Oct: Although I've edited this answer over time to address shortcomings, please see jbtule's answer for a more robust, informed solution.https://stackoverflow.com/a/10366194/18847

Why is the order in dictionaries and sets arbitrary?

Why is the order in dictionaries and sets arbitrary?

I don't understand how looping over a dictionary or set in python is done by 'arbitrary' order.I mean, it's a programming language so everything in the language must be 100% determined, correct? Python must have some kind of algorithm that

Why does a RegExp with global flag give wrong results?

Why does a RegExp with global flag give wrong results?

What is the problem with this regular expression when I use the global flag and the case insensitive flag? Query is a user generated input. The result should be [true, true].var query = 'Foo B';var re = new RegExp(query, 'gi');var result =

Laravel 5.3 Creating Models Returns “Field doesn't have a default value”

Laravel 5.3 Creating Models Returns “Field doesn't have a default value”

I'm using Laravel and Eloquent for two years and today I've decided to install a fresh Laravel 5.3 and try something with it.I used an old database schema of mine and created my models, defined fillable columns. This is what my Page model l

Hungarian Algorithm: How to cover 0 elements with minimum lines?

Hungarian Algorithm: How to cover 0 elements with minimum lines?

I am trying to implement the Hungarian algorithm in Java. I have an NxN cost matrix. I am following this guide step by step. So I have the costMatrix[N][N] and 2 arrays to track covered rows and covered cols - rowCover[N], rowColumn[N] (1

is there a way to pass nested initializer lists in C++11 to construct a 2D matrix?

is there a way to pass nested initializer lists in C++11 to construct a 2D matrix?

Imagine you have a simple matrix classtemplate class Matrix { T* data; size_t row, col;public: Matrix(size_t m, size_t n) : row(m), col(n), data(new T[m*n]) {} //... friend std::ostream& operatorIs there a way that I can initial

Insertion-Order Dictionary (like Java's LinkedHashMap) in Swift?

Insertion-Order Dictionary (like Java's LinkedHashMap) in Swift?

Is there a standard swift class that is a Dictionary, but keeps keys in insertion-order like Java's LinkedHashMap? If not, how would one be implemented? 1:Didn't know of one and it was an interesting problem to solve (already put it in m

How to close Smtp connection in SwiftMailer

How to close Smtp connection in SwiftMailer

I use SwiftMailer to send emails from a gearman worker process. I'm using the Swift_SmtpTransport class to send emails.The problem is that if this worker process stays idle for sometime, the SwiftMailer smtp connection times out. Now when t

Three.js png texture - alpha renders as white instead as transparent

Three.js png texture - alpha renders as white instead as transparent

I'm creating a cube and I apply 6 different textures to each of it's faces. Each texture is a .png file and contains transparent parts. I'm also applying a color to the cube - I want to see that color trough png transparency.Problem: Transp

Rails database boolean values

Rails database boolean values

Code first:create_table :users do |t| ... t.boolean :is_active, :default => true ...endNow, here is my issue - I am creating a rake task to import a LARGE number of records (10,000+). I've done extensive testing and benchmarking and dete

Initializing List with given number of nulls without loop?

Initializing List with given number of nulls without loop?

Can a List be initialized to contain a given number of nulls, where T is a type parameter of the class of which the list is a member? I sure can do it with a loop, but like to know whether it is possible without.List myList = new ArrayList(

Clojure: sequence back to vector

Clojure: sequence back to vector

How can I cast a sequence back to vector after a sequence producing operation (like sort)? Does using (vec..) on a sequence that was a vector is costly? One (bad?) possibility is creating a new vector out of sequence:(vec (sort [1 2 3 4 5 6

Which is better? array, ArrayList or List (in terms of performance and speed)

Which is better? array, ArrayList or List (in terms of performance and speed)

I require a fast speed in processing my page. The count of the values to be added will be dynamic.Which one of the above is preferred? Support with a valid reason.Edit: For eg:string str = "a,b,c"; //Count of the number of elements in str i

Codeigniter unset session

Codeigniter unset session

Hi I have a site develop in CodeIgniter.In one of my page I'm using pagination of CodeIgniter after a search form.In this case I store into my session the search value passed by $_POST because if I have more result clicking the next page th

Convert a string of 0-F into a byte array in Ruby

Convert a string of 0-F into a byte array in Ruby

I am attempting to decrypt a number encrypted by another program that uses the BouncyCastle library for Java.In Java, I can set the key like this: key = Hex.decode("5F3B603AFCE22359");I am trying to figure out how to represent that same st

KnockoutJS bind event after template render

KnockoutJS bind event after template render

I've been searching for a while, and I'm pretty confident this is a new question, and not a repeat like the title suggests. :)Basically, I'm trying to find out if there is a subscribe-able event that KnockoutJS creates after a template rend

Configuring Gradle with Kotlin

Configuring Gradle with Kotlin

I am trying to use kotlin with gradle, but I am unable to succesfully create a project with Intellij Idea 15.I've create simple project with two modules hello-java and hello-kotlin. hello-java is plain java project and it is compiling and r

Creating tuples from two vectors

Creating tuples from two vectors

If I have two vectors of the same length A and B how can I easily turn these two vectors into a single tuple vector i. e. c((5,7),(7,13))? 1:Others have mentioned lists. I see other possibilities:cbind(A, B) # makes a column-major 2x2-