Skip to content

Instantly share code, notes, and snippets.

class Sniffer:
def __init__(self, interface, debug=False):
self._the_interface = interface
self._debug = debug
self._socknum = self._the_interface.get_socket()
assert self._socknum == 0, "MACRAW socket must be socket 0"
def _read_s0cr(self):
while True:
s0_cr = self._the_interface._read_sncr(self._socknum)
@masgari
masgari / low-battery-level-detection-notification-for-all-battery-sensors.yaml
Last active March 1, 2022 20:50 — forked from sbyx/low-battery-level-detection-notification-for-all-battery-sensors.yaml
Home Assistant Blueprint: Low battery level detection & notification for all battery sensors
blueprint:
name: Battery level detection & notification for LiFePO4 battery sensors
description: Regularly test all sensors with 'battery' device-class for crossing
a certain battery level threshold and if so execute an action.
domain: automation
input:
threshold:
name: Battery warning level threshold
description: Battery sensors below threshold are assumed to be low-battery (as
well as binary battery sensors with value 'on').
typealias Price = Double
// experimental inline class, wrapper around primitive without runtime overhead
inline class Percent(private val percent: Int) {
fun toPercent(): Double = percent / 100.0
}
data class TotalCost(val sum: Price, val discount: Price, val appliedOffers: List<String>)
interface BasketCalculator {
func handleMyRsource(ctx context.Context, event cfn.Event) (physicalResourceID string, data map[string]interface{}, err error) {
switch event.RequestType {
case "Create":
// return myApiClient.create(event.event.ResourceProperties)
case "Update":
// return myApiClient.update(event.event.ResourceProperties, event.OldResourceProperties)
case "Delete":
// return myApiClient.delete(event.event.ResourceProperties)
}
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/cfn"
"github.com/aws/aws-lambda-go/lambda"
)
func handleCustomResources(ctx context.Context, event cfn.Event) (physicalID string, data map[string]interface{}, err error) {
switch event.ResourceType {
DevApiKeyValue:
Type: Custom::ApiKeyValue
Properties:
ServiceToken: ${cf:custom-resources-dev.ServiceToken}
ApiKeyId: !Ref DevApiKey
SsmParamPath: /api/keys/${self:provider.stage}
Overwrite: true # default is true
@masgari
masgari / video-errors-fixer.py
Created August 5, 2018 11:12
python script for fixing video errors (mp4, mkv) using ffmpeg
#!/usr/bin/env python3.6
import subprocess
import sys
import os
import glob
def fix_video_using_ffmpeg(f, output_dir):
out_f = os.path.join(output_dir, os.path.basename(f))
# ffmpeg -err_detect ignore_err -i video.mkv -c copy video_fixed.mkv
exit_code = subprocess.call(['ffmpeg', '-err_detect', 'ignore_err', '-i', f, '-c', 'copy', out_f])
@masgari
masgari / docker-cleanup-resources.md
Created March 13, 2018 06:40 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@masgari
masgari / brew-java-and-jenv.md
Created September 12, 2017 21:50 — forked from tomysmile/brew-java-and-jenv.md
How To Install Java 8 on Mac

Install HomeBrew first

brew update
brew tap caskroom/cask
brew install brew-cask

If you get the error "already installed", follow the instructions to unlink it, then install again:

@masgari
masgari / proxy.rb
Created August 24, 2016 18:27 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,