Skip to content

Instantly share code, notes, and snippets.

View maxdrift's full-sized avatar

Riccardo Massari maxdrift

View GitHub Profile
@maxdrift
maxdrift / client_test.ex
Created December 10, 2019 23:48
An attempt to define an API client using only Elixir Behaviours and Mox mocks/stubs
defmodule Client do
defstruct client_module: nil, base_url: "http://foo.bar"
@type t :: %__MODULE__{}
@callback get(config :: Client.t(), url :: String.t()) :: {:ok, any()} | {:error, any()}
@callback post(config :: Client.t(), url :: String.t(), body :: map()) ::
{:ok, any()} | {:error, any()}
@spec new :: Client.t()

Keybase proof

I hereby claim:

  • I am maxdrift on github.
  • I am maxdrift (https://keybase.io/maxdrift) on keybase.
  • I have a public key ASDxebMIszLsQ3ra3mHa0MGIMTog3REIuWqtm-osVY5NEQo

To claim this, I am signing this object:

@maxdrift
maxdrift / admin.py
Created August 24, 2016 11:59
Django read-only admin for all users which are not superusers
class CustomModelAdmin(admin.ModelAdmin):
def save_model(self, *args, **kwargs):
if not request.user.is_superuser:
return
super(CustomModelAdmin, self).save_model(request, *args, **kwargs)
def has_module_permission(self, request):
if not request.user.is_superuser:
return True
return super(CustomModelAdmin, self).has_module_permission(request)
Nov27 = {
'flavio': 5,
'ivan': 5,
'riccardo': 8,
'andrea': None,
'mattia': 1 # Correct?
}
@maxdrift
maxdrift / gist:353c9febdccf65251282
Created August 6, 2014 09:03
Using a mutable object as default function parameter is unsafe
>>> def foo(l=[]): l+= [1]; print l
...
>>> foo()
[1]
>>> foo()
[1, 1]
>>> foo()
[1, 1, 1]
>>> foo()
[1, 1, 1, 1]