Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
import logging
from urlparse import urlparse
import MySQLdb
from MySQLdb.cursors import DictCursor
logger = logging.getLogger(__name__)
@pjwerneck
pjwerneck / mks_flowchart.dot
Created May 20, 2016 02:14
MKS Resources Flowchart
digraph G {
graph [fontname="Helvetica", rankdir="LR", compound=true,
]
edge[fontname="Helvetica", fontsize=10, arrowsize=0.6,
headport=w, tailport=e
]
node[shape=Mrecord, fontname="Helvetica", fontsize=12, style=filled,
colorscheme="pastel28"]
@pjwerneck
pjwerneck / chat.go
Created April 2, 2016 01:22
simple golang chat server
package main
import (
"bufio"
"net"
)
type Client struct {
incoming chan string
outgoing chan string
-*- coding: utf-8 -*-
#!/usr/bin/env python
from math import sqrt, ceil
import itertools
import time
import sys
from tabulate import tabulate
from fractions import gcd
# -*- coding: utf-8 -*-
# https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Python
import time
def iprimes2(limit):
yield 2
if limit < 3:
@pjwerneck
pjwerneck / rmq.py
Last active August 29, 2015 14:09
# -*- coding: utf-8 -*-
import sys
import os
import argparse
import urlparse
import json
import pickle
from Queue import Empty
@pjwerneck
pjwerneck / gist:7157090
Created October 25, 2013 16:03
A switch/case structure using python context managers and decorators. This is just demonstrating the usage (or abuse) of context managers and should not be used in production code.
class switch(object):
def __init__(self, expr):
self.expr = expr
self.cases = {}
self._default = None
def __call__(self, expr):
void setup() {
// inicializa a porta serial
Serial.begin(9600);
}
void loop() {
// le o valor do sensor
int v = analogRead(0);
// faz uma aproximacao
float dist = (2914.0 / (v + 5)) - 1;