Skip to content

Instantly share code, notes, and snippets.

View raimonte's full-sized avatar
🎯
Focusing

Rail Alimov raimonte

🎯
Focusing
View GitHub Profile
@raimonte
raimonte / gist:befd1d12204b55a2f98a
Last active August 29, 2015 14:23
Dynamically adding decorators
from tornado.gen import coroutine
from tornado.web import RequestHandler, authenticated
class AddDecorators(type):
METHODS = ('get', 'post', 'delete', 'put')
def __new__(cls, name, bases, class_dict):
add_decorator = lambda key, value: coroutine(authenticated(value)) if isfunction(value) and key in cls.METHODS else value
new_class_dict = {key: add_decorator(key, value) for key, value in class_dict.items()}
@raimonte
raimonte / erlang_map_reduce_simple_example.erl
Last active August 29, 2015 14:25
erlang mapreduce simple example
-module(map_reduce).
-export([start/1]).
-export([reduce/3, map/2]).
merge_keyval(Key, Value, Map) ->
case maps:find(Key, Map) of
{ok, Old} -> maps:update(Key, Value + Old, Map);
error -> maps:put(Key, Value, Map)
@raimonte
raimonte / gist:b765e43b961fac5f580b
Created July 26, 2015 10:51
curl requests for test
# multipart
curl http://127.0.0.1:8000/api/v1/places/ -F "image[]=@static/for_test/image1.jpg" -F "image[]=@static/for_test/image2.jpg"
# login
curl -u login:password -i -X GET http://127.0.0.1:8000/api/v1/login
@raimonte
raimonte / context manager
Last active May 5, 2016 04:07
django context processor
from backend.models import Background
from users.models import Contact
class MetaData(object):
def __init__(self, model):
self.model = model
def __enter__(self):
try:
self.data = self.model.objects.first()
@raimonte
raimonte / gist:4df87ceea17618186f83e447b1b52689
Created December 11, 2016 08:47
upload_to for django model.FileField
from datetime import datetime
from functools import partial
from os.path import join
from uuid import uuid4
from django.utils.deconstruct import deconstructible
def _update_filename(instance, filename, path):
ext = filename.split('.')[-1]
@raimonte
raimonte / gist:74ab349d31d89844b7baf6a1db451c0d
Last active April 13, 2017 03:45
use of structure in channels
package main
import (
"fmt"
"time"
"encoding/json"
)
type Company struct {
@raimonte
raimonte / Dockerfile
Last active April 23, 2017 09:11
Simple Dockerfile for python project
FROM python:3.6
WORKDIR /opt/src
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
@raimonte
raimonte / docker-compose.yml
Created April 23, 2017 09:11
Simple docker-compose.yml
version: '2'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- '8080:8080'
volumes:
- ./src:/opt/src
stop all containers:
docker stop $(docker ps -a -q)
docker kill $(docker ps -q)
remove all containers
docker rm $(docker ps -a -q)
remove all docker images
docker rmi $(docker images -q)
#!/bin/bash
VERSION="7.17.0"
source_name=""
target_host=""
while getopts u:h: flag
do
case "${flag}" in