Skip to content

Instantly share code, notes, and snippets.

Avatar
🚧
!

Arjun Arjun-sna

🚧
!
View GitHub Profile
View sample_package.json
{
"scripts": {
// ... other scripts
"dev-build-android-staging": "ENVFILE=.env.staging react-native run-android",
"dev-build-android-prod": "ENVFILE=.env.prod react-native run-android",
"release-build-android-prod": "export ENVFILE=.env.prod && cd android && ./gradlew assembleRelease && cd ..",
"release-build-android-staging": "export ENVFILE=.env.staging && cd android && ./gradlew assembleRelease && cd ..",
"start-staging-server": "ENVFILE=.env.staging react-native start",
"start-prod-server": "ENVFILE=.env.prod react-native start",
}
View sampleJavaUse.js
public ReactNativeHost getCodePushKey() {
return BuildConfig.CODEPUSH_ANDROID_KEY;
}
View sampleJSUse.js
import Config from 'react-native-config';
import axios from 'axios';
const response = await axios(GITHUB_OAUTH_ENDPOINT, {
method: METHOD.POST,
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
data: JSON.stringify({
View .env.staging
CLIENT_ID=982****
CLIENT_SECRET=bd51f3***
CODEPUSH_ANDROID_KEY=KAZeMD7***
CODEPUSH_IOS_KEY=KVFoIZBiA****
View .env.prod
CLIENT_ID=982****
CLIENT_SECRET=bd51f3***
CODEPUSH_ANDROID_KEY=KAZeMD7***
CODEPUSH_IOS_KEY=KVFoIZBiA****
@Arjun-sna
Arjun-sna / createReducer.js
Last active Jun 24, 2018
Gist to create reducer in redux
View createReducer.js
export function createReducer(reducerMap, defaultState) {
return (state = { ...defaultState }, action) => reducerMap.hasOwnProperty(action.type) ? reducerMap[action.type](state, action) : state;
}
// Sample usage
posts: createReducer({
[ALL_POSTS_RECEIVED]: (state, action) => {
//do something
},
[POSTS_REQUEST_IN_PROGRESS]: (state, action) => {
@Arjun-sna
Arjun-sna / Previewsize.java
Last active May 24, 2019
Get best preview size for android camera
View Previewsize.java
private static final double MAX_ASPECT_DISTORTION = 0.15;
private static final float ASPECT_RATIO_TOLERANCE = 0.01f;
//desiredWidth and desiredHeight can be the screen size of mobile device
private static SizePair generateValidPreviewSize(Camera camera, int desiredWidth,
int desiredHeight) {
Camera.Parameters parameters = camera.getParameters();
double screenAspectRatio = desiredWidth / (double) desiredHeight;
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
List<Camera.Size> supportedPictureSizes = parameters.getSupportedPictureSizes();
@Arjun-sna
Arjun-sna / TypeFaceEditText.java
Created Feb 21, 2017
Workaround for android `Softkeyboard` hiding `Edittext` and with custom `TypeFace`
View TypeFaceEditText.java
public class TypeFaceEditText extends EditText {
static Map<String, Typeface> inflatedFonts = new HashMap<>();
public TypeFaceEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(attrs);
}
public TypeFaceEditText(Context context, AttributeSet attrs) {
super(context, attrs);
@Arjun-sna
Arjun-sna / SettingsWithSwitch.java
Last active Jun 23, 2018
Switch with TextView using merge layout
View SettingsWithSwitch.java
public class SettingWithSwitch extends RelativeLayout {
TextView settingTitle;
TextView settingState;
SwitchCompat toggleSwitch;
public SettingWithSwitch(Context context) {
super(context);
init(context, null, 0, 0);
}