Skip to content

Instantly share code, notes, and snippets.

View fabiosoft's full-sized avatar

Fabio Nisci fabiosoft

View GitHub Profile
#!/bin/bash
# Descriprion:
# This simple script creates a local sd image backup of a remote raspberry pi in a local folder
# using ssh, dd, and the unix pipe
# Author: Fabio Nisci
# Date: 23/Apr/2014
# Requirements:
# - ssh
# - sshpass (auto installation)
@fabiosoft
fabiosoft / list_diffing.py
Created October 17, 2019 17:05
Array list diffing in python
# Python program to find the missing
# and additional elements
# source: https://www.geeksforgeeks.org/python-find-missing-additional-values-two-lists/
# examples of lists
list1 = [1, 2, 3, 4, 5, 6]
list2 = [4, 5, 6, 7, 8]
# prints the missing and additional elements in list2
print("Missing values in second list:", (set(list1).difference(list2)))
@fabiosoft
fabiosoft / python_equalisty_hash.py
Last active October 30, 2019 09:40
Elegant ways to support equivalence ("equality") in Python classes
#source: https://stackoverflow.com/questions/390250/elegant-ways-to-support-equivalence-equality-in-python-classes
class Number:
def __init__(self, number):
self.number = number
def __eq__(self, other):
"""Overrides the default implementation"""
if isinstance(other, Number):
@fabiosoft
fabiosoft / gist:e16cebdd4c8b072281c559a9f992063b
Created August 28, 2020 18:41 — forked from srosenthal/gist:3adc0dafcdd3c55656bad7a4a8de9c91
Batch convert HEIC (iPhone) photos to JPEG, preserving creation dates
for i in *.heic; do sips -s format jpeg -s formatOptions best "${i}" --out "${i%heic}jpg" && touch -r "${i}" "${i%heic}jpg"; done
@fabiosoft
fabiosoft / AVPlayer_ViewController.swift
Last active January 7, 2021 10:21
AVPlayer Programmatically
import AVFoundation
class ViewController {
private var videoPlayer: AVPlayer?
private var playerItem: AVPlayerItem?
private var layer: AVPlayerLayer?
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
@fabiosoft
fabiosoft / FooterFix.m
Last active July 9, 2021 09:47
Create a UITableView Footer / Header With a Dynamic Height (using AutoLayout). All snippets must be implemented by a UIVIewController subclass
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
if (!self.tableView.tableFooterView){
return;
}
UIView *footerView = (UIView /*you can replace with you concrete type*/ *)self.tableView.tableFooterView;
CGFloat width = self.tableView.bounds.size.width;
CGSize size = [footerView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
if (footerView.frame.size.height != size.height) {
@fabiosoft
fabiosoft / Tree - Breadth_first_search.py
Created September 26, 2021 17:17
Breadth first search
#Breadth first search
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSameTree(self, p: TreeNode, q: TreeNode) -> bool:
from collections import deque
@fabiosoft
fabiosoft / Depth_first_search.py
Last active September 26, 2021 20:50
Tree - Depth first search
def recursive_dfs(graph, source,path = []):
if source not in path:
path.append(source)
if source not in graph:
# leaf node, backtrack
return path
for neighbour in graph[source]:
path = recursive_dfs(graph, neighbour, path)
return path
@fabiosoft
fabiosoft / home_assistant_cam_ptz.yml
Created November 26, 2021 14:45
Add PAN/TILT/ZOOM to onvif, home assistant camera
# paste as a custom (manual) card in lovelace and replace all entities id
type: picture-glance
entities:
- entity: camera.cam_studio_profile_1
tap_action:
action: call-service
service: onvif.ptz
service_data:
entity_id: camera.cam_studio_profile_1
pan: LEFT
blueprint:
name: Detect water and notify
description: detect 'moisture' device-class and if so execute an action.
domain: automation
input:
actions:
name: Actions
description: Notifications or similar to be run. {{sensors}} is replaced with the names of sensors.
selector:
action: {}