Skip to content

Instantly share code, notes, and snippets.

View avi-perl's full-sized avatar

Avi Perl avi-perl

View GitHub Profile
@avi-perl
avi-perl / POST.md
Last active November 14, 2023 05:55
A hand made aluminum pant clip for mid-sized cameras.

DIY Camera Clip For Mirrorless & Film Cameras

Summery: An oversized pen-clip like attachment can be made with simple tools to attach mid-sized cameras to a pant pocket, removing the need for camera straps and other complicated hardware alternatives.

After 6 years of total burnout from a career in commercial photography, an interest in taking photos has started to grow on me, this time in the form of film photography and film development. I've got a long term goal of taking photos of my children, developing the film, printing the photos in a darkroom, and then hanging them in hand built frames. (Full-stack photography?) To that end, I've started to take a camera with me when I take my children out to places.

My goal

I'd like to be able to grab a camera and keep it with me while playing in a park, walking around a musium, and doing all the activities that dads do with their kids. It must not get in the way, must be comfortable, and be quick to access and put away. Modifying the camera is not a

@avi-perl
avi-perl / README.md
Last active June 13, 2023 02:15
Convert Google Voice Takeout files into a spreadsheet

Google Takeout to CSV

I was asked by someone for help with the following: They had used Google Takeout to download voicemails from Google Voice and they now wanted some metadata about the voicemails in a CSV.

The following script will accomplish this task on windows without any need for

@avi-perl
avi-perl / README.md
Last active June 20, 2023 06:50
Django: Bulk update any field in any model with a generic management script!

Generic Bulk Updating

After writing up a number of CLI scripts to update various model values in a Django app, it occurred to me that a generic script could be written that would work for all of my purposes. What follows is a simple catch-all script that can be used in any django app as is!

The script works by taking in the following values:

  • Model name
  • Field name
  • New value type
  • New value
@avi-perl
avi-perl / models.py
Last active July 10, 2023 03:58
Natural integration of business logic with a Django Model
class BlogPostUtils:
def __init__(self, post):
self.post = post
def before_save(self)
self.post.content = bleach.clean(self.post.content)
class BlogPost(models.Model):
@avi-perl
avi-perl / 0_README.md
Last active June 4, 2023 08:49
Django: Scheduled user activation/deactivation without a background task.

Auto Expiring Django Users

When there is a need to give a user temporary access in Django, typically, you will need to enable their user and then expire their user manually. This creates an issue as it relies on remembering to disable the user. One way to deal with this is to save the expiration time somewhere and have a script running that will expire users, however this creates another weak point in the app and a critical scheduled job to make sure is always running.

My Solution

In an app where security was critical and where such a scheduled script would have been subject to audits, I found this method to work perfectly:

Rather than use a boolean to indicate active status, use datetimes for active start and end times and let Django figure out if the user is active based on the current time.

@avi-perl
avi-perl / input.csv
Created October 2, 2022 08:56
Using Python `namedtuple` objects to handle CSV rows
name department birthday month
John Smith Accounting November
Erica Meyers IT March
@avi-perl
avi-perl / HebrewString.py
Created October 26, 2021 03:10
My attempt to make a HebrewString object, a string representing hebrew text that you can slice and dice despite extra Unicode characters.
from rich import print
e = "וְהָאָ֗רֶץ הָיְתָ֥ה תֹ֙הוּ֙ וָבֹ֔הוּ וְחֹ֖שֶׁךְ עַל־פְּנֵ֣י תְה֑וֹם וְר֣וּחַ אֱלֹהִ֔ים מְרַחֶ֖פֶת עַל־פְּנֵ֥י הַמָּֽיִם׃"
class HebrewString(str):
HEBREW_LETTERS = ["א", "ב", "ג", "ד", "ה", "ו", "ז", "ח", "ט", "י", "כ", "ך", "ל", "מ", "ם", "נ", "ן", "ס", "ע",
"פ", "ף", "צ", "ץ", "ק", "ר", "ש", "ת"]
def __init__(self, hebrew_string):
@avi-perl
avi-perl / df_to_table.py
Last active December 15, 2022 21:27
Convert a pandas.DataFrame object into a rich.Table object for stylized printing in Python.
from datetime import datetime
from typing import Optional
import pandas as pd
from rich import box
from rich.console import Console
from rich.table import Table
console = Console()