Skip to content

Instantly share code, notes, and snippets.

View miodeqqq's full-sized avatar
👨‍💻
Coding...

Maciej Januszewski miodeqqq

👨‍💻
Coding...
View GitHub Profile
from collections import Counter
class ArticleHashtags:
def __init__(self, text):
self.text = text
def get_most_common_words(self, n=5, text_min_lenth=5):
"""
Returns 5 most common words in string.
"""
#!/bin/sh
cat ~/.ssh/id_rsa.pub | ssh username@hostname "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"
@miodeqqq
miodeqqq / plot.html
Last active July 28, 2019 10:33
Django view with Plotly
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Django with Plotly - example</title>
</head>
<body>
{% if view.generate_plot %}
<div style="width: 100%; height: 100%;">
{{ view.generate_plot|safe }}
@miodeqqq
miodeqqq / raw_sql_django.py
Created April 17, 2019 08:47
Django raw SQL queries
from django.db.models.expressions import RawSQL
from apps.core.models import MyModel
sql_query = """SELECT * FROM my_table;"""
raw_sql = RawSQL(
sql=sql_query,
params=[1]
)
# -*- coding: utf-8 -*-
import logging
from random import randint
from time import sleep
from django.db.models import F
from requests import RequestException
from requests import get
from user_agent import generate_user_agent
from proxy.models import Proxy
@miodeqqq
miodeqqq / recaptcha_im_not_robot.py
Created December 8, 2017 18:36
Clicks "I'm not robot" when captcha occurs.
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome()
@miodeqqq
miodeqqq / flatten.py
Created April 26, 2017 09:22
Merge flatten lists into the one
def flatten(x):
"""
Merges flatten lists into the one.
"""
return [a for i in x for a in flatten(i)] if isinstance(x, collections.Iterable) else [x]
@miodeqqq
miodeqqq / stop_docker_containers.sh
Created December 9, 2016 23:18
Stop all currently running Docker containers.
docker stop $(docker ps -a -q)
@miodeqqq
miodeqqq / docker_clean_images.sh
Last active December 9, 2016 23:19
Docker - remove all the dangling/unused images.
#!/bin/bash
# Remove all the dangling images
DANGLING_IMAGES=$(docker images -qf "dangling=true")
if [[ -n $DANGLING_IMAGES ]]; then
docker rmi "$DANGLING_IMAGES"
fi
# Get all the images currently in use
USED_IMAGES=($( \
@miodeqqq
miodeqqq / request_with_proxies.py
Created December 8, 2016 20:22
Python Request (urllib2) with proxies.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from urllib2 import Request, URLError, urlopen, build_opener, ProxyHandler, install_opener
def request_with_proxy():
proxy = ProxyHandler(