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 ...
- Modified
- 6 Mar at 21:25
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...
- Modified
- 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...
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...
- Modified
- 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.
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?
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...
- Modified
- 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...
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 =...
- Modified
- 22 May at 19:22
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...
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 ...
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?
- Modified
- 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...
- Modified
- 17 Oct at 20:59
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...
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...
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...
- Modified
- 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?
How to get the current date/time in Java
What's the best way to get the current date/time in Java?
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...
- Modified
- 4 Jul at 10:57
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?
- Modified
- 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...
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...
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 } } ```...
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...
- Modified
- 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 ...
- Modified
- 5 Aug at 17:59