<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Saifur Rahman Mohsin</title>
    <description>The latest articles on DEV Community by Saifur Rahman Mohsin (@mohsin).</description>
    <link>https://dev.to/mohsin</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F431100%2F2ded59a9-8b5b-45bf-99d2-4e644fc69aab.jpeg</url>
      <title>DEV Community: Saifur Rahman Mohsin</title>
      <link>https://dev.to/mohsin</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mohsin"/>
    <language>en</language>
    <item>
      <title>Scaring a stray cat away using ML</title>
      <dc:creator>Saifur Rahman Mohsin</dc:creator>
      <pubDate>Sat, 19 Nov 2022 20:04:45 +0000</pubDate>
      <link>https://dev.to/mohsin/scaring-a-stray-cat-away-using-ml-4o1k</link>
      <guid>https://dev.to/mohsin/scaring-a-stray-cat-away-using-ml-4o1k</guid>
      <description>&lt;p&gt;I recently began to face an issue at my place that was causing a lot of stress. A stray cat wandered into my apartment and started to poop on my doormat. First, I thought it was a one-off and had the rug washed. But then it did it again. I then kept my doormat in for a couple of weeks and put it back later hoping the cat got a different place to relieve itself. But this continued.&lt;/p&gt;

&lt;p&gt;So I figured let's use technology and put my Raspberry Pi Zero to a different use than just a &lt;a href="https://dev.to/mohsin/enabling-my-iot-devices-on-apple-watch-alc"&gt;homebridge server&lt;/a&gt;. So I purchased &lt;a href="https://robu.in/product/5mp-raspberry-pi-camera-module-w-hbv-ffc-cable" rel="noopener noreferrer"&gt;a pi camera module&lt;/a&gt;, and began to code away. Took me a couple of days to get the whole thing running coz I had to juggle between an ongoing freelance project and this fun personal project but I was quite satisfied with the end result. The crazy thing is that I've never worked with Python in the past so this was technically my first python project.&lt;/p&gt;

&lt;p&gt;Anyway, without further ado, here's how a video demo of me setting this up:&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/Ii_dgGC3IoM"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;The way it works is this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Keep the camera video open and running forever.&lt;/li&gt;
&lt;li&gt;Whenever there's a motion detected, start the recording and detection process.&lt;/li&gt;
&lt;li&gt;The recording basically stored video continuously until motion stops for at-least 5 seconds, so I get a nice slice of recorded motion (however long it maybe).&lt;/li&gt;
&lt;li&gt;The detection process takes one image every 10 seconds, sends it to Amazon Rekognition where their deep learning algorithm classifies labels on the image. If there is a cat then it sounds an alert.&lt;/li&gt;
&lt;li&gt;The alert is basically a dog barking sound that should scare the cat away. While there is no audio, I would still get a recording of this in action so if that happens, I'll post that here. In the meantime, here's a demo of the project barking to a cat image from the internet:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/4e4OTL9MR1c"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;I'm yet to actually see if this solves my cat issue and am more curious if the cat "figures it out". Will add some videos with results when it happens. Also, it would be interesting to try using a different group of sounds to see if that behaviour changes. Anyway, if you're interested to look at the code, feel free to check it out here.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/mohsin" rel="noopener noreferrer"&gt;
        mohsin
      &lt;/a&gt; / &lt;a href="https://github.com/mohsin/cat-detection" rel="noopener noreferrer"&gt;
        cat-detection
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A cat detector and scarer using Raspberry Pi Zero
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Cat Detection&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Introduction&lt;/h3&gt;
&lt;/div&gt;
&lt;p&gt;I recently started facing an issue--a wild cat was pooping outside my apartment on my doormat. I figured it would be a good time to put the Raspberry Pi to use to scare the cat away.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Setup&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;First install all the dependencies using:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;pip install -r requirements.txt&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;As you see in requirements, the AWS CLI is installed so you would need to link the AWS API credentials to the AWS console. Once complete, you can run the program.&lt;/p&gt;
&lt;p&gt;I have added a setup mode for convience so you can setup and align the camera to the field of view properly before running it properly. You can enter setup mode using:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;python main.py --setup&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Click to see introduction on youtube:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Ii_dgGC3IoM" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/0f61b119c9307d6406f5415cc1b4c5506f443129a081fd7f47d6a8ece0fac693/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f49695f6467474333496f4d2f302e6a7067" alt="Demonstration of the project setup mode"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Solution&lt;/h3&gt;

&lt;/div&gt;
&lt;p&gt;This code makes a dog barking sound whenever a cat comes into the view of the pi camera, thus scaring the cat away.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Click to see demonstration&lt;/strong&gt;…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/mohsin/cat-detection" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>nextjs</category>
      <category>vite</category>
    </item>
    <item>
      <title>Enabling my IoT devices on Apple Watch</title>
      <dc:creator>Saifur Rahman Mohsin</dc:creator>
      <pubDate>Wed, 09 Nov 2022 19:48:12 +0000</pubDate>
      <link>https://dev.to/mohsin/enabling-my-iot-devices-on-apple-watch-alc</link>
      <guid>https://dev.to/mohsin/enabling-my-iot-devices-on-apple-watch-alc</guid>
      <description>&lt;p&gt;I recently purchased an Apple Watch Ultra, which is an excellent watch if you love swimming, scuba diving, hiking, adventure and other sports. Besides those, it's also a regular watch with the entire Apple eco-system. In my house, I use a bunch of IoT devices to make my life easy i.e. geysers, lights, roomba, etc. which has some automation and control from wherever. So far, I have been using them thro' Alexa and Google Home, which are supported by these devices. However, none of them support Apple HomeKit which means I cannot ask Siri to do this... do that. This is unfortunate because I want to be able to do that thro' the Apple eco-system. I have 2 options:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Run Wireshark and collect traffic while using these devices, document the protocol/API calls and then re-create them as a native Watch app.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;a href="https://homebridge.io"&gt;HomeBridge&lt;/a&gt; and install it on my Raspberry Pi Zero W and that acts as a bridge to allow my devices to be seen on Apple Home App, which currently is configured to shout "Cat detected" through Alexa using a webhook when it's camera detects a cat walking by (long story!).&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I went with 2, as it's easier and simpler to implement and I already have everything I need. Here are the instructions for anyone who would like to re-create it.&lt;/p&gt;

&lt;p&gt;First, go through the usual installation of &lt;a href="https://www.raspberrypi.com/software/operating-systems"&gt;RaspianOS&lt;/a&gt; on your  Pi device (I use lite because it's faster on my Pi Zero W which has limited resources):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Find the device identifier of the connected SD card using:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;diskutil list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mine was &lt;code&gt;/dev/disk4&lt;/code&gt; and then burn the image into the device using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo gdd if=2022-09-22-raspios-bullseye-armhf-lite.img of=/dev/disk4 bs=64M status=progress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, the file ends with .img so I had already extracted the .xz file using macOS native Archive Utility. If not, you would have to do that.&lt;/p&gt;

&lt;p&gt;Possible errors: If the gdd command throws an error:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;gdd: failed to open '/dev/disk4': Resource busy&lt;/code&gt;
Then you need to unmount the SD card first using diskutil:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;diskutil unmountDisk /dev/disk4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;gdd: failed to open '/dev/disk4': Operation not permitted&lt;/code&gt;
The other alternative is a locked SD card in which case you need to confirm that it's not locked.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And then it takes a while to burn the OS into the card. I usually run &lt;code&gt;caffeinate -dismut 65535&lt;/code&gt; and set my brightness to 0 and take a break.&lt;/p&gt;

&lt;p&gt;Finally, I create a &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; in the root of the pen drive where the image was written &lt;a href="https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-networking-2"&gt;with my WiFi details&lt;/a&gt;, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;country=IN
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
 scan_ssid=1
 ssid="MyWiFiSSID"
 psk="MyWifiPassword"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I also drop an empty file with filename as &lt;code&gt;ssh&lt;/code&gt;, that enables SSH on the Pi during the first boot. One of the annoying things about RaspianOS is that if you mess up this last part and boot it up once without a &lt;code&gt;wpa_supplicant.conf&lt;/code&gt; or &lt;code&gt;ssh&lt;/code&gt;, you have to burn the image again from scratch as these files are taken in during first-boot only!&lt;/p&gt;

&lt;p&gt;Of course, in the past, I've gotten annoyed with this to the point where I used a mini-HDMI to HDMI cable along with a USB keyboard to connect to it, then use &lt;code&gt;raspi-config&lt;/code&gt; to change the config from the inside but that's a lot of work for me esp. moving monitors, using USB converters, etc.&lt;/p&gt;

&lt;p&gt;Anyway, once it's completed. You can stick the SD into the PI and then boot it. It will connect to the Wifi with it's default hostname &lt;code&gt;raspberrypi.local&lt;/code&gt;. This is useful to connect to it later without looking up the IP address.&lt;/p&gt;

&lt;p&gt;Then I open a terminal on my mac and connect like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ssh pi@raspberrypi.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I believe the default password is either &lt;code&gt;raspberry&lt;/code&gt; or &lt;code&gt;alpine&lt;/code&gt;. I usually setup a custom username which you can by specifying the username and hashed password during the initial setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Homebridge
&lt;/h3&gt;

&lt;p&gt;Now for the fun part. Well, there's already good &lt;a href="https://github.com/homebridge/homebridge/wiki/Install-Homebridge-on-Raspbian"&gt;instructions here&lt;/a&gt; and now that you are ssh-ed into the pi, you just have to run those commands and follow the instructions. Finally, open your browser and paste in the URL in the format shown in the wiki or just put &lt;code&gt;http://raspberrypi.local:8581&lt;/code&gt; as it will resolve the hostname and open it too. It should open HomeBridge's Web UI.&lt;/p&gt;

&lt;p&gt;Now open the Home app on your iPhone and click Add Accessory. It will open a scanner and you can click on the HomeBridge status page to find a big QR code for "pairing" on the left sidebar. Scan that code and it will set up the Homebridge Hub on your phone (make sure you're on the same Wi-Fi network). Once it's setup, it will appear not on the accessory list but inside &lt;code&gt;Home Settings -&amp;gt; Home Hubs &amp;amp; Bridges&lt;/code&gt; of the Settings section.&lt;/p&gt;

&lt;p&gt;Now you have to manually add the plugins that target the IoT devices at your home. So the way this works is that home bridge acts as an interface to connect those IoT devices to Apple's Home app. Those plugins are generally written targeting each IoT manufacturer and their protocols/APIs to interact with the device in it's format and homebridge converts it so it uses HomeKit APIs.&lt;/p&gt;

&lt;p&gt;For example, in my case I have a Xiaomi Vaacuum Roomba at home so I installed the homebridge-miot plugin to enable it to be discovered. Ensure you see a verified badge next to the plugin listing for "official" plugins, that are more trustable. Once I set it up with my Mi Cloud Account ID and password, it detected and added my Roomba to the Accessories. Now I can control it via the app, and in extension, my Watch.&lt;/p&gt;

&lt;h4&gt;
  
  
  Bonus -- Setting up custom username/password
&lt;/h4&gt;

&lt;p&gt;I'm sure some users would want to change the username password to a custom one. If you &lt;a href="https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user"&gt;saw the documentation section on this&lt;/a&gt; it would suggest running &lt;code&gt;openssl passwd -6&lt;/code&gt; on the pi system, type in the passwd and then get the credential and use that in the initial text file. This is annoying because the headless pi might not be easy to access initially. I use a microUSB to female-USB cord to connect a keyboard to my pi so I could type keys. Here's what I did to send back the key to my machine.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Generate the key and save it.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl passwd -6 &amp;gt; key.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Send it online to &lt;a href="https://www.file.io"&gt;file.io&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -F "file=@key.txt" https://file.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Their service lets you upload stuff from the command line. The returned JSON will have a short URL which you can easily type into your phone and get the key.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Fixing a broken youtube live video download</title>
      <dc:creator>Saifur Rahman Mohsin</dc:creator>
      <pubDate>Wed, 02 Nov 2022 05:29:01 +0000</pubDate>
      <link>https://dev.to/mohsin/fixing-a-broken-youtube-live-video-download-i9</link>
      <guid>https://dev.to/mohsin/fixing-a-broken-youtube-live-video-download-i9</guid>
      <description>&lt;p&gt;I usually download videos using &lt;a href="https://youtube-dl.org"&gt;Youtube-dl&lt;/a&gt;. In fact, it's one of my default programs that's install on &lt;a href="https://github.com/mohsin/dotfiles/blob/master/brew.sh#L38-L39"&gt;any new machine&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So earlier today, I was downloading a "live" youtube video which was to be live the whole day. I needed a specific part i.e. a single event so I ran youtube-dl on it's live URL at the beginning of the event, ran &lt;code&gt;caffeinate -dismut 65535&lt;/code&gt;, set my mac brightness to 0 and left for my daily routine.&lt;/p&gt;

&lt;p&gt;I came back after an hour when the event ended, and hit Ctrl+C hoping to get the final video but then I got this in my log:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;^C[ffmpeg] Interrupted by user
&lt;span class="o"&gt;[&lt;/span&gt;ffmpeg] Downloaded 370933808 bytes
&lt;span class="o"&gt;[&lt;/span&gt;download] 100% of 353.75MiB &lt;span class="k"&gt;in &lt;/span&gt;01:02:40
Mohsin@Mozs-MacBook-Pro Desktop % &lt;span class="o"&gt;[&lt;/span&gt;https @ 0x12800b800] Opening &lt;span class="s1"&gt;'http://SomeLongURL/playlist/index.m3u8'&lt;/span&gt; &lt;span class="k"&gt;for &lt;/span&gt;reading
Error writing trailer of file:SomeEvent.mp4: Immediate &lt;span class="nb"&gt;exit &lt;/span&gt;requested
&lt;span class="nv"&gt;frame&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;112801 &lt;span class="nv"&gt;fps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; 21 &lt;span class="nv"&gt;q&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;-1&lt;/span&gt;.0 &lt;span class="nv"&gt;Lsize&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;  362240kB &lt;span class="nb"&gt;time&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;01:02:40.08 &lt;span class="nv"&gt;bitrate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; 789.2kbits/s &lt;span class="nv"&gt;speed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0.717x
video:303393kB audio:59858kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Error closing file file:SomeEvent.mp4: Immediate &lt;span class="nb"&gt;exit &lt;/span&gt;requested
Exiting normally, received signal 2.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this &lt;code&gt;Error writing trailer of file:SomeEvent.mp4&lt;/code&gt; was not ideal. This meant that the mp4 file that the mp4 container of the video file that was saved did not have a proper terminating trailer. Videos have a header/trailer and it's specification on how that is, depends on it's format. And this meant that when I opened the video on VLC, it threw an error than playing. I needed to fix this in order to watch the video.&lt;/p&gt;

&lt;p&gt;And that's when I found &lt;a href="https://github.com/ponchio/untrunc"&gt;untrunc&lt;/a&gt; but that's originally written to work on Linux machines. I run MacOS and that too ARM (M1), so I would have to compile it from source. Fortunately, unlike the initial days since it's release, Docker works great on Apple Silicon machines and I can install this tool inside and use it.&lt;/p&gt;

&lt;p&gt;The tool needs a working "reference" to fix the video so I ran youtube-dl again on the live video and took a small clip. This time, it terminated correctly and so I put them both in a &lt;code&gt;videos&lt;/code&gt; folder with &lt;code&gt;SomeEvent.mp4&lt;/code&gt; and &lt;code&gt;reference.mp4&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Then I cloned the untrunc repo, and ran the docker build using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone git@github.com:ponchio/untrunc.git
docker build &lt;span class="nt"&gt;-t&lt;/span&gt; untrunc &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And once the docker build was done, I ran the final command to fix the video:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-v&lt;/span&gt; ~/Desktop/videos:/files untrunc /files/reference.mp4 /files/SomeEvent.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It gave an output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reading: /files/reference.mp4
[mov,mp4,m4a,3gp,3g2,mj2 @ 0xaaaacabcda80] multiple edit list entries, a/v desync might occur, patch welcome
Repair: /files/SomeEvent.mp4
Mdat not found!
Processed: 1%
...
...
Processed: 99%
Found 274677 packets.
Found 112779 chunks for avc1
Found 161898 chunks for mp4a
Saving to: /files/SomeEvent_fixed.mp4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that was how I was able to recover the broken mp4 file. Hope this article helps anyone facing the same issue. Feel free to drop a comment if it does.&lt;/p&gt;

</description>
      <category>youtube</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Recovering a mySQL instance from another user account (macOS)</title>
      <dc:creator>Saifur Rahman Mohsin</dc:creator>
      <pubDate>Fri, 25 Dec 2020 13:51:49 +0000</pubDate>
      <link>https://dev.to/mohsin/recovering-a-mysql-instance-from-another-user-account-macos-5e15</link>
      <guid>https://dev.to/mohsin/recovering-a-mysql-instance-from-another-user-account-macos-5e15</guid>
      <description>&lt;p&gt;I was using my friend's mac temporarily until my own was being serviced. So earlier this week, I deleted my user account on his mac which had a bunch of databases that I needed. I had backed up most of the user data before deleting that account but soon I realized that I missed out backing up the database. The fortunate thing and possibly the reason for this is that the database data directory generally resides outside the user account. In this article, I'll mention bullet points of how I got back this DB data using my friends user account (or you can even create a new one and do the same steps).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensure mariadb is still installed by running &lt;code&gt;brew install mariadb&lt;/code&gt;.
I found that it was available but homebrew did not have access to the install directory since it was created from a different user account. So first we recover this by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;whoami&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; /usr/local/bin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the command threw an error dump showing which folders it doesn't have access to, you can run the same command for each of the folders. I also ran &lt;code&gt;brew upgrade mariadb&lt;/code&gt; to stay upto data with the newer mariadb install (although I wouldn't advise running this generally until you've backed up the databases).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next you have to figure out which data directory mariadb uses and run chown on that as well. This can be done by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew services list
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will give a list of the running services and their run configurations. Just open the mariadb tasks' config and see the parameter &lt;code&gt;--datadir&lt;/code&gt; in the XML--should be inside arguments block. In my case, this was &lt;code&gt;--datadir=/usr/local/var/mysql&lt;/code&gt;. Now copy that path and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo chown&lt;/span&gt; &lt;span class="nt"&gt;-R&lt;/span&gt; &lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;whoami&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt; /usr/local/var/mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, you may wonder, why not simply copy the data directory into one's own mac and then open the database directly? The issue here is that the folder has only &lt;strong&gt;.ibd&lt;/strong&gt; and &lt;strong&gt;.frm&lt;/strong&gt; files &lt;a href="https://dba.stackexchange.com/a/16911"&gt;which really aren't importable&lt;/a&gt; by mySQL. So I have to run the mysql server again with this data dir and then export it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, I had to stop any ongoing mysql server to ensure that I can start mysql smoothly. I do this by running:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew services stop mariadb
ps aux | &lt;span class="nb"&gt;grep &lt;/span&gt;mysql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The last command is to check that there are no other mysql instances running. If the command returns any processes running mysql, then those need to be killed using kill -9 command or else, open Activity Monitor, use search to filter down mysql and force kill them manually.&lt;/p&gt;

&lt;p&gt;Now, the fresh mysql instance can be started by using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;brew services start mariadb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively, you can even call the program found at the bin folder mentioned in the XML file of the homebrew service configuration i.e. take the first program string and replace &lt;code&gt;mysqld_safe&lt;/code&gt; to &lt;code&gt;mysql.server start&lt;/code&gt; and run the command. In my case, I did this by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/usr/local/opt/mariadb/bin/mysql.server start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will return SUCCESS! if the service starts successfully. Otherwise, you would have to check the error logs (was in &lt;code&gt;/usr/local/var/mysql&lt;/code&gt; folder for me) to figure out what went wrong and solve it by some googling.&lt;/p&gt;

&lt;p&gt;And that's pretty much it, you can now backup the databases as you would normally do. I do this by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysql &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="nt"&gt;-p&lt;/span&gt;&amp;lt;password&amp;gt;
show databases
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this would give a list of all the databases. And then execute the backup command for each database you want to backup as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;mysqldump &lt;span class="nt"&gt;-u&lt;/span&gt; root &lt;span class="nt"&gt;-p&lt;/span&gt;&amp;lt;password&amp;gt; dbname &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; dbname.sql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's pretty much how it's done. And I airdropped the databases to my own laptop and was done.&lt;/p&gt;

</description>
      <category>mysql</category>
      <category>mariadb</category>
      <category>recovery</category>
      <category>database</category>
    </item>
    <item>
      <title>How to overcome censorship by using tor system-wide on macOS</title>
      <dc:creator>Saifur Rahman Mohsin</dc:creator>
      <pubDate>Sat, 07 Nov 2020 09:16:36 +0000</pubDate>
      <link>https://dev.to/mohsin/how-to-overcome-censorship-by-using-tor-system-wide-on-macos-354e</link>
      <guid>https://dev.to/mohsin/how-to-overcome-censorship-by-using-tor-system-wide-on-macos-354e</guid>
      <description>&lt;p&gt;Today, I will demonstrate how one can use the &lt;code&gt;tor&lt;/code&gt; program as a system-wide proxy on macOS and thereby avoid censorship and gain anonymity.&lt;/p&gt;

&lt;p&gt;Step 1: Install tor&lt;br&gt;
You can do this from your Terminal, simply by running&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;brew install tor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Add the custom script to your &lt;code&gt;.bash_profile&lt;/code&gt;&lt;br&gt;
You can find the script at &lt;a href="https://github.com/SaifurRahmanMohsin/dotfiles/blob/d6e4a5b0a99207da5c8910ef033105d6ba05e29d/.functions#L216-L241"&gt;my github repo&lt;/a&gt;. Copy the 2 functions, and paste it into .bash_profile at the very end.&lt;/p&gt;

&lt;p&gt;Step 3: Reset your terminal&lt;br&gt;
For the functions to reload, you have to close and open the terminal app. Once done, you can run &lt;code&gt;starttor&lt;/code&gt; and walla, it will start the tor network and show this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YpAnAwT6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/nrrvzjt5i3ogk1uwaiop.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YpAnAwT6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/nrrvzjt5i3ogk1uwaiop.png" alt="Screenshot 2020-11-07 at 2.43.49 PM" width="800" height="322"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And that's pretty much it. Surf the web anonymously now, and when you're done, go back to the terminal and hit Ctrl+C and it will cancel the tor relay.&lt;/p&gt;

&lt;p&gt;Caveat: In case, the tor relay fails to cancel for some reason, the proxy will still be using the tor port and therefore the entire web will be unavailable. Simply run &lt;code&gt;stoptor&lt;/code&gt; if this happens and it will clear up the proxy back to it's default setting i.e. no proxy.&lt;/p&gt;

&lt;p&gt;For those who prefer a video version of the same, check this out:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=%20LrbsolUx34A"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e9bgxrQo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://img.youtube.com/vi/LrbsolUx34A/0.jpg" alt="Youtube Demo" width="480" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>censorship</category>
      <category>tor</category>
      <category>banned</category>
      <category>anonymous</category>
    </item>
  </channel>
</rss>
