Skip to content

Instantly share code, notes, and snippets.

View Znack's full-sized avatar

Sergey Cherepanov Znack

  • MetaLamp
  • Barcelona
View GitHub Profile
@Znack
Znack / base_handler.py
Created April 30, 2015 12:45
Tornado server
import json
import redis
import time
import tornado
import tornadoredis
class BaseHandler(object):
def __init__(self, client, socketHandler, *args, **kwargs):
self.client = client
# -*- coding: utf-8 -*-
from hashlib import md5
from urllib import urlencode
from django.conf import settings
_ADDRESS = 'https://auth.robokassa.ru/Merchant/Index.aspx?'
_EXTRA_PARAMS_PREFIX = 'shp_'
_COST = settings.CARDBOARD_COST
@Znack
Znack / auth.js
Created July 3, 2015 06:16
Google APIS for node.js OAuth2
/**
From the Google API console, you need to activate the Analytics API,
and finally setup a Service Account, you'll then download a *.p12 file.
From this *.p12 file, you need to convert it to a *.pem file, to do that, run the following:
openssl pkcs12 -in XXXXX.p12 -nocerts -nodes -out XXXXX.pem
You'll be asked a password, it should be notasecret
Now you got the *.pem file you need, and the account email is the one displayed in the google api console, as EMAIL ADDRESS.
Don't forget to add this address to your analytics account
(see: Analytics Google API Error 403: "User does not have any Google Analytics Account")
You should be good to go with the following snippet:
@Znack
Znack / a.js
Created July 12, 2015 09:18
Import contacts
function importContact (phone, firstName, lastName) {
return MtpApiManager.invokeApi('contacts.importContacts', {
contacts: [{
_: 'inputPhoneContact',
client_id: '1',
phone: phone,
first_name: firstName,
last_name: lastName,
}],
replace: false,
This file has been truncated, but you can view the full file.
{"key":"I. Народное хозяйство","values":[{"key":"I. Народное хозяйство","values":[{"key":"I. Народное хозяйство","values":[{"key":"I. Народное хозяйство","values":[{"key":"1937","values":[{"name":"I. Народное хозяйство","year":"1937","union_budget":37026,"resp_budgets":2307.9,"local_budgets":4079.2,"total_budget":43413.1,"level":"I. Народное хозяйство","subLevel":"I. Народное хозяйство","subSubLevel":"I. Народное хозяйство"}]},{"key":"1938","values":[{"name":"I. Народное хозяйство","year":"1938","union_budget":44629.3,"resp_budgets":2423.1,"local_budgets":4671.2,"total_budget":51723.6,"level":"I. Народное хозяйство","subLevel":"I. Народное хозяйство","subSubLevel":"I. Народное хозяйство"}]},{"key":"1939","values":[{"name":"I. Народное хозяйство","year":"1939","union_budget":51513.4,"resp_budgets":3842.2,"local_budgets":5060.9,"total_budget":60416.5,"level":"I. Народное хозяйство","subLevel":"I. Народное хозяйство","subSubLevel":"I. Народное хозяйство"}]},{"key":"1940","values":[{"name":"I. Народное хозяйство"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"filters": {
"require_debug_false": {
"()": "django.utils.log.RequireDebugFalse"
}
},
"handlers": {
"mail_admins": {
from django.core.urlresolvers import reverse
from django.utils.text import mark_safe
def add_link_field_to_related(target_model=None, field='', app='', field_name='link',
link_text=unicode):
def add_link(cls):
reverse_name = target_model or cls.model.__name__.lower()
def link(self, instance):
@Znack
Znack / remove-table.sql
Created December 8, 2015 05:13
Remove all tables in database, MYSQL
SET FOREIGN_KEY_CHECKS = 0;
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
FROM information_schema.tables
WHERE table_schema = 'DB_NAME';
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
@Znack
Znack / migrations.py
Created December 9, 2015 16:27
Custom operations in migrations
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def make_balance_nullable_forwards(apps, schema_editor):
Carrier = apps.get_model("carriers", "Carrier")
default_balance_carriers = Carrier.objects.filter(balance=0)
default_deposit_carriers = Carrier.objects.filter(deposit=0)
@Znack
Znack / TelegramHandlersRouter.hs
Created February 16, 2018 12:19
Servant-like handlers router for Telegram bots
{-# LANGUAGE DataKinds, TypeOperators #-}
{-# LANGUAGE TypeFamilies, FlexibleInstances, FlexibleContexts, ScopedTypeVariables
#-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE InstanceSigs #-}
module Router where
import Control.Applicative
import Control.Monad