Skip to content

Instantly share code, notes, and snippets.

View luciopaiva's full-sized avatar
🐌
I may be slow to respond

Lucio Paiva luciopaiva

🐌
I may be slow to respond
View GitHub Profile
@luciopaiva
luciopaiva / Faking location on Android.md
Created January 6, 2021 23:26
Faking location on Android

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 / Simple way to get a concurrency issue using async-await.md
Last active January 31, 2021 20:24
Simple way to get a concurrency issue using async/await

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

@luciopaiva
luciopaiva / ssh-tunneling-quick-example.md
Created June 4, 2021 19:42
SSH tunneling quick example

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 / aseprite-clion.md
Last active March 5, 2022 13:56
How to build aseprite via CLion on Windows

ase128 clion_logo_300x300a

The aseprite docs help with building it from the command line. Here I show how to build it via CLion. It is surprinsingly simple!

First, follow the instrucions in INSTALLATION.md. I will summarize here what I had to follow when building tag v1.3-beta11:

  1. Clone the repo with its submodules;
  2. Either stay in the main branch or switch to the desired tag. For example, this is how I switched to v1.3-beta11:

git checkout tags/v1.3-beta11 -b v1.3-beta11

@luciopaiva
luciopaiva / index.md
Created February 28, 2023 16:46
Conditionally add property to JavaScript object

Conditionally add property to JavaScript object

I had to look this up on the internet so many times during the years that I decided to write this Gist to see if I memorize it once for all (or at least I have a quick place to look next time).

Say your code creates an object and there's a particular property that it sometimes needs to add, sometimes it doesn't. The straightforward way of coding this would be:

const x = {
  a: 1
};
@luciopaiva
luciopaiva / README.md
Last active January 4, 2024 16:22
Protobuffer-safe bytes for proprietary protocol formats

Protobuffer-safe bytes for proprietary protocol formats

In a situation where peers can exchange messages in either protobuf or a proprietary format, there must be a way for the recipient to identify whether the incoming message is a protobuf or not.

The simplest solution for that would be to add a header to each message informing the recipient what the payload type is. Let's say, however, that there is an existing protocol using protobuf messages and a proprietary format option must be added without breaking compatibility with existing implementations.

The idea is to pick a byte that will be sent at the beginning of the message and will let the recipient know for sure if it's a protobuf or proprietary format. For that, one has to answer the question: what values are valid first bytes in a protobuf message?

From the documentation: