This file contains hidden or 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
| import datetime | |
| import time | |
| dt = datetime.datetime(2010, 2, 25, 23, 23) | |
| time.mktime(dt.timetuple()) |
This file contains hidden or 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
| def create_all_positions(max_x, max_y): | |
| all_positions = list() | |
| for row in xrange(1, max_y+1): | |
| all_positions.append([(col, row) for col in xrange(1, max_x+1)]) | |
| return all_positions | |
| def get_next_empty(all_positions, used_positions): | |
| for row in all_positions: | |
| for position in row: |
This file contains hidden or 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
| import os | |
| import requests | |
| CLIENT_ID = 'wxzr4lZtT3W4uZd3kOlHdteeugUjmUDT4lbYJkh6' | |
| CLIENT_SECRET = 'xItJryuKsaAcLk9fAp6OZXd4vKaD4WZ96jxxcLHVehog80TMWEr9NtdM5hz8xvz9eEtR0XXQgfnQdUTAj6Fieb2b5u0OrdPHhp7f2ntif9GfI2bfVPz2Wxg2JQJakb2c' | |
| TOKEN_URL = 'http://localhost:8000/api/v2/auth/user/auth/' | |
| USERNAME = 'username' | |
| PASSWORD = 'password' |
This file contains hidden or 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.core import serializers | |
| f = open('dic_user_status.json', b'w') | |
| json = serializers.serialize("json", DicUserStatus.objects.all()) | |
| f.write(json) | |
| f.close() |
This file contains hidden or 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
| def register_all(app_label): | |
| """Function for django admin. | |
| Register all app models in django admin. | |
| """ | |
| from django.apps import apps | |
| from django.contrib import admin | |
| from django.contrib.admin.sites import AlreadyRegistered | |
| app_models = apps.get_app_config(app_label).get_models() | |
| for model in app_models: |
This file contains hidden or 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
| def discover(package_name): | |
| """Function that discovers packages for django. | |
| For example, if you want store your models in different files you must | |
| call this function in __init__ file of the models package. | |
| Django app structure: | |
| some_app/ | |
| __init__.py | |
| models/ | |
| my_model.py |
This file contains hidden or 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 'SELECT setval(''main_' || c.relname || ''', nextval(''' || n.nspname || '.' || c.relname || ''') + 20);' FROM pg_class c | |
| JOIN pg_namespace n ON n.oid = c.relnamespace | |
| WHERE c.relkind = 'S' and n.nspname = 'main'; |
This file contains hidden or 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
| /****************************************************************************** | |
| Current example realize many-to-many relationship between product and | |
| customer's purchase order on it in PostgreSQL DBMS. | |
| +~~~~~~~~~+ +~~~~~~~~~~~~~~~~~~~+ +~~~~~~~~~~~~~~~~~~~+ | |
| |*product*| | *order_items* | | *purchase_order* | | |
| +~~~~~~~~~+ +~~~~~~~~~~~~~~~~~~~+ +~~~~~~~~~~~~~~~~~~~+ | |
| | id | _____ | product_id | __ | id | | |
| +---------+ +-------------------+ / +-------------------+ | |
| | name | | purchase_order_id | _/ | customer_address | | |
| +---------+ +-------------------+ +-------------------+ |
This file contains hidden or 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 | |
| tc.constraint_name, tc.table_name, kcu.column_name, | |
| ccu.table_name AS foreign_table_name, | |
| ccu.column_name AS foreign_column_name | |
| FROM | |
| information_schema.table_constraints AS tc | |
| JOIN information_schema.key_column_usage AS kcu | |
| ON tc.constraint_name = kcu.constraint_name | |
| JOIN information_schema.constraint_column_usage AS ccu | |
| ON ccu.constraint_name = tc.constraint_name |
This file contains hidden or 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 | |
| n.nspname as "schema" | |
| ,t.relname as "table" | |
| ,c.relname as "index" | |
| ,i.indisunique AS "is_unique" | |
| ,array_to_string(array_agg(a.attname), ', ') as "columns" | |
| ,pg_get_indexdef(i.indexrelid) || ';' as "ddl" | |
| ,'DROP INDEX ' || n.nspname || '.' || c.relname || ';' as "delete_ddl" | |
| FROM pg_catalog.pg_class c | |
| JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace |