Skip to content

Instantly share code, notes, and snippets.

@s3i7h
s3i7h / AnyUri.py
Last active April 2, 2024 17:14
a class that handles uri
import re
from re import Pattern
from typing import Dict, Any, cast
from pydantic.utils import update_not_none
from pydantic.validators import constr_length_validator
class RFC3986Regex:
ALPHA: Pattern = r"[a-zA-Z]"
@t-oster
t-oster / OPIHelper.php
Created April 18, 2018 06:53
Little helper class to request a payment on an OPI enabled Card Terminal
<?php
/**
* Little helper class to request a payment on an OPI enabled Card Terminal
*/
class OPIHelper {
private $ip;
private $port;
private $requestID = 0;
@nickvandewiele
nickvandewiele / driver.py
Last active January 31, 2023 19:14
PyQT, pyqtgraph, and Cython
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
from window import CustomWindow
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@sgmurphy
sgmurphy / podcast-ratings.php
Created February 21, 2012 19:31
Scrape ratings from iTunes store
<?php
/**
* Scrape the number of podcast reviews from iTunes for all country specific storefronts.
*
* @author Sean Murphy <sean@iamseanmurphy.com>
*/
$podcast_id = '366931951'; // Startups For the Rest of Us
//$podcast_id = '318567721'; // techzing
@jordinl-zz
jordinl-zz / django_field_validation.py
Created September 22, 2011 11:51
Add field validations to the model
from django.db import models
from django.core.exceptions import ValidationError
from django.forms import ModelForm
class CleanModel(models.Model):
""" Abstract class that adds field validations """
def clean_fields(self, exclude):
errors = {}
@joshmarshall
joshmarshall / tornado_temp_file_put.py
Created March 15, 2011 02:35
Temporary File PUT Transfer Handler for Tornado
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.httputil
import tempfile
class MainHandler(tornado.web.RequestHandler):
def put(self):
filename = self.request.body.name
# do stuff with the image