Skip to content

Instantly share code, notes, and snippets.

View vishnubob's full-sized avatar

Giles Hall vishnubob

  • Boston, MA
View GitHub Profile
#!/usr/bin/env python
# -*- coding: latin-1 -*-
import google
import requests
import magic
def get_pdf(url, title):
print url
pdf = requests.get(url)
with magic.Magic() as m:
@vishnubob
vishnubob / python_snippets.py
Last active August 29, 2015 14:01
Python Snippets
# Traceback at a specific point
import traceback
frames = 4
print str.join('', traceback.format_stack()[-(frames+1):-1])
# build a color name to RGB python module
import urllib2, json, pprint
url = "https://raw.githubusercontent.com/bahamas10/css-color-names/master/css-color-names.json"
colors = json.loads(urllib2.urlopen(url).read())
colors = {c: (int(v[1:3], 16), int(v[3:5], 16), int(v[5:7], 16)) for (c, v) in colors.items()}
The magic recipe for ABS Juice is 4" of 3mm high quality ABS filament or 8" of 1.75mm chopped into bits and disolved into 1 fluid oz of acetone.
1 cup, 32" 3mm ABS
@vishnubob
vishnubob / octoprint_terminal.log
Created November 28, 2014 16:53
OctoPrint terminal log for G4 dwell bug
Recv: Resend: 16906
Send: N16906 G1 X107.551 Y97.406 E135.66307*82
Recv: ok
Recv: ok
Send: N16907 G1 X107.598 Y97.402 E135.66338*94
Recv: ok
Send: N16908 G1 X107.594 Y97.449 E135.66368*87
Recv: ok
Send: N16909 G1 X107.618 Y97.740 E135.66558*94
Recv: ok
@vishnubob
vishnubob / octoprint.log
Created November 28, 2014 16:55
OctoPrint log file for G4 dwell bug
2014-11-28 15:26:04,034 - octoprint.server.util.sockjs - INFO - New connection from client: 192.168.1.8
2014-11-28 15:30:00,578 - octoprint.util.comm - ERROR - Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:
Traceback (most recent call last):
File "/home/ghall/local/octoprint/local/lib/python2.7/site-packages/OctoPrint-1.2.0_dev_242_g084ca95-py2.7.egg/octoprint/util/comm.py", line 924, in _monitor
self._sendNext()
File "/home/ghall/local/octoprint/local/lib/python2.7/site-packages/OctoPrint-1.2.0_dev_242_g084ca95-py2.7.egg/octoprint/util/comm.py", line 1036, in _sendNext
self._changeState(self.STATE_OPERATIONAL)
File "/home/ghall/local/octoprint/local/lib/python2.7/site-packages/OctoPrint-1.2.0_dev_242_g084ca95-py2.7.egg/octoprint/util/comm.py", line 218, in _changeState
self._callback.mcStateChange(newState)
File "/home/ghall/local/octoprint/local/lib/python2.7/site-packages/OctoPrint-1.2.0_dev_242_g084ca95-py2.7.egg/octoprint/printer.py
@vishnubob
vishnubob / pulley.gcode
Created November 28, 2014 16:58
.gcode file demonstrating OctoPrint G4 dwell bug
This file has been truncated, but you can view the full file.
M140 S100.000000
M109 T0 S230.000000
T0
M190 S100.000000
;Sliced at: Wed 26-11-2014 21:39:25
;Basic settings: Layer height: 0.1 Walls: 0.8 Fill: 100
;Print time: #P_TIME#
;Filament used: #F_AMNT#m #F_WGHT#g
;Filament cost: #F_COST#
;M190 S100 ;Uncomment to add your own bed temperature line
ghall@littletit:[~/code/chainsaw/python] python vt_passwd.py -p /dev/ttyUSB2
Sun Jul 4 20:28:38 2010
____ _ ____ ______ _____ ____ ____
| _ \ / \ / ___/ ___\ \ / / _ \| _ \| _ \ _ _
| |_) / _ \ \___ \___ \\ \ /\ / / | | | |_) | | | | (_|_)
| __/ ___ \ ___) |__) |\ V V /| |_| | _ <| |_| | _ _
|_| /_/ \_\____/____/ \_/\_/ \___/|_| \_\____/ (_|_)
from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
import random
def random_sequence_generator(length):
return str.join('', [random.choice('AGTC') for x in range(length)])
def gc_good(sequence, ideal=.5, spread=.05):
val = (sequence.count('G') + sequence.count('C')) / float(len(sequence))
return (ideal - spread) < val < (ideal + spread)
@vishnubob
vishnubob / shapeoko_grbl_settings.txt
Created January 4, 2015 15:42
Shapeoko GRBL Settings
$0=40.020 (x, step/mm)
$1=40.020 (y, step/mm)
$2=320.000 (z, step/mm)
$3=30 (step pulse, usec)
$4=500.000 (default feed, mm/min)
$5=500.000 (default seek, mm/min)
$6=224 (step port invert mask, int:11100000)
$7=255 (step idle delay, msec)
$8=25.000 (acceleration, mm/sec^2)
$9=0.050 (junction deviation, mm)
@vishnubob
vishnubob / lesson_1.md
Last active November 15, 2017 22:32
Tables and Scales: Do'h-Ray-Meh

Tables and Scales: Do'h-Ray-Meh

Digital Music systems such as MIDI use integers to represent different notes. This method of representation is known an enumeration. For this exercise, we will write a program to build a hash table that translates note values to numerical values, and an array to translate numerical values back to note values. In order to accomplish this, we will need to know two pieces of information, and let our program enumerate our two lookup tables.

  1. What are the two pieces of information our program needs to enumerate the tables?
  2. Why use a hash table for note lookups, and an array for numerical lookups?

For now, we will ignore sharps and flats, and just utilize the "white keys" of a piano when building our table. A full octave is represented by eight notes: C D E F G A B C. When specifying note values, we will use scientific pitch notation.

  1. How many full octaves can we enumerate with an 8-bit unsigned integer? h