Skip to content

Instantly share code, notes, and snippets.

View fabiomsr's full-sized avatar

Fabio Santana fabiomsr

View GitHub Profile
// Java
final int andResult = a & b;
final int orResult = a | b;
final int xorResult = a ^ b;
final int rightShift = a >> 2;
final int leftShift = a << 2;
// Java
if(x instanceof Integer){ }
final String text = (String) other;
if(x >= 0 && x <= 10 ){}
// Java
if(a instanceof String){
final String result = ((String) a).substring(1);
}
// Java
final String result;
switch (x){
case 0:
case 11:
result = "0 or 11";
break;
case 1:
case 2:
fun newInstance(startPosition: Int) = MediaPagerFragment().apply {
arguments = Bundle().apply {
putInt(ARG_START_POSITION, startPosition)
}
}
// Java
for (int i = 1; i < 11 ; i++) { }
for (int i = 1; i < 11 ; i+=2) { }
for (String item : collection) { }
for (Map.Entry<String, String> entry: map.entrySet()) { }
// Java
List<Integer> numbers = Arrays.asList(1, 2, 3);
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "One");
map.put(2, "Two");
map.put(3, "Three");
@fabiomsr
fabiomsr / GrantPhonePermission.java
Last active August 4, 2016 06:25
Android Test utils
@Before
public void grantPhonePermission() {
// In M+, trying to call a number will trigger a runtime dialog. Make sure
// the permission is granted before running this test.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getInstrumentation().getUiAutomation().executeShellCommand(
"pm grant " + getTargetContext().getPackageName()
+ " android.permission.CALL_PHONE");
}
}
@fabiomsr
fabiomsr / FlutterHelloWorld_0.dart
Last active December 9, 2018 16:56
Flutter hello world
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Text("Hello, World!")
)
);
}
@fabiomsr
fabiomsr / FlutterHelloWorld_1.dart
Last active December 9, 2018 16:58
Flutter Hello World 1
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Padding(
padding: const EdgeInsets.only(top: 24.0),
child: Text("Hello, World")
)
)