Skip to content

Instantly share code, notes, and snippets.

View raheemazeezabiodun's full-sized avatar
🎯
Solving problems with my craft

Raheem Azeez Abiodun raheemazeezabiodun

🎯
Solving problems with my craft
View GitHub Profile
@raheemazeezabiodun
raheemazeezabiodun / dispatch_on_type.py
Last active September 19, 2019 20:29
A way of dispatching action based on type in Python.
"""
This demonstrates how to use singledispatch for dispatching on type
We want to draw each based on the type. Typically, we can use if else statement to check the type
then call the function that does draw the shape, however, we will keep having multiple if elif statement.
This is just another pythonic way of doing it
"""
from functools import singledispatch
@raheemazeezabiodun
raheemazeezabiodun / gcd.py
Created July 23, 2019 12:04
Computing greatest common divisor
def slow_gcd(arg1,arg2):
gcd = 0
for num in range(1, arg1 + arg2+ 1):
if (arg1 % num == 0) and (arg2 %num == 0):
gcd = num
return gcd
def fast_gcd(arg1,arg2):
if arg2 == 0:
@raheemazeezabiodun
raheemazeezabiodun / fibonacci.py
Created July 22, 2019 12:14
A fibonacci sequence with a better approach
def slow_fibonacci_number(n):
if n <= 1:
return n
return slow_fibonacci_number(n - 1) + slow_fibonacci_number(n - 2)
def fast_fibonacci_number(n):
numbers = [0, 1]
for num in range(2, n+1):
numbers.append(numbers[num - 1] + numbers[num - 2])
@nnja
nnja / less.md
Created October 5, 2017 04:54
A cheatsheet for using less on the command line

Tips for using less on the command line.

To navigate:

  • f = for next page
  • b = for previous page

To search:

  • /&lt;query>
{
"root": "build/",
"clean_urls": false,
"routes": {
"/**": "index.html"
}
}
@freewayz
freewayz / django_model_deletable.py
Created September 27, 2016 14:43
Django check if model has related object before Deleting the model
#After looking for a way to check if a model instance can be deleted in django ,
#i came across many sample, but was not working as expected. Hope this solution can help.
#Let start by creating an Abstract model class which can be inherited by other model
class ModelIsDeletable(models.Model):
name = models.CharField(max_length=200, blank=True, null=True, unique=True)
description = models.CharField(max_length=200, blank=True, null=True)
date_modified = models.DateTimeField(auto_now_add=True)
@adamJLev
adamJLev / mixins.py
Last active November 14, 2022 15:54
(DEPRECATED) Atomic transactions and Django Rest Framework
# NOTE This is probably no longer needed, now DRF does this
# automatically if you have ATOMIC_REQUESTS enabled.
# https://github.com/encode/django-rest-framework/pull/2887
from django.db import transaction
class AtomicMixin(object):
"""
Ensures we rollback db transactions on exceptions.