Skip to content

Instantly share code, notes, and snippets.

@simudream
simudream / graphene_gevent.py
Created November 16, 2016 00:59 — forked from syrusakbary/graphene_gevent.py
Gevent executor example with Graphene
from collections import OrderedDict
from graphql.core.execution.executor import Executor
from graphql.core.execution.middlewares.gevent import GeventExecutionMiddleware, run_in_greenlet
import graphene
class Patron(graphene.ObjectType):
id = graphene.ID()
@simudream
simudream / asyncio-tornado.py
Created March 29, 2016 04:09 — forked from arvidfm/asyncio-tornado.py
Running Tornado on asyncio's event loop, including 'yield from' support in request handlers
import asyncio
import tornado.concurrent
import tornado.ioloop
import tornado.web
import tornado.platform.asyncio
import tornado.httpclient
class ReqHandler(tornado.web.RequestHandler):
async def get(self):

This now works with the latest Selenium bindings. (pip install selenium)

from selenium import webdriver
driver = webdriver.Firefox() # or webdriver.Chrome()
driver.get('http://user:password@example.com')

The eqivalent with Splinter doesn't work.

from splinter import Browser
browser = Browser()
@simudream
simudream / how_to_use_screen.md
Created January 1, 2016 01:00 — forked from drewlesueur/how_to_use_screen.md
How to use linux screen
@simudream
simudream / gist:15c9e207b1bdc653dcf0
Created December 22, 2015 05:03 — forked from eriwen/gist:187610
Pythonic site monitor
#!/usr/bin/env python
# sample usage: checksites.py eriwen.com nixtutor.com yoursite.org
import pickle, os, sys, logging
from httplib import HTTPConnection, socket
from smtplib import SMTP
def email_alert(message, status):
fromaddr = 'you@gmail.com'
@simudream
simudream / bbb_boot_service_instructions.md
Created December 4, 2015 18:56 — forked from tstellanova/bbb_boot_service_instructions.md
How to setup a service to automatically run a python script when the BeagleBone Black (BBB) reboots. These instructions allow you to setup a python script to automatically start when the BeagleBone (running Angstrom linux with systemd) restarts.

Creating a service to startup at BeagleBone Black boot time:

  • Create a shell script such as /usr/bin/myFancyBash.sh:

      #!/bin/bash
    
      # this could be any runnable code or shell script, really
      /usr/bin/myFancyPython.py 
    

Note that the first line is critical.

@simudream
simudream / client.py
Created December 1, 2015 05:54 — forked from gdamjan/client.py
Python 3.5 async/await with aiohttp, parallel or sequential
import aiohttp
import asyncio
async def get_body(url):
response = await aiohttp.request('GET', url)
raw_html = await response.read()
return raw_html
async def main():
# run them sequentially (but the loop can do other stuff in the meanwhile)
@simudream
simudream / aiohttp-server.py
Created November 27, 2015 05:57 — forked from gdamjan/aiohttp-server.py
Example: asyncio and aiohttp, handling longpoll, eventsource and websocket requests with a queue and background workers
from aiohttp import web
from concurrent.futures import ThreadPoolExecutor
import asyncio
import time, uuid
loop = asyncio.get_event_loop()
async def thread(q):
# you can run non-asyncio code in a separate thread
exc = ThreadPoolExecutor(max_workers=1)
@simudream
simudream / processify.py
Created November 26, 2015 20:33 — forked from schlamar/processify.py
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
@simudream
simudream / forms.py
Created November 17, 2015 20:53 — forked from maraujop/forms.py
django-crispy-forms bootstrap form example
# -*- coding: utf-8 -*-
from django import forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field
from crispy_forms.bootstrap import AppendedText, PrependedText, FormActions
class MessageForm(forms.Form):
text_input = forms.CharField()