Skip to content

Instantly share code, notes, and snippets.

View fabiosoft's full-sized avatar

Fabio Nisci fabiosoft

View GitHub Profile
@fabiosoft
fabiosoft / rc.local
Created December 20, 2016 15:28
Raspberry pi original rc.local boot file
#!/bin/sh -e
#/etc/rc.local
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
@fabiosoft
fabiosoft / toggle_device_after_time.yaml
Last active September 22, 2022 22:11 — forked from derekoharrow/toggle_device_after_time.yaml
Home Assistant Blueprint to toggle a device after a period of time since state was set
blueprint:
name: Toggle device status after a period of time
description: "Once a device has been in a defined status for a period of time, toggle it's status"
domain: automation
input:
trigger_device:
name: Device
description: Which device to monitor and toggle?
selector:
entity:
@fabiosoft
fabiosoft / Program.cs
Created February 2, 2017 10:10
C# Sudoku Generator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static int[,] grid = new int[9, 9];
@fabiosoft
fabiosoft / NSObject.m
Created May 4, 2022 13:57
Get all methods of an Objective-C class or instance
// Either in lldb:
(lldb) po [self _methodDescription]
//or in code:
@interface NSObject (Private)
- (NSString*)_methodDescription;
@end
// Somewhere in the code:
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: {}
@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
@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 / 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 / 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 / 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)