Skip to content

Instantly share code, notes, and snippets.

View matthew-carroll's full-sized avatar

Matt Carroll matthew-carroll

View GitHub Profile
@matthew-carroll
matthew-carroll / HttpBoilerplate.java
Last active August 29, 2015 13:59
Intro to Retrofit by Square
// Compose a single request to send to the server:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.myserver.com/apis/users/" + userId + "/profile");
List<NameValuePair> bodyParams = new ArrayList<NameValuePair>();
pairs.add(new NameValuePair("first_name", firstName));
pairs.add(new NameValuePair("last_name", firstName));
pairs.add(new NameValuePair("street1", firstName));
pairs.add(new NameValuePair("street2", firstName));
pairs.add(new NameValuePair("zip", firstName));
@matthew-carroll
matthew-carroll / PicassoExample.java
Last active August 29, 2015 14:01
Introduction to Picasso
// Picasso canonical usage. Notice the elegance of the method chaining
Picasso.with(context).load(imageUrl).into(myImageView);
// Images fade in by default, if you don't want that
Picasso.with(context).load(imageUrl).noFade().into(myImageView);
// Explicitly control sizing and scaling
Picasso.with(context).load(imageUrl).resize(100, 100).centerCrop().into(myImageView);
// Provide placeholder images when downloading and upon error
@matthew-carroll
matthew-carroll / BusProvider.java
Created May 18, 2014 12:05
Introduction to Otto
/**
* BusProvider is a Singleton which provides
* app-wide access to a single Bus instance.
*/
public class BusProvider
{
private static BusProvider instance;
public BusProvider getInstance()
{
@matthew-carroll
matthew-carroll / functional.js
Last active August 29, 2015 14:03
Example of functional programming in JavaScript
// Example of how one might do some functional programming in
// JavaScript. This example uses promises and presents a fictional
// process for taking a photo, creating a thumbnail, and saving
// them. Notice how the data is passed through all the functions
// instead of being stored in a higher scope.
obtainCamera()
.then(function(camera) {
// we receive a camera from obtainCamera()
@matthew-carroll
matthew-carroll / objectoriented.js
Created June 28, 2014 01:36
Example of object-oriented programming in JavaScript
// Example of how one might do some object-oriented programming in
// JavaScript. This example uses a prototype definition to present
// a fictional application that might govern a plane taking off
// from an airport. Notice how the program is not just a list of
// instructions - control often leaves the Plane object and then
// later returns to the Plane upon some outside event or message.
// Initiates the take off process
Plane.prototype.takeOff = function() {
this.doSafetyCheck();
@matthew-carroll
matthew-carroll / Currrent_MainActivity.java
Last active August 29, 2015 14:03
Handling KindleTV Remote Events
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.d("mgm:t1", "MainActivity.onKeyDown " + event);
if ( keyCode == KeyEvent.KEYCODE_MENU) {
handler.post(new Runnable() {
@Override
public void run() {
mDrawerFragment.openDrawer();
}
@matthew-carroll
matthew-carroll / bad_touch_area.dart
Created May 5, 2018 07:46
50x50 circle button centered on screen with bad touch area
// At center of screen...
new FractionalTranslation(
translation: const Offset(0.5, 0.5),
// Stack whose origin is centered on screen
child: new Stack(
children: <Widget>[
// This FractionalTranslation pulls the button back by
// 50% in both directions to center the button at the
// Stack's origin
MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
primaryColor: Colors.red,
),
);
@matthew-carroll
matthew-carroll / with_dark_theme.dart
Last active September 16, 2019 04:58
Dark Theme
MaterialApp(
theme: ThemeData(
brightness: Brightness.light,
primaryColor: Colors.red,
),
darkTheme: ThemeData(
brightness: Brightness.dark,
),
);
@matthew-carroll
matthew-carroll / MainActivity.java
Created May 22, 2019 21:07
Canonical GeneratedPluginLoader usage
// This example assumes that the developer is using the new Android embedding
// API, as well as plugins that have opted-in to the proposed dart-side
// plugin initialization.
public class MainActivity extends FlutterActivity {
@Override
protected void onFlutterEngineCreated(@NonNull FlutterEngine engine) {
engine.setPluginLoader(new GeneratedPluginLoader());
}
}