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
# models.py | |
import uuid | |
from django.db import models | |
class Organization(models.Model): | |
org_uuid = models.UUIDField( | |
primary_key=True, default=uuid.uuid4, editable=False) | |
name = models.CharField(max_length=40) |
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
# serializers.py | |
from rest_framework import serializers | |
from myapp import models | |
class OrganizationListViewSerializer(serializers.ModelSerializer): | |
class Meta: | |
model = models.Organization | |
fields = '__all__' |
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
-- You can use pg_terminate_backend() to kill a connection. You have to be superuser to use this function. This works on all operating systems the same. | |
SELECT | |
pg_terminate_backend(pid) | |
FROM | |
pg_stat_activity | |
WHERE | |
-- don't kill my own connection! | |
pid <> pg_backend_pid() | |
-- don't kill the connections to other databases |
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
SELECT CONCAT("ALTER TABLE `", TABLE_NAME,"` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;") AS ExecuteTheString | |
FROM INFORMATION_SCHEMA.TABLES | |
WHERE TABLE_SCHEMA="[YOUR DATABASE NAME]" | |
AND TABLE_TYPE="BASE TABLE"; | |
SELECT @@character_set_database, @@collation_database; |
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
__version__ = "0.1.6.8" | |
if __name__ == "__main__": | |
import sys | |
import argparse | |
def increment_line(args): | |
vi = [int(i) for i in __version__.split('.')] | |
print('current version: %s' % __version__) |
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 celery import shared_task | |
@shared_task | |
def write_task(msg): | |
# Write log in Network IO | |
print(msg) | |
celery_handler = AsyncLogDispatcher(write_task, use_thread=False, use_celery=True) | |
celery_handler.setLevel(logging.INFO) | |
logger.addHandler(celery_handler) |
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
class FullPaths(argparse.Action): | |
"""Expand user- and relative-paths""" | |
def __call__(self, parser, namespace, values, option_string=None): | |
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values))) | |
def is_dir(dirname): | |
"""Checks if a path is an actual directory""" | |
if not os.path.isdir(dirname): | |
msg = "{0} is not a directory".format(dirname) | |
raise argparse.ArgumentTypeError(msg) |
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
# views.py | |
from rest_framework import exceptions | |
from rest_framework import generics | |
from myapp import models | |
from myapp import serializers as ser | |
class MethodSerializerView(object): | |
''' |
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
#![feature(slice_patterns)] | |
impl Solution { | |
pub fn is_match(s: String, p: String) -> bool { | |
is_match(s.as_bytes(), p.as_bytes()) | |
} | |
} | |
fn is_match(s: &[u8], p: &[u8]) -> bool { | |
match (p, s) { |
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
#!/usr/bin/env bash | |
# Ubuntu 18.04 | |
# Rust + Postgresql 10 + redis development environment | |
# Zsh | |
sudo apt install zsh | |
# oh-my-zsh | |
# using curl | |
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
# or using wget |
OlderNewer