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 / index.css
Last active May 3, 2021 07:08
Read/write CSS variable in Javascript
:root {
--app-width: 1000px;
--some-calculation: calc(var(--app-width) + 1);
}
@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 / 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 / debugging-remote-nodejs-processes.md
Last active December 25, 2020 16:58
Debugging remote Node.js processes

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 / walksync.js
Last active October 29, 2020 20:24 — forked from kethinov/walksync.js
List all files in a directory in Node.js recursively in a synchronous fashion
#!/usr/bin/env node
const
path = require("path"),
fs = require("fs");
/**
* List all files in a directory recursively in a synchronous fashion
*
* @param {String} dir
// @include https://raw.githubusercontent.com/luciopaiva/foo/master/bar.js
console.info("HULLO");
.foo {}
/* @include other.css */
.bar {}
// @include my-script.js
// @include "some other script.js"
/* @include third-script.js */
setup(); // `setup` is defined in `my-script.js`
@luciopaiva
luciopaiva / Network perf test with iperf3.md
Created February 17, 2020 19:33
Network perf test with iperf3

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