Skip to content

Instantly share code, notes, and snippets.

var blue = require("bluetoothctl");
var sleep = require('sleep');
blue.Bluetooth()
blue.on(blue.bluetoothEvents.Controller, function(controllers){
console.log('Controllers:' + JSON.stringify(controllers,null,2))
});
import subprocess
# from Command import Command
from time import sleep
class CreateConnectionToWifi():
def run(self):
while True:
# for x in range(3):
for n in notifications:
notification_file = self.SERVICES_PATH + n['service'] + "/notifications"
lock = filelock.FileLock(notification_file + '.lock')
try:
with lock.acquire():
with open(notification_file, 'w') as file:
try:
content = json.loads(file.read())
except:
content = []
@miguel-amaral
miguel-amaral / if_last_command_ok.sh
Created June 5, 2018 17:26
Bash Last Command ok or not ok
some_command
if [ $? -eq 0 ]; then
echo OK
else
echo FAIL
fi
@miguel-amaral
miguel-amaral / check.sh
Created June 5, 2018 17:43
Check if element is in array bash
# given the following data
mydata=(a b c "hello world")
for val in a c hello "hello world"
do
# get line # of 1st matching entry
ix=$( printf "%s\n" "${mydata[@]}" | grep -n -m 1 "^${val}$" | cut -d ":" -f1 )
if [[ -z $ix ]]
then
@miguel-amaral
miguel-amaral / check_exit.js
Created June 7, 2018 14:12
Example of dealing with the close of a nodejs process
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
if (options.cleanup) console.log('clean');
if (err) console.log(err.stack);
if (options.exit) process.exit();
}
//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));
@miguel-amaral
miguel-amaral / redirect.sh
Last active September 4, 2018 10:08
forward traffic from port 80 to 8080
# flush current rules (might not apply)
#iptables -t nat -L
# 80 -> 8080
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8080
# 443 -> 8443
iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 443 -j REDIRECT --to-port 8443
@miguel-amaral
miguel-amaral / find_portugal_phone_numbers.sh
Created July 20, 2018 19:05
command for findind all phone numbers inside file
grep -o -P "[9][0-9]{8}" fine_name | uniq
echo "Usage sudo redirect.sh http_port https_port"
http_port=$1
https_port=$2
re='^[0-9]+$'
if ! [[ $http_port =~ $re ]] ; then
echo "error: HTTP PORT Not a number" >&2; exit 1
fi
if ! [[ $https_port =~ $re ]] ; then

Keybase proof

I hereby claim:

  • I am miguel-amaral on github.
  • I am miguelamaral (https://keybase.io/miguelamaral) on keybase.
  • I have a public key ASAIs9Y3FGVCrnr6JDb35gdELL4Z9EJayDjMFo8CEmdlkQo

To claim this, I am signing this object: