Skip to content

Instantly share code, notes, and snippets.

defmodule SimpleTCP do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
worker(SimpleTCP.Worker, [8000])
]
defmodule SimpleTCP.Worker do
import Socket
def start_link(port) do
pid = spawn_link(fn -> init(port) end)
{:ok, pid}
end
def init(port) do
defmodule SimpleTCP.Sender do
use GenServer
import Socket
def start_link(socket, opts \\ []) do
GenServer.start_link(__MODULE__, [socket: socket], opts)
end
def init(socket) do
# Register the process with gproc and subcscribe to :something
defmodule SimpleTCP.Worker do
import Socket
def start_link(port) do
pid = spawn_link(fn -> init(port) end)
{:ok, pid}
end
def init(port) do
Project Gutenberg's The Adventures of Sherlock Holmes, by Arthur Conan Doyle
This eBook is for the use of anyone anywhere at no cost and with
almost no restrictions whatsoever. You may copy it, give it away or
re-use it under the terms of the Project Gutenberg License included
with this eBook or online at www.gutenberg.net
Title: The Adventures of Sherlock Holmes
from django.db import models
class AppQueryset(models.QuerySet):
pass
class AppManager(models.Manager):
queryset_class = AppQuerySet
def get_queryset(self):
return self.queryset_class(self.model)
from django.db import models
from django.db.models import signals
from django.contrib.admin.utils import NestedObjects
class AppQuerySet(models.QuerySet):
def delete(self, **kwargs):
return self.update(is_void=True)
class AdvancedManager(models.Manager):
from django.db import models
from django.db.models import signals
from django.contrib.admin.utils import NestedObjects
class AppQuerySet(models.QuerySet):
def delete(self, **kwargs):
return self.update(is_void=True)
class AppManager(models.Manager):
queryset_class = AppQuerySet
"""
Logical deletion for Django models. Uses is_void flag
to hide discarded items from queries. Overrides delete
methods to set flag and soft-delete instead of removing
rows from the database.
"""
from django.apps import apps
from django.contrib.admin.utils import NestedObjects
from django.db import models
from django.db.models import signals
@kyle-eshares
kyle-eshares / models.py
Created October 15, 2016 18:01
Strict ForeignKeys
from __future__ import unicode_literals
from django.db import models
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor # noqa
class RelationNotLoaded(Exception):
pass