Skip to content

Instantly share code, notes, and snippets.

View jamal's full-sized avatar

Jamal Fanaian jamal

View GitHub Profile
@jamal
jamal / discover_hap.py
Last active June 23, 2023 20:50
Discover mDNS records for Home Assistant and print the Avahi service config
# This is based on the solution by Michel5 provided here https://community.home-assistant.io/t/solved-how-to-configure-avahi-daemon-on-docker-host/356422
from zeroconf import ServiceBrowser, Zeroconf
class MyListener:
def remove_service(self, zeroconf, type, name):
print("Service %s removed" % (name,))
def add_service(self, zeroconf, type, name):
info = zeroconf.get_service_info(type, name)
@jamal
jamal / build.zig
Last active May 18, 2023 01:44
Example of using CoreAudio API in Zig to play a beep
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "tmp",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
$ cat strace.txt.1035*
execve("./dial", ["./dial"], [/* 27 vars */]) = 0
brk(NULL) = 0x1e67000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa9e3900000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=40388, ...}) = 0
mmap(NULL, 40388, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fa9e3904000
close(3) = 0
@jamal
jamal / dial.go
Created September 25, 2017 20:19
package main
import "net"
func main() {
c, err := net.Dial("tcp", "google.com:80")
if err != nil {
panic(err)
}
c.Close()
#
# Boxstarter script
# To install Boxstarter and run this script:
#
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
# Install-BoxstarterPackage -PackageName <RAW-GIST-URL> -DisableReboots
#
# Most of this was referenced from:
# - https://gist.github.com/jessfraz/7c319b046daa101a4aaef937a20ff41f
# - https://gist.github.com/NickCraver/7ebf9efbfd0c3eab72e9
@jamal
jamal / gist:bdaccbb02e60a26d5464
Created January 24, 2015 14:36
Simple Vimscript to switch between source and header files in C++ using ctags, requires --extra=+f to be passed to ctags
function! SwitchSourceHeader()
if (expand("%:e") == "cpp")
execute 'tag' join([expand("%:t:r"), "h"], ".")
else
execute 'tag' join([expand("%:t:r"), "cpp"], ".")
endif
endfunction
map <Leader>o :call SwitchSourceHeader()<CR>
map <Leader>i :vert belowright split<CR>:call SwitchSourceHeader()<CR> " Open alt file in a right pane
### Keybase proof
I hereby claim:
* I am jamal on github.
* I am jamal (https://keybase.io/jamal) on keybase.
* I have a public key whose fingerprint is 344B 51C5 0799 A4E8 121E 1AF9 3E31 864F 52C0 075F
To claim this, I am signing this object:
@jamal
jamal / gist:9230927
Last active August 29, 2015 13:56
git-svn reset to upstream branch
# WARNING: This will destroy ALL local changes that have not been dcommitted (even what has been committed to your local git repo)
git reset --hard git-svn/master
@jamal
jamal / create_test_photos.sh
Created February 19, 2014 21:49
Generate 100 unique test photos using ImageMagick
for i in {1..100}
do
convert -size 100x100 xc:rgba\(255,0,0,0.4\) -draw "fill white text 10,10 '$i'" $i.png
done
@jamal
jamal / rethinkdb_atomic_filter_and_update.js
Created November 7, 2013 02:10
Hack to support an atomic filter and update with RethinkDB. This is useful for supporting something like a locking message queue. The problem here is that return_vals only works for single-row modifications, and filter() and limit() always returns multiple rows. At least, this was the simplest solution I could come up with.
r.db("test").table("queue").filter({"available": true}).limit(1).forEach(function (row) {
return r.db("test").table("queue").get(row("id")).update({"available": false}, {return_vals: true})
})