Skip to content

Instantly share code, notes, and snippets.

Avatar
🐢
I may be slow to respond.

Lucio Paiva luciopaiva

🐢
I may be slow to respond.
View GitHub Profile
View ssh-tunneling-quick-example.md

SSH tunneling quick example

General pattern:

ssh bridge-machine -L local-port:destination-machine:destination-port -N

Where bridge-machine is the machine providing an ssh server that will act as a bridge to the destionation-machine. The destionation machine could be, for instance, a database, a Redis server, etc, that is not accessible from your network, but is accessible via another server (the bridge) that you are able to access via SSH.

I always forget which port is the local one is which is the remote. One nice mnemonic is to remember that Left is Local, Right is Remote.

@luciopaiva
luciopaiva / Simple way to get a concurrency issue using async-await.md
Last active Jan 31, 2021
Simple way to get a concurrency issue using async/await
View Simple way to get a concurrency issue using async-await.md

This is a simple example of how to get a concurrency issue in JavaScript while using async/await.

In the initial example, async-concurreny-issue.js, the main function starts two tasks that were supposed to run asynchronously. The big problem here is that runTask() has side effects and changes an internal state represented by currentTaskId. After going through a function call that requires awaiting on a promise (promiseMe()), the task expects currentTaskId to still have the same id assigned to it a couple of lines above. Even if promiseMe() does actually nothing, it will still execute asynchronously. That should be no problem because we are awaiting on it in runTask(), right? Yeah, but the problem is that main() is not doing its job and await is not being used there. This means that main() fires runTask(2) immediately after calling runTask(1), so it runs before the call to promiseMe() has the chance to return - it can only return in the next event loop tick, since it is behind a p

View Faking location on Android.md

Using apps to fake GPS location, like Fake GPS, is not enough to trick some apps into thinking they are somewhere else.

One obvious thing to do is to use a VPN to spoof your ISP location as well, but there's more.

Apps also rely on the "Improve location accurary" that you can find on your Android settings. When that is turned on, geolocation also uses info about nearby wifi and cellular signals. If you turn that option off, the app will tell you it needs location info to work and will refuse to continue. As far as I know, there's no way to circumvent that without rooting the phone or running the app on an emulator.

One easy option, though, is that sometimes apps have equivalent versions running as web apps, and web apps cannot fetch location info as easily. If the app you're trying to use has a web version, just turn the VPN on and you should be able to use it just fine.

If you need to cast to Chromecast, it will probably not work unless you configure the VPN directly into your home router.

@luciopaiva
luciopaiva / debugging-remote-nodejs-processes.md
Last active Dec 25, 2020
Debugging remote Node.js processes
View debugging-remote-nodejs-processes.md

Debugging remote Node.js processes

There are 3 steps involved:

1. send a signal to the process so it enters debug mode

Connect to the remote machine, get the pid of the Node.js process and then run:

kill -usr1 <pid>
@luciopaiva
luciopaiva / gist:87b64d8d47a51d1bb6866b7c9df9bf23
Created Dec 23, 2020
Windows remote desktop access with simultaneous users
View gist:87b64d8d47a51d1bb6866b7c9df9bf23
General steps:
- download Microsoft Remote Desktop app on client machine (check the Apple store)
- enable remote access on host Windows (window key, type "allow remote access" to find the setting)
- test the connection using the Remote Desktop app. Notice that any current logged in users on the host machine will need to log out
- download [RDP Wrapper](https://github.com/stascorp/rdpwrap/releases) - I tested with v1.6.2. The msi installer did not work for me (got an error trying to execute it), but the zip worked fine
- unzip, run install.bat
- run the "*conf*.exe" app that comes with the zip
- it should show all green - if it shows a red "[not supported]", continue below
- get the ini file posted by Damasker [here](https://github.com/stascorp/rdpwrap/issues/1252). As instructed, run `net stop TermService`, replace the ini file in `Program Files/RDP Wrapper`, then `net start TermService`
@luciopaiva
luciopaiva / change-files-timestamps.js
Created Aug 13, 2020
Quick script to change timestamps of files in given directory
View change-files-timestamps.js
/*
* This script changes the timestamps of a series of files in batch. The script will go through all files in
* specified folder, ordering them by name. The first file will be stamped with given start date. The second one will
* be stamped with start date plus 1 second, the third with start date plus 2 seconds, and so on.
*
* But why? I had a series of photos that I wanted to upload to the cloud and their timestamps did not represent the
* actual date when they were taken. The photos were all taken in the same day and I knew what day was that, so I just
* needed a script to do it in batch for me. Also, files were sequentially named by the digital camera, and although I
* didn't know the exact time of day each photo was taken, I could at least preserve the sequence, that's why I decided
* to stamp each one second after the other, ordered by name.
View witchcraft-remote-include-example.js
// @include https://raw.githubusercontent.com/luciopaiva/foo/master/bar.js
View Network perf test with iperf3.md

Network perf test with iperf3

iperf: https://github.com/esnet/iperf

Installation

In case sudo yum install iperf3 doesn't work:

git clone https://github.com/esnet/iperf.git
cd iperf