This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SimpleTCP do | |
use Application | |
def start(_type, _args) do | |
import Supervisor.Spec, warn: false | |
children = [ | |
worker(SimpleTCP.Worker, [8000]) | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
from django.db import models | |
from django.db.models.fields.related_descriptors import ForwardManyToOneDescriptor # noqa | |
class RelationNotLoaded(Exception): | |
pass | |
OlderNewer