Skip to content

Instantly share code, notes, and snippets.

View balascript's full-sized avatar
💻
cranking...

Bala balascript

💻
cranking...
  • Amazon
  • San Francisco Bay Area
View GitHub Profile
@balascript
balascript / build.gradle
Last active November 23, 2019 02:56
sample settings.gradle
// file: android/app/build.gradle
...
dependencies {
...
compile project(':react-native-ble-manager')
}
@balascript
balascript / MainApplication.java
Last active November 23, 2019 02:59
Auto linking Android post
import it.innove.BleManagerPackage; // <--- import
public class MainApplication extends Application implements ReactApplication {
...
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
// file: android/app/build.gradle
...
dependencies {
...
compile project(':react-native-ble-manager')
}
apply from: "../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"
applyNativeModulesSettingsGradle(settings)
$ npx react-native config
{
"root": "/Users/bala/sample-app/Sample",
"reactNativePath": "/Users/bala/sample-app/Sample/node_modules/react-native",
"dependencies": {
"react-native-ble-manager": {
"root": "/Users/bala/sample-app/Sample/node_modules/react-native-ble-manager",
"name": "react-native-ble-manager",
"platforms": {
"android": {
"android": {
"sourceDir": "/Users/bala/sample-app/Sample/node_modules/react-native-ble-manager/android",
"folder": "/Users/bala/sample-app/Sample/node_modules/react-native-ble-manager",
"packageImportPath": "import it.innove.BleManagerPackage;",
"packageInstance": "new BleManagerPackage()"
}
@balascript
balascript / fetchPhotos.js
Created July 12, 2020 19:14
function to fetch photos from unsplash API for the given keyword, page, and limit (defaults to 10)
import Unsplash, { toJson } from 'unsplash-js';
const unsplashInstance = new Unsplash({
secret: 'Your secret here',
accessKey: 'Your accessKey here',
});
async function fetchPhotos(keyword, page, limit = 10) {
const photoResult = await unsplashInstance.search
.photos(keyword, page, limit)
@balascript
balascript / hooks-unsplashPhotos.js
Last active July 12, 2020 20:02
custom hook to provide photos and fetchMore method to be used as a cursor to Flatlist
function useUnsplashPhotos(keyword) {
const [page, setPage] = useState(1);
// default this to true to kick the initial effect hook to
// fetch the first page
const [shouldFetch, setShouldFetch] = useState(true);
const [photos, setPhotos] = useState([]);
// return this function for Flatlist to call onEndReached
const fetchMore = useCallback(() => setShouldFetch(true), []);
const UnsplashFeed = props => {
const [photos, fetchMore] = useUnsplashPhotos('dogs');
const renderItem = ({ item, index }) => {
const { uri } = item;
return (
<Image
source={{
uri,
}}
@balascript
balascript / .bash_profile
Created August 10, 2020 01:16
My dev machine bash_profile
# /usr/local/etc/bash_completion.d
export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home"
export ANDROID_HOME="/Users/bramdoss/Library/Android/sdk"
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH="$PATH:$JAVA_HOME/bin"