Skip to content

Instantly share code, notes, and snippets.

@alecordev
alecordev / .md
Last active April 25, 2017 10:43
Graphviz

Installation

  • conda install graphviz
  • pip install graphviz
  • pip install pygraphviz
  • pip install pydot

Setup

  1. Add executables to the system path
@alecordev
alecordev / pandas.md
Last active January 29, 2018 17:19
Pandas Summary

General

Concepts

loc: only work on index iloc: work on position ix: You can get data from dataframe without it being in the index at: get scalar values. It's a very fast loc iat: get scalar values. It's a very fast iloc

@alecordev
alecordev / .md
Last active July 26, 2017 14:21
Matplotlib Plotting Options Summary

Plots Configuration

Colors:

 'r' = red
 'g' = green
 'b' = blue
 'c' = cyan
 'm' = magenta
 'y' = yellow
@alecordev
alecordev / .py
Created June 5, 2017 11:03
Python logging dictConfig
# https://docs.python.org/2/library/logging.config.html
# https://docs.python.org/3.6/library/logging.config.html
import logging
import logging.config
import datetime
DEFAULT_LOGGING = {
'version': 1,
'disable_existing_loggers': False,
@alecordev
alecordev / .py
Created June 6, 2017 15:07
Python REPL
for line in iter(lambda: input('> '), 'exit'):
print(eval(line))
@alecordev
alecordev / server.py
Created June 7, 2017 11:31
Simple Twisted Server in Current Directory
import sys
from twisted.web.static import File
from twisted.python import log
from twisted.web.server import Site
from twisted.internet import reactor
log.startLogging(sys.stdout)
root = File('.')
site = Site(root)
reactor.listenTCP(8080, site)
@alecordev
alecordev / server.py
Created June 7, 2017 11:33
Simple Twisted WebSocket Implementation
import sys
from twisted.web.static import File
from twisted.python import log
from twisted.web.server import Site
from twisted.internet import reactor
from autobahn.twisted.websocket import WebSocketServerFactory, \
WebSocketServerProtocol
from autobahn.twisted.resource import WebSocketResource
@alecordev
alecordev / index.html
Created June 7, 2017 11:35
Example vanilla JS WebSocket
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
// use vanilla JS because why not
window.addEventListener("load", function() {
// create websocket instance
var mySocket = new WebSocket("ws://localhost:8080/ws");
@alecordev
alecordev / .py
Last active April 27, 2018 11:17
Decorator and Context Manager simple examples
def decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
print('Wrapping')
return f(*args, **kwargs)
return wrapper
@decorator
def f():
print('Function f')