Skip to content

Instantly share code, notes, and snippets.

View lorenzofelletti's full-sized avatar

Lorenzo Felletti lorenzofelletti

View GitHub Profile
/**
* Checks for a set of permissions. If not granted, the user is asked to grant them.
*
* @param activity The activity that is requesting the permissions
* @param permissions The permissions to be checked
* @param requestCode The request code to be used when requesting the permissions
*/
fun checkPermissions(activity: Activity, permissions: Array<out String>, requestCode: Int)
/**
val permissions = arrayOf(
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.BLUETOOTH_ADMIN,
)
@lorenzofelletti
lorenzofelletti / AndroidManifest.xml
Created October 12, 2022 20:46
BLE Scanning Required Permissions
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
@lorenzofelletti
lorenzofelletti / lexer.py
Created May 21, 2021 14:02
Regex Engine Lexer
from .tokens import *
import numpy as np
class Lexer:
def __init__(self):
self.__digits__ = '0123456789'
pass
def __is_digit__(self, ch):
@lorenzofelletti
lorenzofelletti / tokens.md
Last active May 21, 2021 14:00
Regex Engine in Python Tokens
Token Type (Parent Class) Description
Token The base class from which each token inherits
ElementToken(Token) Each non special char is an element token
WildcardToken(Token) Base class for the wildcard type tokens
Wildcard(WildcardToken) Class for the '.' as wildcard token
StartToken(Token) Base class for the start type tokens
Start(StartToken) Class for '^' as start token
EndToken(Token) See StartToken
End(EndToken) '$' as end token
@lorenzofelletti
lorenzofelletti / features.md
Last active May 10, 2021 22:28
Regex Engine in Python
Feature Syntax
match start ^...
match end ...$
escaping \
grouping (...)
alternative a|b
wildcard .
quantifiers ? * +
curly brace quantification {exact} {min,max} {,max} {min,}
@lorenzofelletti
lorenzofelletti / motogp-2020-championship-standing.csv
Created February 1, 2021 00:13
CSV of the 2020 MotoGP championship standing (riders points race by race)
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 27 columns, instead of 15. in line 9.
race,Joan Mir,Franco Morbidelli,Alex Rins,Andrea Dovizioso,Pol Espargaro,Maverick Vinales,Jack Miller,Fabio Quartararo,Miguel Oliveira,Takaaki Nakagami,Brad Binder,Danilo Petrucci,Johann Zarco,Alex Marquez,Valentino Rossi,Francesco Bagnaia,Aleix Espargaro,Cal Crutchlow,Stefan Bradl,Iker Lecuona,Bradley Smith,Esteve Rabat,Michele Pirro,Mika Kallio,Lorenzo Savadori,Marc Marquez
race 1,0,11,0,16,10,20,13,25,8,6,3,7,5,4,0,9,0,0,0,0,1,2,0,0,0,0
race 2,11,11,6,26,19,40,13,50,8,19,3,7,12,12,16,9,0,3,0,0,5,7,0,0,0,0
race 3,11,31,19,31,19,42,20,59,18,27,28,11,28,13,27,9,6,6,0,0,5,7,0,0,0,0
race 4,31,31,19,56,19,48,36,67,18,37,41,20,28,15,38,9,11,7,0,7,8,7,4,0,0,0
race 5,44,32,29,67,35,48,56,70,43,46,49,25,30,15,45,9,15,7,0,13,8,7,4,0,0,0
race 6,60,57,40,76,41,58,64,70,48,53,53,25,31,15,58,29,18,7,0,15,8,7,4,0,0,0
race 7,80,64,44,84,57,83,64,83,59,63,53,31,36,24,58,29,18,7,0,15,11,7,4,0,0,0
race 8,100,77,60,84,57,90,75,108,59,72,58,39,36,27,58,39,22,13,0,17,11,8,4,0,0,0
race 9,105,77,60,97,73,96,75,115,69,81,62,64,47,4
@lorenzofelletti
lorenzofelletti / playpause.html
Last active October 20, 2020 14:43
PlayPause button using closures
<!DOCTYPE html>
<html>
<body>
<input type='button' id="btn" value='now: true'>
<script src="playpause.js"></script>
</body>
</html>
function playPause() {
let playing = true;
return () => { // () => is equivalent to function() ...in this case
if (playing)
console.log("now stopped");
else
console.log("now playing");
playing = !playing;
}
@lorenzofelletti
lorenzofelletti / closures-simpler-syntax.js
Last active May 7, 2020 10:50
A version of the other gist closure.js but with a simpler syntax for beginners
function makeCounter(initialValue) {
let count = initialValue;
function toString() {
return 'The count is ' + count +'.';
}
return {
add: function() { return ++count },
sub: function() { return --count },
val: function() { return count },
toString: toString