Questions

Interface vs Base class

When should I use an interface and when should I use a base class? Should it always be an interface if I don't want to actually define a base implementation of the methods? If I have a Dog and Cat ...

Distinct() with lambda?

Right, so I have an enumerable and wish to get distinct values from it. Using `System.Linq`, there's, of course, an extension method called `Distinct`. In the simple case, it can be used with no param...

7 Jul at 21:0

How to check if a string is a substring of items in a list of strings

How do I search for items that contain the string `'abc'` in the following list? ``` xs = ['abc-123', 'def-456', 'ghi-789', 'abc-456'] ``` The following checks if `'abc'` is in the list, but does not...

11 Aug at 17:49

How to cherry-pick a range of commits and merge them into another branch?

I have the following repository layout: - - - What I want to achieve is to cherry-pick a range of commits from the working branch and merge it into the integration branch. I'm pretty new to git and I...

23 Aug at 08:31

LINQ Aggregate algorithm explained

This might sound lame, but I have not been able to find a really good explanation of `Aggregate`. Good means short, descriptive, comprehensive with a small and clear example.

21 Jan at 13:12

Equivalent of shell 'cd' command to change the working directory?

`cd` is the shell command to change the working directory. How do I change the current working directory in Python?

10 Feb at 18:38

View a file in a different Git branch without changing branches

Is it possible to open a file in a git branch without checking out that branch? How? Essentially I want to be able to open a file in my [github pages](http://pages.github.com/) branch without switchi...

14 Feb at 15:28

How to break out of jQuery each loop?

How do I break out of a jQuery [each](https://api.jquery.com/each/) loop? I have tried: ``` return false; ``` in the loop but this did not work. Any ideas? --- ## Update 9/5/2020 I put the `ret...

29 Sep at 05:44

How to test multiple variables for equality against a single value?

I'm trying to make a function that will compare multiple variables to an integer and output a string of three letters. I was wondering if there was a way to translate this into Python. So say: ``` x =...

How to tell Jackson to ignore a field during serialization if its value is null?

How can Jackson be configured to ignore a field value during serialization if that field's value is null. For example: ``` public class SomeClass { // what jackson annotation causes jackson to s...

17 Jul at 04:30

What does the Ellipsis object do?

While idly surfing the namespace I noticed an odd looking object called `Ellipsis`, it does not seem to be or do anything special, but it's a globally available builtin. After a search I found that ...

6 Jan at 16:17

Adding a method to an existing object instance in Python

I've read that it is possible to add a method to an existing object (i.e., not in the class definition) in Python. I understand that it's not always good to do so. But how might one do this?

6 Feb at 13:43

How to fix "Attempted relative import in non-package" even with __init__.py

I'm trying to follow [PEP 328](http://www.python.org/dev/peps/pep-0328/), with the following directory structure: ``` pkg/ __init__.py components/ core.py __init__.py tests/ core_te...

How to kill a process on a port on ubuntu

I am trying to kill a process in the command line for a specific port in ubuntu. If I run this command I get the port: ``` sudo lsof -t -i:9001 ``` so...now I want to run: ``` sudo kill 'sudo lso...

29 Oct at 17:49

Split a string by another string in C#

I've been using the `Split()` method to split strings, but this only appears to work if you are splitting a string by a character. Is there a way to split a `string`, with another string being the spl...

22 Apr at 07:11

Repeat a string in JavaScript a number of times

In Perl I can repeat a character multiple times using the syntax: ``` $a = "a" x 10; // results in "aaaaaaaaaa" ``` Is there a simple way to accomplish this in Javascript? I can obviously use a fun...

22 Jan at 03:3

.gitignore all the .DS_Store files in every folder and subfolder

I've added .DS_Store to the .gitignore file, but it seems that it is only ignoring .DS_Store in the root directory, not in every folder and subfolder. How do I fix this?

22 Feb at 00:28

How to get the current date/time in Java

What's the best way to get the current date/time in Java?

3 May at 05:44

How to change fontFamily of TextView in Android

So I'd like to change the `android:fontFamily` in Android but I don't see any pre-defined fonts in Android. How do I select one of the pre-defined ones? I don't really need to define my own TypeFace b...

What's the best way to limit text length of EditText in Android

What's the best way to limit the text length of an `EditText` in Android? Is there a way to do this via xml?

5 Dec at 12:41

How to generate a random string in Ruby

I'm currently generating an 8-character pseudo-random uppercase string for "A" .. "Z": ``` value = ""; 8.times{value << (65 + rand(25)).chr} ``` but it doesn't look clean, and it can't be passed a...

13 Apr at 19:22

Creating an empty Pandas DataFrame, and then filling it

I'm starting from the pandas DataFrame documentation here: [Introduction to data structures](http://pandas.pydata.org/pandas-docs/stable/dsintro.html) I'd like to iteratively fill the DataFrame with v...

18 Feb at 17:49

How to get the type of T from a member of a generic class or method

Let's say I have a generic member in a class or method, like so: ``` public class Foo<T> { public List<T> Bar { get; set; } public void Baz() { // get type of T } } ```...

21 Jun at 19:54

Babel 6 regeneratorRuntime is not defined

I'm trying to use async/await from scratch on Babel 6, but I'm getting `regeneratorRuntime` is not defined. .babelrc file ``` { "presets": [ "es2015", "stage-0" ] } ``` package.json file ``` "dev...

23 Aug at 08:50

Why can't I change directories using "cd" in a script?

I'm trying to write a small script to change the current directory to my project directory: ``` #!/bin/bash cd /home/tree/projects/java ``` I saved this file as proj, added execute permission with ...

5 Aug at 17:59