Skip to content

Instantly share code, notes, and snippets.

View IaroslavR's full-sized avatar

Iaroslav Russkykh IaroslavR

View GitHub Profile
@IaroslavR
IaroslavR / whatsapp.py
Created August 31, 2018 14:30 — forked from deepak3081996/whatsapp.py
send whatsapp messages using python
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
def message(to,message=''):
"""this a simple function to send a whatsapp message to your friends
and group using python and selenium an automated tool to parse the HTML
content and to change the properties.
@IaroslavR
IaroslavR / README.md
Created May 7, 2018 17:12
Circular imports in Python 2 and Python 3: when are they fatal? When do they work?

When are Python circular imports fatal?

In your Python package, you have:

  • an __init__.py that designates this as a Python package
  • a module_a.py, containing a function action_a() that references an attribute (like a function or variable) in module_b.py, and
  • a module_b.py, containing a function action_b() that references an attribute (like a function or variable) in module_a.py.

This situation can introduce a circular import error: module_a attempts to import module_b, but can't, because module_b needs to import module_a, which is in the process of being interpreted.

But, sometimes Python is magic, and code that looks like it should cause this circular import error works just fine!

with open("inFile.txt", 'r') as src, \
open("outFile1.txt", 'w') as out_1, \
open("outFile2.txt", 'w') as out_2:
for line in src.readlines():
out_1.writelines(line)
out_2.writelines(line)
@IaroslavR
IaroslavR / examples.py
Last active April 22, 2018 13:51
Examples of readable comprehension formatting from SO
[x.id for x
in self.db.query(schema.allPostsUuid).execute(timeout=20)
if x.type == 'post'
and x.deleted is not False
and ...
and ...]
#-----------------------------------------------------------------
transform = lambda x: x.id
results = self.db.query(schema.allPostsUuid).execute(timeout=20)
condition = lambda x: x.deleted is not False and ... and ...
@IaroslavR
IaroslavR / http-status-codes.md
Created March 8, 2018 00:09 — forked from subfuzion/http-status-codes.md
General REST API HTTP Status Codes

Reference: RFC 2616 - HTTP Status Code Definitions

General

  • 400 BAD REQUEST: The request was invalid or cannot be otherwise served. An accompanying error message will explain further. For security reasons, requests without authentication are considered invalid and will yield this response.
  • 401 UNAUTHORIZED: The authentication credentials are missing, or if supplied are not valid or not sufficient to access the resource.
  • 403 FORBIDDEN: The request has been refused. See the accompanying message for the specific reason (most likely for exceeding rate limit).
  • 404 NOT FOUND: The URI requested is invalid or the resource requested does not exists.
  • 406 NOT ACCEPTABLE: The request specified an invalid format.
import logging
import re
from lawyers.spiders.common import CommonSpider, kayessian_intersection
class LawyerSpider(CommonSpider):
name = 'robertsonshk'
start_urls = ('http://www.robertsonshk.com/en/people', )
common_fields = {
'firm': 'Robertsons (HK)',
@IaroslavR
IaroslavR / byobuCommands
Created September 6, 2017 10:57 — forked from jshaw/byobuCommands
Byobu Commands
Byobu Commands
==============
byobu Screen manager
Level 0 Commands (Quick Start)
------------------------------
<F2> Create a new window
# oxygen missing
sudo apt-get install --reinstall oxygen-icon-theme
# ...и xxx пакетов не обновлено http://forum.ubuntu.ru/index.php?topic=212330.0
sudo apt-get dist-upgrade
# Пакеты, которые будут оставлены в неизменном виде: https://debianforum.ru/index.php?topic=5817.0
dpkg --get-selections | grep hold
echo имя_пакета install | sudo dpkg --set-selections
@IaroslavR
IaroslavR / 1.py
Created December 10, 2016 20:44 — forked from asvetlov/1.py
import asyncio
import aiohttp
async def f(sem, client, url):
async with sem:
with async_timeout.timeout(5):
async with client.get(url) as resp:
print(resp.status)
print(await resp.text()) # resp.context.read(1024)
@IaroslavR
IaroslavR / leveldb.sh
Last active May 8, 2019 05:16
prepare leveldb on CentOS 6
# prepare leveldb on CentOS 6
# https://techoverflow.net/blog/2012/12/14/compiling-installing-leveldb-on-linux/
# https://plyvel.readthedocs.org/en/latest/user.html
sudo yum install -y snappy-devel
cd ~
mkdir src
cd src
git clone https://code.google.com/p/leveldb/
cd leveldb/