Skip to content

Instantly share code, notes, and snippets.

View fabiomsr's full-sized avatar

Fabio Santana fabiomsr

View GitHub Profile
// Java
if(x instanceof Integer){ }
final String text = (String) other;
if(x >= 0 && x <= 10 ){}
// Java
final String result;
switch (x){
case 0:
case 11:
result = "0 or 11";
break;
case 1:
case 2:
// 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");
fun newInstance(startPosition: Int) = MediaPagerFragment().apply {
arguments = Bundle().apply {
putInt(ARG_START_POSITION, startPosition)
}
}
@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 / contact_data.dart
Last active September 5, 2016 19:36
Contact data II
const kContacts = const <Contact>[
const Contact(
fullName: 'Romain Hoogmoed',
email:'romain.hoogmoed@example.com'
),
const Contact(
fullName: 'Emilie Olsen',
email:'emilie.olsen@example.com'
)
];
@fabiomsr
fabiomsr / contact_data.dart
Last active September 5, 2016 19:36
Contact Data I
class Contact {
final String fullName;
final String email;
const Contact({this.fullName, this.email});
}
@fabiomsr
fabiomsr / contact_data.dart
Created September 11, 2016 19:40
Contact data interface
import 'dart:async';
class Contact {
final String fullName;
final String email;
const Contact({this.fullName, this.email});
}
@fabiomsr
fabiomsr / contact_data.dart
Created September 11, 2016 20:10
Contact from map
class Contact {
final String fullName;
final String email;
const Contact({this.fullName, this.email});
Contact.fromMap(Map<String, dynamic> map) :
fullName = "${map['name']['first']} ${map['name']['last']}",
email = map['email'];