Skip to content

Instantly share code, notes, and snippets.

View dftaiwo's full-sized avatar

Femi TAIWO dftaiwo

View GitHub Profile
@dftaiwo
dftaiwo / Code.ino
Created October 6, 2023 10:14
Arduino Ultrasound Code
const int TRIG_PIN = 4;
const int ECHO_PIN = 5;
const int BUZZER_PIN = 3;
const int DISTANCE_THRESHOLD = 30;
// variables will change:
float duration_us, distance_cm;
void setup() {
Serial.begin (9600);
@dftaiwo
dftaiwo / capture_android_screenshot.sh
Created February 17, 2023 09:22
Capture Screenshot off Android
#!/bin/bash
##author - dftaiwo
## Expects that an Android device is connected via ADB on USB/Wifi
filename="$1.png"
if [ $# -eq 0 ]
then
filename="android_screenshot_`date +"%Y-%m-%d_%H-%M-%S"`.png"
fi
@dftaiwo
dftaiwo / loadenv.sh
Created November 23, 2019 04:32
Load Environment Variables from a .env file into a bash script or terminal
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
@dftaiwo
dftaiwo / add_asterisk_required.html
Created January 3, 2018 06:55
Add asterisk * to labels of required fields with javascript and css
<script>
$('input[required], select[required],textarea[required]').each(function(){$($(this).parent()).find('label').addClass('required')});
</script>
<style>
.required:after{
content:" *";
font-weight:bold;
color:red;
}
{
"rules": {
"articles": {
".read": "root.child('users').child(auth.uid).child('subscribed').val() == true"
}
}
}
@dftaiwo
dftaiwo / fb8.json
Created January 20, 2017 07:37
Make sure a user's 'created' field is never a future date
{
"rules": {
"users": {
"$user": {
"created": {
".validate": "newData.val() < now"
}
}
}
}
@dftaiwo
dftaiwo / fbrules-7.json
Last active January 6, 2017 13:11
Firebase Rules - only messages from the last ten minutes can be read
"messages": {
"$message": {
".read": "data.child('timestamp').val() > (now - 600000)"
}
}
@dftaiwo
dftaiwo / fbrules-5.json
Created January 6, 2017 13:00
Firebase Rules settings which fields must be sent
{
"rules": {
"profiles":{
".validate": "newData.hasChildren([
'age',
'first_name',
'last_name',
'state'
])"
}
@dftaiwo
dftaiwo / fbrules-4.json
Created January 6, 2017 12:45
Only authenticated users can read, the user can only write to his own node and No one can create a new node apart from within the /users node
{
"rules": {
".read":"auth.uid != null",
".write":false,
"users": {
"$uid": {
".write": "$uid == auth.uid"
}
}
}
@dftaiwo
dftaiwo / fbrules-3.json
Created January 6, 2017 12:40
Grants a user write access on /users/<auth.uid>/ to the user whose unique ID matches the dynamic path, $user_id.
{
"rules": {
"users": {
"$user_id": {
".write": "$user_id === auth.uid"
}
}
}
}