Skip to content

Instantly share code, notes, and snippets.

@chrisjeon
chrisjeon / puma.rb
Created March 24, 2017 22:57
Puma config recommended by heroku
workers Integer(ENV['WEB_CONCURRENCY'] || 2)
threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5)
threads threads_count, threads_count
preload_app!
rackup DefaultRackup
port ENV['PORT'] || 3000
environment ENV['RACK_ENV'] || 'development'
@chrisjeon
chrisjeon / App.java
Created March 21, 2017 11:56
App.java with holding instance of itself
public class App {
public static App instance;
private static UserCacher mUserCacher;
private static SharedPreferences mPrefs;
private static TokenRefresher mTokenRefresher;
private GoogleApiClient mGoogleApiClient;
@Override
public void onCreate() {
super.onCreate();
@chrisjeon
chrisjeon / AndroidManifest.xml
Created March 21, 2017 11:50
SomeAndroidManifest example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.someapp">
<application
android:name="com.someapp.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
@chrisjeon
chrisjeon / IntentServiceWrapperClass.java
Created January 2, 2017 19:12
Starting/stopping an intent service
public class IntentServiceWrapperClass {
private static final String LOG_TAG = SomeJavaClass.class.getSimpleName();
private SomeIntentService mSomeIntentService;
public void sendOnlineStatusWithLocation(Context context) {
mSomeIntentService = new Intent(ACTION_SYNC, null, context, SomeIntentService.class);
context.startService(mSomeIntentService);
}
public void stopSendingOnlineStatusWithLocation(Context context) {
@chrisjeon
chrisjeon / ExampleIntentService.java
Created January 2, 2017 19:06
IntentService example
package com.pik.sample.app;
public class SomeLocationIntentService extends IntentService {
private static final String LOG_TAG = SomeLocationIntentService.class.getSimpleName();
public SomeLocationIntentService() {
super(SomeLocationIntentService.class.getName());
}
@Nullable
@chrisjeon
chrisjeon / ToiletMapsFragment.java
Created January 1, 2017 18:36
Toilet Maps Fragment giving permissions to google maps
package com.toasterbits.toiletfinder;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
a = 1
b = 2
c = 3
d = 4
e = 5
# no guard clause
if a > b
if b > c
if d > e
profilePhotoUri.getRealPath();
File profileImageFile = new File(getRealPathFromURI(profilePhotoUri));
private String getRealPathFromURI(Uri contentUri) {
String result;
Cursor cursor = getContext().getContentResolver().query(contentUri, null, null, null, null);
if (cursor == null) {
result = contentUri.getPath();
} else {
cursor.moveToFirst();
int indx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
File imageFile = new File(profilePhotoUri.getPath());