var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous developer used two...

What does if __name__ == "__main__": do?

Given the following code, what does the if __name__ == "__main__": do? # Threading example import time, thread def myfunction(string, sleeptime, lock, *args): while True: ...

How do you remove duplicates from a list whilst preserving order?

Is there a built-in that removes duplicates from list in Python, whilst preserving order? I know that I can use a set to remove duplicates, but that destroys the original order. I also know that I...

Lisp Community - Quality tutorials/resources

As many other people interested in learning Lisp, I feel the resources available are not the best for beginners and eventually prevent many new people from learning it. Do you feel it could be...

Pythonic way to write functions/methods with a lot of arguments

Imagine this: def method(self, alpha, beta, gamma, delta, epsilon, zeta, eta, theta, iota, kappa): pass The line overpass the 79 characters, so, what's the pythonic way to multiline it?

Get the key corresponding to the minimum value within a dictionary

If I have a Python dictionary, how do I get the key to the entry which contains the minimum value? I was thinking about something to do with the min() function... Given the input: {320:1, 321:0,...

Can a valid Unicode string contain FFFF? Is Java/CharacterIterator broken?

Here's an excerpt from java.text.CharacterIterator documentation: This interface defines a protocol for bidirectional iteration over text. The iterator iterates over a bounded sequence of...

what does `using std::swap` inside the body of a class method implementation mean?

I was trying to learn and adopt the copy-swap idiom following this thorough explanation on this question: the Copy-Swap Idiom. But I found some code I had never seen: using std::swap; // allow ADL...

How to implement the factory method pattern in C++ correctly

There's this one thing in C++ which has been making me feel uncomfortable for quite a long time, because I honestly don't know how to do it, even though it sounds simple: How do I implement...

Elegant way to remove contiguous repeated elements in a list

I'm looking for a clean, Pythonic, way to eliminate from the following list: li = [0, 1, 2, 3, 3, 4, 3, 2, 2, 2, 1, 0, 0] all contiguous repeated elements (runs longer than one number) so as to...

The simplest and neatest c++11 ScopeGuard

I'm attempting to write a simple ScopeGuard based on Alexandrescu concepts but with c++11 idioms. namespace RAII { template< typename Lambda > class ScopeGuard { mutable bool...

Select by partial string from a pandas DataFrame

I have a DataFrame with 4 columns of which 2 contain string values. I was wondering if there was a way to select rows based on a partial string match against a particular column? In other words, a...

Is "*_" an acceptable way to ignore arguments in python

If I have a function/method that is an implementation of a callback for some framework, and do not care for any further arguments, it seems to be syntactically correct, and to not have pylint/IDE...

py.test - how to use a context manager in a funcarg/fixture

Closely related: In python, is there a good idiom for using context managers in setup/teardown I have a context manager that is used in tests to fix the time/timezone. I want to have it in a...

std::vector removing elements which fulfill some conditions

As the title says I want to remove/merge objects in a vector which fulfill specific conditions. I mean I know how to remove integers from a vector which have the value 99 for instance. The remove...

Idiom for "repeat n times"?

Here's a somewhat wasteful and impractical way to produce an array of 3 random numbers in JS: [1, 1, 1].map(Math.random) // Outputs: [0.63244645928, 0.59692098067, 0.73627558014] The use of a...

What's the C++ idiom equivalent to the Java static block?

I have a class with some static members, and I want to run some code to initialize them (suppose this code cannot be converted into a simple expression). In Java, I would just do class MyClass { ...

What is the idiomatic Go equivalent of C's ternary operator?

In C/C++ (and many languages of that family), a common idiom to declare and initialize a variable depending on a condition uses the ternary conditional operator : int index = val > 0 ? val :...

Python MySQLdb/mysqlclient: bind a named set (or tuple or list) as parameter

Background: Not much documentation on MySQLdb Connector Maybe I'm looking in the wrong places, but there's not much documentation about Python's MySQLdb family of connectors. Perhaps PEP249 is...

Is there an alternative to "revalue" function from plyr when using dplyr?

I'm a fan of the revalue function is plyr for substituting strings. It's simple and easy to remember. However, I've migrated new code to dplyr which doesn't appear to have a revalue function. What...

Read from a channel or timeout?

With Rust 1.9, I'd like to read from a mpsc::channel or timeout. Is there a clear idiom to make this work? I've seen the unstable approach described in mpsc::Select but this Github discussion...

Idiomatic Typescript Enum Discriminated Union

As of typescript 2.0 you can use discriminated unions with an enum as the discriminant like this: export function getInstance(code: Enum.Type1, someParam: OtherType1): MyReturnType1; export...

structs with boxed vs. unboxed closures

I'm still internalizing closures in Rust and how to best work with them, so this question might be somewhat vague, and there will perhaps be silly sub-questions. I'm basically looking for proper...

Is there any built in lambda for is notNone in python

I see the following idiom repeated several times in python X = filter(lambda x: x is not None, X)) I was hoping there is a builtin function for is not None(in its standard library or something...

How does StampedLock queue lock requests?

I am investigating locking a cache based on Java8's StampedLock (javadoc here) but I can't find a convincing implementation on the net to follow, despite reading articles like StampedLock...

Idiomatic way to create n-ary cartesian product (combinations of several sets of parameters)

To create all possible combinations of two sets of parameters and perform an action on them, you can do: setOf(foo, bar, baz).forEach { a -> setOf(0, 1).forEach { b -> /* use a and b...

How to replay Jenkins pipeline job that uses generic webhook HTTP POST content?

I have a Jenkins Pipeline job that is triggered by a Bitbucket generic webhook. I.e. Jenkins has the Generic Webhook Trigger: ...and Bitbucket projects trigger this Jenkins project by adding a...

Solving predicate calculus problems with Z3 SMT

I'd like to use Z3 to solve problems that are most naturally expressed in terms of atoms (symbols), sets, predicates, and first order logic. For example (in pseudocode): A = {a1, a2, a3, ...} # A...

Multithreaded idiomatic find first of substrings in a string using modern C++

It is easy to find a string in a set of strings using set::find or first of a set of strings in a set of strings using std::find_first_of. But I think that STL doesn't handle this case of...