Skip to content

Instantly share code, notes, and snippets.

View svvitale's full-sized avatar

Scott Vitale svvitale

View GitHub Profile

Keybase proof

I hereby claim:

  • I am svvitale on github.
  • I am svvitale (https://keybase.io/svvitale) on keybase.
  • I have a public key ASDTmkxAdl96XWG71bZe4C58UsDKQXlt8DaltryKd8ALYAo

To claim this, I am signing this object:

@svvitale
svvitale / README.md
Last active May 1, 2020 16:22
Vitale's Python Style Guide

Operator Overrides

I absolutely love using operator overrides in low-level objects because it can make the caller's use case WAY more intuitive. There are certainly some pitfalls though.

  1. If you're overriding __getitem__ and __setitem__ to make an object more dictionary-like, make sure to also override __iter__ OR __contains__ since they're called to handle membership tests like in and not in. (ref: https://docs.python.org/3/reference/expressions.html#membership-test-operations)

Enums

Enums can be a little tedious in Python, but there are a few things I try to do to streamline usage:

@svvitale
svvitale / Example.cs
Created January 23, 2018 16:55
Dymo SDK Concurrency Issues
using DYMO.Label.Framework;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Printers printers = new Printers();
@svvitale
svvitale / ca.md
Created January 4, 2018 16:06 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('spigot', '0034_hydrated_connection_view_v2'),
@svvitale
svvitale / standard_api_client.py
Created November 14, 2017 03:01
Requests.Session -> Async
import requests
class MyApiClient(requests.Session):
def do_something(self):
response = self.post('/some/url', json={
'param1': 'a',
'param2': 'b'
})
if response.status_code == requests.codes.ok:
def fib_iterative(n):
sequence = (0, 1)
if n < 2:
return sequence[n]
for _ in range(n - 2):
sequence = (sequence[1], sequence[0] + sequence[1])
return sequence[0] + sequence[1]
@svvitale
svvitale / gen.py
Created January 24, 2017 21:36
What does this do?
import random
import string
import re
allowable = re.sub(r'[IO10]', '', (string.ascii_uppercase + string.digits))
def combos(place):
for char in allowable:
@svvitale
svvitale / setup.py
Created June 14, 2016 20:33
setup.py with -isystem includes
from setuptools import setup
from distutils.core import Extension
from distutils.command.build import build
import os
from subprocess import call
import multiprocessing
from glob import glob
@svvitale
svvitale / decorated_view.py
Created March 31, 2015 05:04
Comparison of Traditional Django Views to Decorated Views for APIs
from django.views.generic import View
from django.shortcuts import get_object_or_404
from .decorators import json
from .models import RoomModel
from django.http import HttpResponse
class RoomView(View):
"""Room view class that implements the primary HTTP verbs (POST, GET, PUT, DELETE).