Add the following code to the onCreate()/onResume() method:
SensorManager sensorManager;
Sensor mAccelerometer;
final float movementThreshold = 0.5f; // You may have to change this value.
boolean isMoving = false;
float[] prevValues = {1.0f, 1.0f, 1.0f};
float[] currValues = new float[3];
...
6.0
Default SET format is MMDDhhmm[[CC]YY][.ss], that's (2 digits each)
For example, to set July 17'th 10:10am, without changing the current year, type:
adb shell 'date 07171010.00'
Tip 1: the date change will not be reflected immediately, and a noticable change will happen only after the syst...
By going to Settings >> Keymap A window will popup showing All the Editor Actions with the their name and shortcuts. Some of the Editor Actions do not have shortcuts. So right click on that and add a new shortcut to that.
Check the image below
public class PlaySound extends Activity implements OnTouchListener {
private SoundPool soundPool;
private int soundID;
boolean loaded = false;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
su...
A spring bean can be configured such that it will register only if it has a particular value or a specified property is met. To do so, implement Condition.matches to check the property/value:
public class PropertyCondition implements Condition {
@Override
public boolean matches(ConditionC...
Before starting with the example I'd recommend to create a Singleton with a delegate class member so you could achieve a use case of uploading a file in the background and let the user keep using your app while the files are being uploaded even when the app is the background.
Let's start, first, we...
If all you need is to wrap the value into a promise, you don't need to use the long syntax like here:
//OVERLY VERBOSE
var defer;
defer = $q.defer();
defer.resolve(['one', 'two']);
return defer.promise;
In this case you can just write:
//BETTER
return $q.when(['one', 'two']);
$q.when ...
Pressing C-h a will run the emacs function apropos-command which makes emacs prompt for words (or a regexp) to search for. It will then show a buffer containing a list of names and descriptions related to that topic, including key bindings for each of the functions available via keystrokes.
Pressin...
The Data.Vector module provided by the vector is a high performance library for working with arrays.
Once you've imported Data.Vector, it's easy to start using a Vector:
Prelude> import Data.Vector
Prelude Data.Vector> let a = fromList [2,3,4]
Prelude Data.Vector> a
fromList [2,3,4]...
Vectors can be map'd and fold'd,filter'd andzip`'d:
Prelude Data.Vector> Data.Vector.map (^2) y
fromList [0,1,4,9,16,25,36,49,64,81,100,121] :: Data.Vector.Vector
Reduce to a single value:
Prelude Data.Vector> Data.Vector.foldl (+) 0 y
66
Zip two arrays into an array of pairs:
Prelude Data.Vector> Data.Vector.zip y y
fromList [(0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11)] :: Data.Vector.Vector
Most of the magic of destructuring uses the splat (*) operator.
ExampleResult / commenta, b = [0,1]a=0, b=1a, *rest = [0,1,2,3]a=0, rest=[1,2,3]a, * = [0,1,2,3]a=0 Equivalent to .first*, z = [0,1,2,3]z=3 Equivalent to .last
By default Code First includes in model
Types defined as a DbSet property in context class.
Reference types included in entity types even if they are defined in
different assembly.
Derived classes even if only the base class is defined as DbSet
property
Here is an example, that we are only...
Here is a quick example of using multiple forms in one Django view.
from django.contrib import messages
from django.views.generic import TemplateView
from .forms import AddPostForm, AddCommentForm
from .models import Comment
class AddCommentView(TemplateView):
post_form_class = AddPo...
Here is a quick reference for advanced insertion, formatting, and filtering commands/shortcuts.
Command/ShortcutResultg + ? + mPerform rot13 encoding, on movement mn + ctrl + a+n to number under cursorn + ctrl + x-n to number under cursorg + q+ mFormat lines of movement m to fixed width:rce wCenter...
By default, npm installs the latest available version of modules according to each dependencies' semantic version. This can be problematic if a module author doesn't adhere to semver and introduces breaking changes in a module update, for example.
To lock down each dependencies' version (and the ve...
Mockito.when(mock.returnSomething()).thenReturn("my val");
mock.returnSomething(); // returns "my val"
mock.returnSomething(); // returns "my val" again
mock.returnSomething(); // returns "my val" again and again and again...
If you want different valu...
There have been many releases of Java since the original Java 1.0 release in 1995. (Refer to Java version history for a summary.) However most releases have passed their official End Of Life dates. This means that the vendor (typically Oracle now) has ceased new development for the release, and n...
One method for creating recursive lambda functions involves assigning the function to a variable and then referencing that variable within the function itself. A common example of this is the recursive calculation of the factorial of a number - such as shown in the following code:
lambda_factorial ...