Skip to content

Instantly share code, notes, and snippets.

View justindarc's full-sized avatar

Justin D'Arcangelo justindarc

View GitHub Profile
@justindarc
justindarc / filters.py
Created July 25, 2025 19:54
Dynamic FilterSet generator for Django Rest Framework
from django.db.models import ManyToOneRel
from django_filters import rest_framework as filters
def get_dynamic_filterset_filters(model_cls, prefix=None):
"""Get dynamic dictionary containing all fields and filter expressions for the specified model class."""
field_filters = {}
for field in model_cls._meta.get_fields():
if isinstance(field, ManyToOneRel):
continue
@justindarc
justindarc / VisibilityTracker.kt
Created July 14, 2025 13:51
VisibilityTracker.kt
package com.example.trackvisibilityexample
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
@justindarc
justindarc / ObservableCollectionViewCell.swift
Created July 7, 2025 18:59
ObservableCollectionViewCell
//
// ObservableCollectionViewCell.swift
//
// Created by Justin D'Arcangelo on 7/3/25.
//
import UIKit
class ObservableCollectionViewCell: UICollectionViewCell {
var isMostlyVisible: Bool {
@justindarc
justindarc / AppDelegate.swift
Created April 30, 2020 22:22
UIViewController on a second screen
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let secondStoryboard = UIStoryboard(name: "SecondScreen", bundle: nil)
let secondScreenVC = secondStoryboard.instantiateInitialViewController() as! SecondScreenViewController
secondScreenVC.loadViewIfNeeded()
@justindarc
justindarc / timestamp.sh
Created March 28, 2018 02:49
zsh/bash timestamp
timestamp () {
date -r $(echo "$1" | cut -c "1-10")
}
@justindarc
justindarc / Introducing FlyWeb.md
Created October 21, 2016 19:27
Introducing FlyWeb

Introducing FlyWeb

For the past several months, a small team at Mozilla has been working on an experimental new Web API and an accompanying browser feature called FlyWeb.

What does it do?

In short, FlyWeb provides an API for web pages to host local web servers for exposing content and services to nearby browsers. It also adds the ability to discover and connect to nearby local web servers to the web browser itself. This feature allows users to find and connect to nearby devices with embedded web servers such as printers, thermostats and televisions as well as local web servers hosted in web pages via the FlyWeb API.

Enabling web pages to host local servers and providing the ability for the web browser to discover nearby servers opens up a whole new range of use cases for web apps. With FlyWeb, we can finally reach a level of richness in cross-device interactions previously only attainable via native apps. In addition, the built-in service discovery feature in the browser offers device makers and hob

@justindarc
justindarc / txt2cdefine
Last active September 1, 2016 18:01
txt2cdefine: Encode multiline text files into C/C++ #define directives
#!/usr/bin/env node
/**
* txt2cdefine: Encode multiline text files into C/C++ #define directives
* https://gist.github.com/justindarc/efee6d3d09341618da5af6a58dfd7b69
*
* Node.js-based command-line utility for encoding HTML, JS, CSS and other
* text files into C/C++ #define directives. Useful for embedded hardware
* applications such as Arduino or ESP8266 where no file system is available
* for reading external files. The resulting output can saved as a ".h"
@justindarc
justindarc / hello-flyweb.js
Created March 29, 2016 19:45
hello-flyweb.js
navigator.publishServer('HelloFlyWeb').then((srv) => {
(window.srv = srv).onfetch = (evt) => {
evt.respondWith(new Response('<h1>Hello FlyWeb!!!</h1>', {
headers: { 'Content-Type': 'text/html' }
}));
};
});
@justindarc
justindarc / esp8266-ap-flyweb-temperature-server.ino
Created March 17, 2016 19:39
esp8266-ap-flyweb-temperature-server
// Install ESP8266 Board v2.1.0 by adding this
// to the "Additional Board Manager URLs" in
// "Preferences..." and then select it for
// installation via "Boards Manager..." under
// the "Tools" -> "Board: XXX" menu.
// http://arduino.esp8266.com/stable/package_esp8266com_index.json
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
@justindarc
justindarc / index.js
Created February 23, 2016 20:02
node-mdns-http-test
var http = require('http');
var mdns = require('mdns');
const HTTP_PORT = 8000;
var server = http.createServer(function(request, response) {
response.end('Hello world!');
});
server.listen(HTTP_PORT);