Skip to content

Instantly share code, notes, and snippets.

@eirenik0
eirenik0 / .envrc
Created March 14, 2019 09:59
Load ENV variables from .env file using `dotenv` package
#!/usr/bin/env bash
IFS=$'\n'
for line in $(cat .env); do
if [[ $line != \#* ]] ; then
eval 'export $line'
fi
done
@eirenik0
eirenik0 / create_request_factory.py
Created February 20, 2019 20:27
Create methods dynamically in Python with a creation factory
def create_request_factory(timeout, headers, api_session_running_url):
methods = ("post", "get", "delete", "long_post", "long_get", "long_delete")
class _Request(object):
def __init__(self, com):
self._com = com
class RequestFactory(object):
def __init__(self):
self._com = None
@eirenik0
eirenik0 / enaml_with_fbs.py
Last active December 6, 2018 16:51
Combine https://github.com/mherrmann/fbs/ build tool with https://github.com/nucleic/enaml/ for building Desktop applications smoothly
import sys
import enaml
from enaml.qt.qt_application import QtApplication
from fbs_runtime.application_context import ApplicationContext, cached_property
from hstatus import ModemInfoUpdater
class CustomQtApplication(QtApplication):
@eirenik0
eirenik0 / get_json_from_url.py
Created October 23, 2018 13:16
Get sorted Json from URL where object is zipped Json string
import requests
import io
import gzip
import pyperclip
import json
def get_sorted_json(url):
buff = io.BytesIO()
r = requests.get(url, stream=True)
@eirenik0
eirenik0 / hierarchy_shower.py
Last active November 1, 2017 18:53
Show method hierarchy source codes for selected class method
"""
Allows to looking through method hierarchy source codes for selected class method
Usage:
sources = get_method_hierarchy_sources(CompanyProfileSettingsForm, 'save')
# shows all instances code
show_method_hierarchy(sources)
# shows shorter and prettier version
@eirenik0
eirenik0 / circle.yml
Created April 28, 2017 12:56 — forked from Yorkshireman/circle.yml
Installing Chrome on Circle CI machine (Ubuntu 14.04)
dependencies:
pre:
- sudo apt-get install libxss1 libappindicator1 libindicator7
- wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- sudo dpkg -i ./google-chrome*.deb
- sudo apt-get install -f
@eirenik0
eirenik0 / middleware.py
Last active February 15, 2017 15:28
Django middelware profiler
import cProfile, pstats, StringIO
class ProfileMiddleware(object):
def process_request(self, request):
pr = cProfile.Profile()
pr.enable()
request._pr = pr
def process_response(self, request, response):
request._pr.disable()
@eirenik0
eirenik0 / simple_websocket_client.html
Created December 29, 2016 07:46 — forked from geoffb/simple_websocket_client.html
Super simple websockets client/server using Python. Compatible with the draft 76 challenge/response.
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebSocket Client</title>
<style>
#output {
border: solid 1px #000;
}
</style>
</head>
@eirenik0
eirenik0 / setup_selenium.sh
Last active April 4, 2017 21:30 — forked from curtismcmullan/setup_selenium.sh
Setup Selenium Server on Ubuntu 14.04
#!/bin/bash
# Following the guide found at this page
# http://programmingarehard.com/2014/03/17/behat-and-selenium-in-vagrant.html
echo "\r\nUpdating system ...\r\n"
sudo apt-get update
# Create folder to place selenium in
class AdapterFabric(type):
"""
Return adapter object regarding to social network
"""
instances = 0
def __new__(cls, social, bases=(), dct={}):
cls.instances += 1
adapters = [YouTubeSocialAdapter, VKSocialAdapter]