Categories
SwiftUI

SwiftUI: Markdown support for string variables

struct MarkdownTest: View {
  var text: String = "**Hello** *World*"
  var body: some View {
    VStack {
      Text("**Hello** *World*") // will be rendered with markdown formatting
      Text(text) // will NOT be rendered according to markdown
    }
  }
}

Here how to fix.


      Text(.init(text)) // this renders markdown properly
    

Ref: https://developer.apple.com/forums/thread/683632

Categories
Android React-Native

React Native App: Task :app:processDebugMainManifest FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugMainManifest'.
> Unable to make field private final java.lang.String java.io.File.path accessible: module java.base does not "opens java.io" to unnamed module @379b3356

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 8s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081

I had the same problem (JDK 16) and fixed it with:

cd android && gradlew clean
cd ..


npx react-native start

This will run the metro window
then open android studio and let it clean project
run app in android studio

Categories
Unity

Best way to get variable from another script C# unity

public class Bool_Script_To_Access : MonoBehaviour
{
    public bool Smashed_Ant = false;
}
public class Script_To_Do_Stuff : MonoBehaviour
{
    public GameObject ant;
    private Bool_Script_To_Access bool_script;
    private void Start()
    {
        bool_script = ant.GetComponent<Bool_Script_To_Access>();
    }
    private void Update()
    {
        bool_script.Smashed_Ant = true;
    }
}

This is assuming that the two scripts are attached to two separate game objects. Now, in the inspector, select the game object which is attached to Script_To_Do_Stuff. Then, drag the game object which is attached to Bool_Script_To_Access to where it says “ant.” Done. This will work for most cases you’ll have. If you need more general reference to a game object it gets more difficult, and you might want to look into singleton approach.

You might check out the first 15 minutes or so of https://unity3d.com/learn/tutorials/topics/scripting/persistence-saving-and-loading-data
where he creates a GameControl which stores variables that can be accessed from any script. It is a great video

Ref: https://forum.unity.com/threads/best-way-to-get-variable-from-another-script-c-unity.579322/

Categories
Uncategorized

How to fix command not found : code

Step 1: Locate the vs-code executable file.

Step 2 : Edit ~/.bash_profile or  ~/.zshrc

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

Step 3: Restart your terminal to make change and try to open any files with code command again. That’s all!

Hope this help

Categories
Uncategorized

How to store access token securely in React Native

Async Storage#

Async Storage is a community-maintained module for React Native that provides an asynchronous, unencrypted, key-value store. Async Storage is not shared between apps: every app has its own sandbox environment and has no access to data from other apps.

DO USE ASYNC STORAGE WHEN…DON’T USE ASYNC STORAGE FOR…
Persisting non-sensitive data across app runsToken storage
Persisting Redux stateSecrets
Persisting GraphQL state
Storing global app-wide variables

Secure Storage#

React Native does not come bundled with any way of storing sensitive data. However, there are pre-existing solutions for Android and iOS platforms.

iOS – Keychain Services#

Keychain Services allows you to securely store small chunks of sensitive info for the user. This is an ideal place to store certificates, tokens, passwords, and any other sensitive information that doesn’t belong in Async Storage.

Android – Secure Shared Preferences#

Shared Preferences is the Android equivalent for a persistent key-value data store. Data in Shared Preferences is not encrypted by default, but Encrypted Shared Preferences wraps the Shared Preferences class for Android, and automatically encrypts keys and values.

Android – Keystore#

The Android Keystore system lets you store cryptographic keys in a container to make it more difficult to extract from the device.

In order to use iOS Keychain services or Android Secure Shared Preferences, you can either write a bridge yourself or use a library which wraps them for you and provides a unified API at your own risk. Some libraries to consider:

Ref: https://reactnative.dev/docs/security

Categories
React-Native

How to format ISO 8601 date to local date time in moment.js

As your getting date as String, so you need to convert it into Date then you can update formate as you want.

// YOUR_DATE_STRING = 2014-09-08T08:02:17-05:00

const utcDate = moment.utc(YOUR_DATE_STRING).toDate();
const localDate = moment(utcDate).local().format('YYYY-MM-DD HH:mm:ss');
Categories
Android React-Native

Change package name for Android in React Native

I’ve renamed the project’ subfolder from: “android/app/src/main/java/MY/APP/OLD_ID/” to: “android/app/src/main/java/MY/APP/NEW_ID/

Then manually switched the old and new package ids:

In: android/app/src/main/java/MY/APP/NEW_ID/MainActivity.java:

package MY.APP.NEW_ID;

In android/app/src/main/java/MY/APP/NEW_ID/MainApplication.java:

package MY.APP.NEW_ID;

In android/app/src/main/AndroidManifest.xml:

package="MY.APP.NEW_ID"

And in android/app/build.gradle:

applicationId "MY.APP.NEW_ID"

In android/app/BUCK:

android_build_config(
  package="MY.APP.NEW_ID"
)
android_resource(
  package="MY.APP.NEW_ID"
)

Gradle’ cleaning in the end (in /android folder):

./gradlew clean

Ref: https://stackoverflow.com/questions/37389905/change-package-name-for-android-in-react-native

Categories
Firebase

Firebase cloud functions deploy only one function

Assumed you have defined your function like this.

exports.yourfunction = functions.https.onRequest(async (req, res) => {
  functions.logger.info("Hello logs!", { structuredData: true });
});

Deploy your function to google cloud with command: firebase deploy –only functions:function_name

firebase deploy --only functions:yourfunction

You should see the completed deploy result like this.

=== Deploying to 'xxxxxxxx'...

i  deploying functions
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled

...

✔  functions[yourfunction(us-central1)]: Successful update operation. 

✔  Deploy complete!
Categories
PHP

How to convert JSON string to array

If you pass the JSON in your post to json_decode, it will fail. Valid JSON strings have quoted keys:

json_decode('{foo:"bar"}');         // this fails
json_decode('{"foo":"bar"}', true); // returns array("foo" => "bar")
json_decode('{"foo":"bar"}');       // returns an object, not an array.

Ref: https://stackoverflow.com/questions/7511821/how-to-convert-json-string-to-array

Categories
PHP

PHP cURL retrieve response headers AND body in a single request

$url = "https://www.googleapis.com";
$ch = curl_init();
$headers = [];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$body = curl_exec($ch);

// this function is called by curl for each header received
curl_setopt(
    $ch,
    CURLOPT_HEADERFUNCTION,
    function ($curl, $header) use (&$headers) {
        $len = strlen($header);
        $header = explode(':', $header, 2);
        if (count($header) < 2) { // ignore invalid headers
            return $len;
        }

        $headers[strtolower(trim($header[0]))][] = trim($header[1]);

        return $len;
    }
);

$data = curl_exec($ch);
print_r($headers);
print_r($body);

Ref: https://stackoverflow.com/questions/9183178/can-php-curl-retrieve-response-headers-and-body-in-a-single-request