Skip to content

Instantly share code, notes, and snippets.

View Ankhbayar's full-sized avatar

Ankhbayar Ankhbayar

View GitHub Profile
@Ankhbayar
Ankhbayar / init_svr.yml
Created July 17, 2015 14:12
Ansible Prepare ubuntu server for Mongolian Mirror
---
- hosts: VM
remote_user: ankhaa
sudo: true
tasks:
- name: edit archive url in /etc/apt/sources.list
replace:
dest: /etc/apt/sources.list
regexp: 'mn.archive.ubuntu.com'
replace: 'mirror.ndc.mn'
-- Function: clone_schema(text, text)
DROP FUNCTION clone_schema(text, text);
CREATE OR REPLACE FUNCTION clone_schema(source_schema text, dest_schema text)
RETURNS void AS
$BODY$
DECLARE
seq RECORD;
@Ankhbayar
Ankhbayar / metaclass.py
Created April 15, 2012 15:44
Python Meta class 3
class DeclarativeFieldsMetaclass(type):
"""
Metaclass that converts Field attributes to a dictionary called
'base_fields', taking into account parent class 'base_fields' as well.
"""
def __new__(cls, name, bases, attrs):
attrs['base_fields'] = get_declared_fields(bases, attrs)
new_class = super(DeclarativeFieldsMetaclass,
cls).__new__(cls, name, bases, attrs)
if 'media' not in attrs:
@Ankhbayar
Ankhbayar / django_metaclass.py
Created April 15, 2012 15:42
Python Meta class 2
class Form(BaseForm):
"A collection of Fields, plus their associated data."
# This is a separate class from BaseForm in order to abstract the way
# self.fields is specified. This class (Form) is the one that does the
# fancy metaclass stuff purely for the semantic sugar -- it allows one
# to define a form using declarative syntax.
# BaseForm itself has no way of designating self.fields.
__metaclass__ = DeclarativeFieldsMetaclass
@Ankhbayar
Ankhbayar / contact_form_demo.py
Created April 15, 2012 14:12
Python Meta class 1
from django import forms
class Contact(forms.Form):
subject = forms.CharField()
email = forms.EmailField()
content = forms.CharField(widet = forms.Textarea )
Dictionary<long, string> num = new Dictionary<long, string>() {
{0, "" }, { 1, "нэг" }, { 2, "хоёр" }, {3,"гурав"}, {4, "дөрөв"}, {5, "тав"}, {6,"зургаа"}, {7,"долоо"}, {8,"найм"}, {9,"ес"},
{10, "арав"}, {20,"хорь"},{30,"гуч"}, {40,"дөч"}, {50,"тавь"}, {60,"жар"}, {70,"дал"}, {80,"ная"}, {90,"ер"},
{100,"зуу"},{200,"хоёр зуу"},{300,"гурван зуу"},{400,"дөрвөн зуу"},{500,"таван зуу"},{600,"зургаан зуу"},{700,"долоон зуу"},{800,"найман зуу"},{900,"есөн зуу"}
};
Dictionary<long, string> sep_num = new Dictionary<long, string>()
{
{3,"мянга"},
{6,"сая"},
# -*- coding: utf-8 -*-
import unittest
from mongoengine import *
from django.template import Context, Template
from django.conf import settings
import datetime
settings.configure(DEBUG = True)
@Ankhbayar
Ankhbayar / number.py
Created March 24, 2011 12:47
Эерэг бүхэл Тоог монгол хэллэгрүү хөрвүүлэх script
#coding:utf-8
# By: @ankhaatk
import types
def find_omnoh_oron(number, numberArray):
""" Ойролцоох тоог жагсаалтаас олох
"""
min_diff = 999999
last_num = 0
for num in numberArray: