Resolving Git Errors: Fixing 'Invalid HEAD' and Broken References

<p>Hi devs, today I encountered some serious issues with my local Git repository. I was working on my project, and then all of a sudden, something happened while I was committing to my GitHub repository, my laptop went off. When I later opened my vscode IDE, I saw that I had 185 changes in the git source control. I did not work on so many files, and the last time I worked, it was on four files only meaning i suppose to have 4 changes in the source control. Having this type of error for the first time can be so terrifying, and it was there because of some corrupt files in the local Git repository due to not completing the operation.</p><p><br></p><p>Even though I was able to make updates on the GitHub website and send them for production, I do need to be coding locally with my vscode IDE.</p><p><br></p><p><strong>Understanding the Problem</strong></p><p><br></p><p>When working with Git, you might encounter various issues. In this case, after running the command "git fsck", which attempts to repair the repository, it diagnosed the Git errors to be:</p><p><br></p><p>⦁ error: invalid HEAD</p><p>⦁ error: bad ref for .git/logs/HEAD</p><p>⦁ error: bad ref for .git/logs/refs/heads/main</p><p>⦁ fatal: cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/main': reference broken</p><p><br></p><p>These types of errors often arise when there is a disruption during Git operations, such as committing changes or performing a rebase. An unexpected shutdown due to power failure can leave your Git repository in a corrupted state. These errors can be particularly frustrating, but with the right approach, you can get your repository back to a stable state.</p><p> </p><p><strong>Steps I Took to Fix The Error</strong></p><p><br></p><p>Note that there are other, possibly better, ways to fix this type of error. However, I am sharing how I was able to fix mine.</p><p><br></p><p><strong>1. Backup Your Repository:</strong> First and foremost, you must backup your repository to ensure you don't lose your code. If anything goes wrong, you can easily restore your code from the backup.</p><p><br></p><p><strong>2. Create a New Folder and Initialize Git:</strong> Create a new folder and initialize a new Git repository in that folder. You can do this by running the following command:</p><p><br></p><p> git init</p><p><br></p><p><strong>3. Add Remote Origin:</strong> After initializing the new Git repository, add the remote origin of your original project, which is experiencing the error. Use the following command:</p><p><br></p><p> git remote add origin https://github.com/Github-user/project-name </p><p><br></p><p><strong>4. Pull the Project:</strong> Pull the entire project into the new folder by running this command:</p><p><br></p><p> git pull origin main</p><p><br></p><p>This will immediately restore all your project files in the new folder.</p><p><br></p><p><strong>5. Install Dependencies:</strong> Run npm install to install all the dependencies in the project. Don’t forget to add files like .env and other files listed in .gitignore from the other project.</p><p><br></p><p><strong>Conclusion</strong></p><p><br></p><p>By following these steps, you will be able to sort out the problem you encountered in your project. This method allows you to quickly resolve Git errors, ensuring that you can make changes to your code and commit them to the original repository without any issues. Remember, backing up your repository is crucial to avoid data loss and maintain a stable workflow. Happy coding!</p>
Create Production ready App for App Store and Play Store with Expo EAS Build

<p>From our previous post we talked about how to create a native app with our pre built next.js website, so today i will be giving you a guide that you can use to create a production ready build with EAS that you can upload to the app store or play store. </p><p>EAS Build is your personal app-building factory in the cloud! It takes your Expo or React Native project and transforms it into a production ready app, ready to to be published on the App Store or Play Store. EAS Build streamlines the entire process by offering pre-configured settings that work perfectly with these frameworks. No more getting worried about complex configurations or app keys! EAS Build can also handle your app signing credentials for you. EAS Build's internal distribution features allows you to Share your app with teammates for testing or collaboration also.</p><p><br></p><p><strong>Prerequisites</strong></p><p><br></p><p>To initiate an eas build you will need to install the eas-cli on your machine. simply run this command from your terminal</p><p><br></p><p>npm install -g eas-cli</p><p><br></p><p>Additionally, you have to create an expo account <a href=" https://expo.dev/signup. " rel="noopener noreferrer" target="_blank"> https://expo.dev/signup. </a> Sign in to the account by entering the following command in your terminal</p><p>eas login</p><p>note that if you've previously signed in to an Expo account using the Expo CLI, you won't need to sign in again.</p><p><br></p><p><strong>Configure the project</strong></p><p><br></p><p>You have to configure the project for both iOS and Android EAS build. To configure an Android or an iOS project for EAS Build, run the following command:</p><p><br></p><p>eas build:configure</p><p><br></p><p>Running the configuration command should provide you with an EAS configuration file (often named eas.json). This file acts will help you in customizing your EAS Build process. the eas build code should look like this: </p><p> </p><p> </p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1715279889396-code%201.png?alt=media&token=7d4efd72-ff79-4227-a1d5-0b0a0c44ccd7"></p><p><br></p><p><br></p><p><strong>Additional Considerations:</strong></p><p><br></p><p>Additional configuration may be required for some scenarios:</p><p><br></p><p>⦁ Does your app code depend on environment variables? Add them to your build configuration.</p><p>⦁ Is your project inside of a monorepo? Follow these instructions.</p><p>⦁ Do you use private npm packages? Add your npm token.</p><p>⦁ Does your app depend on specific versions of tools like Node, Yarn, npm, CocoaPods, or Xcode? Specify these versions in your build configuration.</p><p><br></p><p>next we have to work on the app.json file. this is where we can set the name, version icon, splash image and all other configuration. i recommend that you should ensure that the name of you app starts with a capital letter, also configure the build number and version code which must match your package.json version, because EAS prevents you to submit twice the same app version, so you have to increase it manually to bypass EAS checks. The eas.json code should look like this:</p><p><br></p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1715279976658-code%202.png?alt=media&token=9979697b-594d-486e-b9c0-c2be344398c6"></p><p><br></p><p><strong>Finally build your App For Production</strong></p><p><br></p><p>After you have confirmed that you have a Google Play Store or Apple App Store account and decided whether or not EAS CLI should handle app signing credentials, you can proceed with the following set of commands to build for the platform's store:</p><p><br></p><p>eas build --platform android</p><p><br></p><p>eas build --platform all (This builds for both iOS and Android)</p><p><br></p><p>Sit back and relax while EAS Build handles the app building. The terminal will display the build progress, keeping you informed. Once complete, you will receive a link to your Expo dashboard that leads to your built app.</p><p>For play store you can download the android App Bundle (.aab file). For IOS you can also download the .ipa file. This files is what you need to upload on Google Play Console and Apple Developer Dashboard.</p><p><br></p><p><strong>Looking for More?</strong></p><p><br></p><p>The official EAS Build documentation is a treasure trove of information. Dive deeper for advanced configuration options and explore the full potential of EAS Build:<a href=" https://github.com/expo/eas-cli." rel="noopener noreferrer" target="_blank"> https://github.com/expo/eas-cli.</a></p><p><br></p>
Turn Your Next.js Site into an App: A Guide to Expo Webview

<p>Today we will explore how to leverage Expo's capabilities to build a mobile application using our already built Next.js website. But before we start, let us understand the key players involved.</p><p><br></p><p><strong>what is nextjs, react native and expo?</strong></p><p><br></p><p><strong>Next.js </strong>is an open-source web development framework created by the private company Vercel providing React-based web applications with server-side rendering and static website generation. Next.js is widely used by developers because of its high performance, high SEO ranking, efficiency, and great developer experience. Nextjs gives you building blocks to create fast, full-stack web applications. </p><p><br></p><p><strong>React Native</strong> is an open-source mobile application framework created by Facebook. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, and Windows by enabling developers to use React along with native platform capabilities.</p><p>react native allows you to use a front end framework (React) to code a mobile app. But it's different from Cordova, Ionic or PhoneGap because those front end frameworks allows you to use HTML, CSS and Javascript to create a native application for a variety of mobile platforms. Cordova takes your web app and renders it within a native WebView.</p><p><br></p><p><strong>Expo </strong>is a framework and a platform for universal React applications. It is a set of tools and services built around React Native and native platforms that help you develop, build, deploy, and quickly iterate on iOS, Android, and web apps from the same JavaScript/TypeScript codebase. With Expo you have a framework were you have multiple libraries that can help you to develop and distribute the App. </p><p><br></p><p> <strong>A WebView</strong> is a large-scale software component that is used to display web content within a native application. Its like a web browser that is embedded within an app. The WebView allows a programmer to write the bulk of the application using HTML, JavaScript and CSS which are the standard Web programming tools.</p><p><br></p><p>To start using Expo to build your project is very simple and it won't take you more than 5 minutes.</p><p><br></p><p>First you need to create an expo project. Open your code editor terminal (VS Code) and input this command:</p><p><br></p><p>npx create-expo-app my-app</p><p><br></p><p>replacing "my-app" with your desired project name, Move into the newly created project directory and start the project using this command. </p><p><br></p><p>cd my-app</p><p>npm start</p><p><br></p><p>It will immediately start the Metro Bundler, and it will display the QR code and sometext like:</p><p> Metro waiting on exp://192.168.0.185:8081</p><p><br></p><p>› Scan the QR code above with Expo Go (Android) or the Camera app (iOS)</p><p> you just have to download the expo app from the Play Store (Android) or App Store (iOS). Use the Expo app to scan the displayed QR code.</p><p><br></p><p>And that is it! You have successfully set up your Expo project and established a connection with your mobile device. You can change the name of the project in the package.json file.</p><p><br></p><p> Open the App.js file, this file serves as the entry point for your expo application and will contain some pre-written code to start your development process.</p><p><br></p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1714908940441-expo1.png?alt=media&token=2367649b-3dc5-482e-878c-3d6e6b331b8d"></p><p><br></p><p>Now that we have the Expo project set up, we have to incorporate the react-native-webview component to render our existing Next.js website within the mobile app. Open a separate terminal window within your project directory and execute the following command to install the necessary package:</p><p><br></p><p> npm install react-native-webview</p><p><br></p><p>At the top of the App.js file, import the WebView component from the react-native-webview package. Then we have to remove the View component and replace it with an empty react fragment. Inside this fragment, render the WebView component, specifying the URL of your Next.js website as the source prop. The javaScriptEnabled prop is set to true. This ensures that any JavaScript code within your Next.js website executes properly when displayed in the app.</p><p><br></p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1714909027395-expo2.png?alt=media&token=b665441a-fbca-4bc6-ae38-8610b16cbd1c"></p><p><br></p><p>This post must have equipped you with the knowledge on how to use Expo to integrate your pre-built Next.js website into a mobile application. By following these steps, you have successfully created a foundation for delivering your Next.js website through a mobile app.</p><p><br></p><p>While this guide focused on the core integration, there are other possibilities to explore! Here are some ideas to enhance your mobile app:</p><p><br></p><p><strong>Styling and Customization:</strong> Dont forget to customize the appearance and layout of your webview within the app using stylesheets.</p><p><strong>Expo Features:</strong> Explore the rich set of features offered by Expo, such as push notifications, user authentication, and more, to elevate your mobile app's functionality.</p><p><br></p><p><strong>Optimizing for Performance:</strong> Consider techniques to optimize the loading speed and responsiveness of your Next.js website within the webview for a seamless user experience.</p><p>Remember, this is just the beginning! With your newfound knowledge and the power of Expo, you can craft engaging mobile applications that leverage the strengths of both Next.js and native mobile development.</p><p><br></p><p>Stay tuned for future posts where we will go deeper into these exciting areas and explore more advanced Expo functionalities!</p>
Password Protection Made Easy: Secure Your Web Content in Minutes

<p>Have you ever wanted to add an extra layer of security to specific content on your webpages? Or maybe you've created valuable content and want to monetize it? This tutorial will show you how to create a simple password protection system using HTML and JavaScript.</p><p><br></p><p><strong>Here's how it works:</strong> </p><p><br></p><p><strong>Checking for Access</strong>: When a user visits your webpage, the system first checks their local storage (like a mini-storage compartment on their device) to see if a password is already saved.</p><p><br></p><p><strong>Password Match?</strong> If a password exists in local storage and it matches the correct password you set, the system grants access! It hides the login section and directs the user straight to the protected content they're after.</p><p><br></p><p><strong>Incorrect Password? </strong>If there's no password saved, or the entered password doesn't match, the system displays the password input form, prompting the user to enter the correct password.</p><p><br></p><p><strong>Wrong Password,</strong> Try Again: If the user enters an incorrect password, the system won't give up on them entirely. It will display a message box suggesting they contact you, the owner, to gain access. However, it won't save the wrong password attempt in local storage.</p><p><br></p><p>This is a simplified overview, but it gives you a good idea of how the password protection system functions. In the next sections, we'll delve deeper into the code itself, breaking down each step and explaining how it works line by line.</p><p><br></p><p><br></p><p>Alright, let's start by creating the basic HTML structure. The body tag has an onload attribute set to "load()". This tells the browser to call the load function when the webpage finishes loading.</p><p>We have two key elements:</p><p><br></p><p>⦁ A div element with the ID step1 containing the password input field and a submit button. This is the visible section users will interact with initially.</p><p><br></p><p>⦁ Another div element with the ID step2 that currently holds the hidden content. This section is initially hidden from the user and will likely contain the content you want to protect with the password.</p><p><br></p><p>We'll explore the check function next, which plays an important role in managing content visibility based on password validation.</p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1714837678798-passcode1.png?alt=media&token=fbf2c909-d2e7-44d3-9ddc-5ac3b260523c"></p><p><br></p><p><br></p><p><strong>The check Function: Validating the Password</strong></p><p><br></p><p>The check function plays the most important role, When the user click the submit button. Here's what happens:</p><p>⦁ It takes the value from the password field and stores it in a variable X.</p><p>⦁ It compares the entered value with the correct password (currently set to 100).</p><p>⦁ If it's a match; It hides the password input section and refreshes the page.</p><p>⦁ It unveils the hidden content (step2).</p><p>⦁ If it's wrong password, it will displays an error message in the dialog box.</p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1714837728620-password2.png?alt=media&token=3b50d6d8-9623-4507-ab32-c5d5ebe26f76"></p><p><br></p><p><br></p><p><strong>Remembering the Password</strong></p><p><br></p><p>The load function calls whenever the webpage loads. Here's how it works:</p><p>⦁ It retrieves any password stored in local storage using localStorage.getItem('text') and assigns it to a variable y</p><p>⦁ If y (the saved password) matches the correct password (currently 100 in this example), the function bypasses the login section entirely by hiding step 1(password section) and displays step 2 (the hidden content).</p><p>⦁ If no password is saved, or it doesn't match, the function keeps step1 (the login section) visible</p><p><br></p><p><br></p><p><img src="https://firebasestorage.googleapis.com/v0/b/ripplez-blog.appspot.com/o/blog%2F1714837770270-passcode3.png?alt=media&token=5f370524-838f-4c22-8358-346c16aed846"></p><p><br></p><p><br></p><p>This tutorial explored building a basic password verification system using HTML, CSS, and JavaScript. This system allows you to hide content, granting access only to those who possess the correct password. Here are some potential applications:</p><p><br></p><p>⦁ Monetize Your Content: You could sell access to the hidden content by providing the password to paying customers.</p><p>⦁ Protect Sensitive Information: Use this system to safeguard sensitive information on your webpages, like internal documents or member-only content.</p><p>Security Considerations:</p><p><br></p><p>While this approach offers a simple solution, it's important to remember that storing passwords in local storage is not the most secure method. For real-world applications involving sensitive data, consider implementing server-side authentication for enhanced security.</p><p><br></p><p>In the next post, we'll delve into creating a similar password protection system using Java in Android Studio, allowing you to secure content within a mobile application.</p>