Skip to content

Instantly share code, notes, and snippets.

View Learning Plan for Design Patterns.md

Learning Plan for Design Patterns and Principles of Good Design

These learning resources primarily focus on programming using Good Design Principles and Design Patterns

  • There is an emphasis on learning using PHP, although most patterns are universal to every object orientated language.
@dmmeteo
dmmeteo / 1.srp.py
Last active May 22, 2022
SOLID Principles explained in Python with examples.
View 1.srp.py
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):
@samueljseay
samueljseay / es6-import-cheat-sheet.md
Created Jun 2, 2017
ES6 exports / imports cheat sheet
View es6-import-cheat-sheet.md
// default exports
export default 42;
export default {};
export default [];
export default (1 + 2);
export default foo;
export default function () {}
export default class {}
export default function foo () {}
@turtlemonvh
turtlemonvh / README.md
Last active Apr 22, 2021
Multi-level arg parse
View README.md

Multi-level arg parse

Shows how to structure a python app using arg parse that goes down many levels.

The "trick" is to

  • add a subparsers S1[]
  • add parsers P1[] to your subparser S1[x]
  • add a new set of subparsers S2[] to one of those parsers P1[x]
@tomvon
tomvon / resize-image-keep-aspect-ratio.py
Created Jun 8, 2014
Python script to resize an image while keeping the original aspect ratio.
View resize-image-keep-aspect-ratio.py
#Resizes an image and keeps aspect ratio. Set mywidth to the desired with in pixels.
import PIL
from PIL import Image
mywidth = 300
img = Image.open('someimage.jpg')
wpercent = (mywidth/float(img.size[0]))
hsize = int((float(img.size[1])*float(wpercent)))
@valberg
valberg / imagewiththumbnails_updateable.py
Created Apr 20, 2012
Django create thumbnail form ImageField and save in a different ImageField - now with updating!
View imagewiththumbnails_updateable.py
# Extension of http://www.yilmazhuseyin.com/blog/dev/create-thumbnails-imagefield-django/
# Note: image_folder and thumbnail_folder are both a callable (ie. a lambda that does a '/'.join())
class Image(Media):
image = models.ImageField(
upload_to=image_folder
)
thumbnail = models.ImageField(