Skip to content

Instantly share code, notes, and snippets.

View svetlyak40wt's full-sized avatar
💭
Making Ultralisp.org

Alexander Artemenko svetlyak40wt

💭
Making Ultralisp.org
View GitHub Profile
@svetlyak40wt
svetlyak40wt / postgresql-crawler.py
Created April 14, 2015 13:00
Пример работы с posgresql из python + gevent и пулом коннектов от sqlalchemy
#!/usr/bin/env python
# SOME DOCS:
# PostgreSQL driver: http://initd.org/psycopg/docs/
# How to setup PosgreSQL in Docker: https://registry.hub.docker.com/_/postgres/
import gevent.monkey
gevent.monkey.patch_thread()
import psycogreen.gevent
psycogreen.gevent.patch_psycopg()
integers_list = has_items(of_type(int))
assert_that(data, has_entries(
results=integers_list,
total_pages=is_(int),
page=is_(int)))
@svetlyak40wt
svetlyak40wt / check.hy
Created October 26, 2015 11:09
Apply function in hy does not work anymore
(defn blah [foo &optional bar]
(print foo)
(print bar))
(try
;; this does not work in Hy-0.11
(apply blah [1] {"bar" 2})
(except [e Exception]
(print '(apply blah [1] {"bar" 2}) "does not work, throwing:" e)))
@svetlyak40wt
svetlyak40wt / dinamometr.el
Last active January 26, 2016 20:15
Рассчет груза для тарировки динамоментрического ключа (код на Emacs Lisp, но наверное и на Common Lisp со Schema заведется)
;; Данный код написан в соответствии с
;; инструкцией по тарированию динамометрических ключей
;; https://yadi.sk/i/aZy87aLPnncDM
(defun dinamo (mz)
"Возвращает массу груза (кг), при которой должно произойти
срабатывание предельного динамометрического ключа, выставленного
на момент закручивания mz"
(let* ((g 9.81) ; ускорение свободного падения (м/с^2)
@svetlyak40wt
svetlyak40wt / use-nullmailer.sh
Created February 7, 2016 14:38
Using nullmailer from docker image
# this example shows how to run docker container and use nullmailer, running on a host machine
# first, run a container like that
sudo docker run \
--rm \
-ti \
-v `which sendmail`:`which sendmail` \
-v `which nullmailer-inject`:`which nullmailer-inject` \
-v `which nullmailer-queue`:`which nullmailer-queue` \
@svetlyak40wt
svetlyak40wt / test-try-except.py
Created March 23, 2016 16:18
Example of nested try/except in python
# guess what will be at the output?
class FooError(RuntimeError):
pass
class BarError(RuntimeError):
pass
@svetlyak40wt
svetlyak40wt / py2-broken-traceback.py
Created April 5, 2016 13:52
This is a demo of broken traceback when reraising exception in python 2.x.
"""
This is a demo of broken traceback
when reraising exception in python 2.x.
In this code, "raise e" makes python
lost original traceback, attached to the
exception. It outputs:
Traceback (most recent call last):
File "/tmp/test.py", line 19, in <module>
@svetlyak40wt
svetlyak40wt / bad-ugly-and-weird.py
Created May 20, 2016 10:31
Bad python code example
for p in range ( 0, iteration if iteration<5 else 5 ):
threads = list()
up = len_ids/iteration*(p+1) if p!=iteration else len_ids-1
part_payloads['ids'] = ','.join(list(map(str, payloads['ids'][p*len_ids/iteration:up] )))
threads.append(gevent.spawn(self.request, part_payloads))
gevent.joinall(threads)
django>=1.8,<1.9
South
djangorestframework<3.0.0
drf-extensions
django-extensions
django-debug-toolbar
requests>=2.10.0,<2.11.0
envoy
graphitesend
rq